-
Notifications
You must be signed in to change notification settings - Fork 18
feat(oas3): add format link #533
base: master
Are you sure you want to change the base?
Changes from 6 commits
8cb6eb7
b7ebf79
2772392
01b6121
48abc84
729dacb
f52cd03
88bcb56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,9 @@ | |
| const R = require('ramda'); | ||
| const parseYAML = require('./parser/parseYAML'); | ||
|
|
||
| const { isAnnotation, isWarningAnnotation, isObject } = require('./predicates'); | ||
| const { | ||
| isAnnotation, isWarningAnnotation, isObject, isMember, hasKey, | ||
| } = require('./predicates'); | ||
| const { createError } = require('./elements'); | ||
| const pipeParseResult = require('./pipeParseResult'); | ||
|
|
||
|
|
@@ -126,14 +128,35 @@ function parse(source, context) { | |
| R.unless(isObjectOrAnnotation, createError(context.namespace, 'Source document is not an object')), | ||
| R.unless(isAnnotation, parseOpenAPIObject(context))); | ||
|
|
||
| return R.chain( | ||
| const parseResult = R.chain( | ||
| R.pipe( | ||
| parseDocument, | ||
| deduplicateUnsupportedAnnotations(context.namespace), | ||
| context.options.generateSourceMap ? filterColumnLine : filterSourceMaps | ||
| ), | ||
| document | ||
| ); | ||
|
|
||
| if (!isAnnotation(parseResult.content[0])) { | ||
| const formatVersion = R.pipe( | ||
|
||
| R.prop('content'), | ||
| R.find(isObject), | ||
| R.prop('content'), | ||
| R.find(R.both(isMember, hasKey('openapi'))) | ||
| )(document).toValue().value; | ||
|
|
||
| const formatLink = `https://spec.openapis.org/oas/v${formatVersion}`; | ||
| const { Link } = context.namespace.elements; | ||
| const link = new Link(); | ||
|
|
||
| link.title = `OpenAPI ${formatVersion}`; | ||
| link.relation = 'via'; | ||
| link.href = formatLink; | ||
|
|
||
| parseResult.links.push(link); | ||
| } | ||
|
|
||
| return parseResult; | ||
| } | ||
|
|
||
| module.exports = parse; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this check can be removed like in the API Blueprint version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed