@@ -4,7 +4,7 @@ const R = require('ramda');
4
4
const parseYAML = require ( './parser/parseYAML' ) ;
5
5
6
6
const {
7
- isAnnotation, isWarningAnnotation, isObject, isMember, hasKey,
7
+ isAnnotation, isWarningAnnotation, isObject, isMember, hasKey, isString ,
8
8
} = require ( './predicates' ) ;
9
9
const { createError } = require ( './elements' ) ;
10
10
const pipeParseResult = require ( './pipeParseResult' ) ;
@@ -137,24 +137,26 @@ function parse(source, context) {
137
137
document
138
138
) ;
139
139
140
- if ( ! isAnnotation ( parseResult . content [ 0 ] ) ) {
141
- const formatVersion = R . pipe (
140
+ const formatVersion = R . tryCatch (
141
+ R . pipe (
142
142
R . prop ( 'content' ) ,
143
143
R . find ( isObject ) ,
144
144
R . prop ( 'content' ) ,
145
- R . find ( R . both ( isMember , hasKey ( 'openapi' ) ) )
146
- ) ( document ) . toValue ( ) . value ;
145
+ R . find ( R . both ( isMember , hasKey ( 'openapi' ) ) ) ,
146
+ R . path ( [ 'content' , 'value' ] ) ,
147
+ R . and ( isString , R . prop ( 'content' ) )
148
+ ) , R . always ( '3.0.3' )
149
+ ) ( document ) ;
147
150
148
- const formatLink = `https://spec.openapis.org/oas/v${ formatVersion } ` ;
149
- const { Link } = context . namespace . elements ;
150
- const link = new Link ( ) ;
151
+ const formatLink = `https://spec.openapis.org/oas/v${ formatVersion } ` ;
152
+ const { Link } = context . namespace . elements ;
153
+ const link = new Link ( ) ;
151
154
152
- link . title = `OpenAPI ${ formatVersion } ` ;
153
- link . relation = 'via' ;
154
- link . href = formatLink ;
155
+ link . title = `OpenAPI ${ formatVersion } ` ;
156
+ link . relation = 'via' ;
157
+ link . href = formatLink ;
155
158
156
- parseResult . links . push ( link ) ;
157
- }
159
+ parseResult . links . push ( link ) ;
158
160
159
161
return parseResult ;
160
162
}
0 commit comments