Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

feat(oas3): add format link #533

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/openapi3-parser/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
This can dramatically increase the performance when dealing with documents
which use many unsupported features.

### Enhancements

- added a Link element to the specific format/version in the parse result.

### Bug Fixes

- Return a warning when parsing a document with a 'Media Type Object'
Expand Down
18 changes: 17 additions & 1 deletion packages/openapi3-parser/lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,30 @@ 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])) {
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

const formatVersion = (/3\.\d+\.\d+/).exec(source)[0];
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;
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
{
"element": "parseResult",
"meta": {
"links": {
"element": "array",
"content": [
{
"element": "link",
"meta": {
"title": {
"element": "string",
"content": "OpenAPI 3.0.0"
}
},
"attributes": {
"relation": {
"element": "string",
"content": "via"
},
"href": {
"element": "string",
"content": "https://spec.openapis.org/oas/v3.0.0"
}
}
}
]
}
},
"content": [
{
"element": "category",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
{
"element": "parseResult",
"meta": {
"links": {
"element": "array",
"content": [
{
"element": "link",
"meta": {
"title": {
"element": "string",
"content": "OpenAPI 3.0.0"
}
},
"attributes": {
"relation": {
"element": "string",
"content": "via"
},
"href": {
"element": "string",
"content": "https://spec.openapis.org/oas/v3.0.0"
}
}
}
]
}
},
"content": [
{
"element": "category",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
{
"element": "parseResult",
"meta": {
"links": {
"element": "array",
"content": [
{
"element": "link",
"meta": {
"title": {
"element": "string",
"content": "OpenAPI 3.0.0"
}
},
"attributes": {
"relation": {
"element": "string",
"content": "via"
},
"href": {
"element": "string",
"content": "https://spec.openapis.org/oas/v3.0.0"
}
}
}
]
}
},
"content": [
{
"element": "category",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
{
"element": "parseResult",
"meta": {
"links": {
"element": "array",
"content": [
{
"element": "link",
"meta": {
"title": {
"element": "string",
"content": "OpenAPI 3.0.0"
}
},
"attributes": {
"relation": {
"element": "string",
"content": "via"
},
"href": {
"element": "string",
"content": "https://spec.openapis.org/oas/v3.0.0"
}
}
}
]
}
},
"content": [
{
"element": "category",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
{
"element": "parseResult",
"meta": {
"links": {
"element": "array",
"content": [
{
"element": "link",
"meta": {
"title": {
"element": "string",
"content": "OpenAPI 3.0.0"
}
},
"attributes": {
"relation": {
"element": "string",
"content": "via"
},
"href": {
"element": "string",
"content": "https://spec.openapis.org/oas/v3.0.0"
}
}
}
]
}
},
"content": [
{
"element": "category",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
{
"element": "parseResult",
"meta": {
"links": {
"element": "array",
"content": [
{
"element": "link",
"meta": {
"title": {
"element": "string",
"content": "OpenAPI 3.0.0"
}
},
"attributes": {
"relation": {
"element": "string",
"content": "via"
},
"href": {
"element": "string",
"content": "https://spec.openapis.org/oas/v3.0.0"
}
}
}
]
}
},
"content": [
{
"element": "category",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
{
"element": "parseResult",
"meta": {
"links": {
"element": "array",
"content": [
{
"element": "link",
"meta": {
"title": {
"element": "string",
"content": "OpenAPI 3.0.0"
}
},
"attributes": {
"relation": {
"element": "string",
"content": "via"
},
"href": {
"element": "string",
"content": "https://spec.openapis.org/oas/v3.0.0"
}
}
}
]
}
},
"content": [
{
"element": "category",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
{
"element": "parseResult",
"meta": {
"links": {
"element": "array",
"content": [
{
"element": "link",
"meta": {
"title": {
"element": "string",
"content": "OpenAPI 3.0.0"
}
},
"attributes": {
"relation": {
"element": "string",
"content": "via"
},
"href": {
"element": "string",
"content": "https://spec.openapis.org/oas/v3.0.0"
}
}
}
]
}
},
"content": [
{
"element": "category",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
{
"element": "parseResult",
"meta": {
"links": {
"element": "array",
"content": [
{
"element": "link",
"meta": {
"title": {
"element": "string",
"content": "OpenAPI 3.0.0"
}
},
"attributes": {
"relation": {
"element": "string",
"content": "via"
},
"href": {
"element": "string",
"content": "https://spec.openapis.org/oas/v3.0.0"
}
}
}
]
}
},
"content": [
{
"element": "category",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
{
"element": "parseResult",
"meta": {
"links": {
"element": "array",
"content": [
{
"element": "link",
"meta": {
"title": {
"element": "string",
"content": "OpenAPI 3.0.0"
}
},
"attributes": {
"relation": {
"element": "string",
"content": "via"
},
"href": {
"element": "string",
"content": "https://spec.openapis.org/oas/v3.0.0"
}
}
}
]
}
},
"content": [
{
"element": "category",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
{
"element": "parseResult",
"meta": {
"links": {
"element": "array",
"content": [
{
"element": "link",
"meta": {
"title": {
"element": "string",
"content": "OpenAPI 3.0.0"
}
},
"attributes": {
"relation": {
"element": "string",
"content": "via"
},
"href": {
"element": "string",
"content": "https://spec.openapis.org/oas/v3.0.0"
}
}
}
]
}
},
"content": [
{
"element": "category",
Expand Down
Loading