Skip to content

Commit

Permalink
feat(ns-openapi-3-0): add support for OpenAPI 3.0.4 (#4613)
Browse files Browse the repository at this point in the history
Refs #4612
  • Loading branch information
char0n authored Dec 24, 2024
1 parent 40d2b25 commit e1c2eb7
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 6 deletions.
5 changes: 4 additions & 1 deletion packages/apidom-ns-openapi-3-0/src/media-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class OpenAPIMediaTypes extends MediaTypes<string> {
return this.filter((mediaType) => mediaType.includes(effectiveFormat));
}

findBy(version = '3.0.3', format: Format = 'generic') {
findBy(version = '3.0.4', format: Format = 'generic') {
const search =
format === 'generic'
? `vnd.oai.openapi;version=${version}`
Expand Down Expand Up @@ -46,6 +46,9 @@ const mediaTypes = new OpenAPIMediaTypes(
'application/vnd.oai.openapi;version=3.0.3',
'application/vnd.oai.openapi+json;version=3.0.3',
'application/vnd.oai.openapi+yaml;version=3.0.3',
'application/vnd.oai.openapi;version=3.0.4',
'application/vnd.oai.openapi+json;version=3.0.4',
'application/vnd.oai.openapi+yaml;version=3.0.4',
);

export default mediaTypes;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@swagger-api/apidom-core';

/**
* OpenAPI 3.0.3 specification elements.
* OpenAPI 3.0.x specification elements.
*/
import InfoElement from '../../elements/Info.ts';
import ContactElement from '../../elements/Contact.ts';
Expand Down Expand Up @@ -89,7 +89,7 @@ import { getNodeType } from '../../traversal/visitor.ts';
* @example
*
* ```yaml
* openapi: 3.0.3
* openapi: 3.0.4
* info:
* ```
* Refracting result without this plugin:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,130 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`refractor elements OpenApi3_0Element should refract to semantic ApiDOM tree 1`] = `
exports[`refractor elements OpenApi3_0Element should refract OpenAPI 3.0.0 to semantic ApiDOM tree 1`] = `
(OpenApi3_0Element
(MemberElement
(StringElement)
(OpenapiElement))
(MemberElement
(StringElement)
(InfoElement))
(MemberElement
(StringElement)
(ArrayElement
(ServerElement)))
(MemberElement
(StringElement)
(PathsElement))
(MemberElement
(StringElement)
(ComponentsElement))
(MemberElement
(StringElement)
(ArrayElement
(SecurityRequirementElement)))
(MemberElement
(StringElement)
(ArrayElement
(TagElement)))
(MemberElement
(StringElement)
(ExternalDocumentationElement)))
`;

exports[`refractor elements OpenApi3_0Element should refract OpenAPI 3.0.1 to semantic ApiDOM tree 1`] = `
(OpenApi3_0Element
(MemberElement
(StringElement)
(OpenapiElement))
(MemberElement
(StringElement)
(InfoElement))
(MemberElement
(StringElement)
(ArrayElement
(ServerElement)))
(MemberElement
(StringElement)
(PathsElement))
(MemberElement
(StringElement)
(ComponentsElement))
(MemberElement
(StringElement)
(ArrayElement
(SecurityRequirementElement)))
(MemberElement
(StringElement)
(ArrayElement
(TagElement)))
(MemberElement
(StringElement)
(ExternalDocumentationElement)))
`;

exports[`refractor elements OpenApi3_0Element should refract OpenAPI 3.0.2 to semantic ApiDOM tree 1`] = `
(OpenApi3_0Element
(MemberElement
(StringElement)
(OpenapiElement))
(MemberElement
(StringElement)
(InfoElement))
(MemberElement
(StringElement)
(ArrayElement
(ServerElement)))
(MemberElement
(StringElement)
(PathsElement))
(MemberElement
(StringElement)
(ComponentsElement))
(MemberElement
(StringElement)
(ArrayElement
(SecurityRequirementElement)))
(MemberElement
(StringElement)
(ArrayElement
(TagElement)))
(MemberElement
(StringElement)
(ExternalDocumentationElement)))
`;

exports[`refractor elements OpenApi3_0Element should refract OpenAPI 3.0.3 to semantic ApiDOM tree 1`] = `
(OpenApi3_0Element
(MemberElement
(StringElement)
(OpenapiElement))
(MemberElement
(StringElement)
(InfoElement))
(MemberElement
(StringElement)
(ArrayElement
(ServerElement)))
(MemberElement
(StringElement)
(PathsElement))
(MemberElement
(StringElement)
(ComponentsElement))
(MemberElement
(StringElement)
(ArrayElement
(SecurityRequirementElement)))
(MemberElement
(StringElement)
(ArrayElement
(TagElement)))
(MemberElement
(StringElement)
(ExternalDocumentationElement)))
`;

exports[`refractor elements OpenApi3_0Element should refract OpenAPI 3.0.4 to semantic ApiDOM tree 1`] = `
(OpenApi3_0Element
(MemberElement
(StringElement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,52 @@ import { OpenApi3_0Element } from '../../../../src/index.ts';
describe('refractor', function () {
context('elements', function () {
context('OpenApi3_0Element', function () {
specify('should refract to semantic ApiDOM tree', function () {
specify('should refract OpenAPI 3.0.0 to semantic ApiDOM tree', function () {
const openApiElement = OpenApi3_0Element.refract({
openapi: '3.0.0',
info: {},
servers: [{}],
paths: {},
components: {},
security: [{}],
tags: [{}],
externalDocs: {},
});

expect(sexprs(openApiElement)).toMatchSnapshot();
});

specify('should refract OpenAPI 3.0.1 to semantic ApiDOM tree', function () {
const openApiElement = OpenApi3_0Element.refract({
openapi: '3.0.1',
info: {},
servers: [{}],
paths: {},
components: {},
security: [{}],
tags: [{}],
externalDocs: {},
});

expect(sexprs(openApiElement)).toMatchSnapshot();
});

specify('should refract OpenAPI 3.0.2 to semantic ApiDOM tree', function () {
const openApiElement = OpenApi3_0Element.refract({
openapi: '3.0.2',
info: {},
servers: [{}],
paths: {},
components: {},
security: [{}],
tags: [{}],
externalDocs: {},
});

expect(sexprs(openApiElement)).toMatchSnapshot();
});

specify('should refract OpenAPI 3.0.3 to semantic ApiDOM tree', function () {
const openApiElement = OpenApi3_0Element.refract({
openapi: '3.0.3',
info: {},
Expand All @@ -20,6 +65,21 @@ describe('refractor', function () {

expect(sexprs(openApiElement)).toMatchSnapshot();
});

specify('should refract OpenAPI 3.0.4 to semantic ApiDOM tree', function () {
const openApiElement = OpenApi3_0Element.refract({
openapi: '3.0.4',
info: {},
servers: [{}],
paths: {},
components: {},
security: [{}],
tags: [{}],
externalDocs: {},
});

expect(sexprs(openApiElement)).toMatchSnapshot();
});
});
});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`refractor elements OpenapiElement 3.0.0 should refract to semantic ApiDOM tree 1`] = `(OpenapiElement)`;

exports[`refractor elements OpenapiElement 3.0.1 should refract to semantic ApiDOM tree 1`] = `(OpenapiElement)`;

exports[`refractor elements OpenapiElement 3.0.2 should refract to semantic ApiDOM tree 1`] = `(OpenapiElement)`;

exports[`refractor elements OpenapiElement 3.0.3 should refract to semantic ApiDOM tree 1`] = `(OpenapiElement)`;

exports[`refractor elements OpenapiElement 3.0.4 should refract to semantic ApiDOM tree 1`] = `(OpenapiElement)`;

exports[`refractor elements OpenapiElement should refract to semantic ApiDOM tree 1`] = `(OpenapiElement)`;
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,44 @@ import { OpenapiElement } from '../../../../src/index.ts';

describe('refractor', function () {
context('elements', function () {
context('OpenapiElement', function () {
context('OpenapiElement 3.0.0', function () {
specify('should refract to semantic ApiDOM tree', function () {
const openapiElement = OpenapiElement.refract('3.0.0');

expect(sexprs(openapiElement)).toMatchSnapshot();
});
});

context('OpenapiElement 3.0.1', function () {
specify('should refract to semantic ApiDOM tree', function () {
const openapiElement = OpenapiElement.refract('3.0.1');

expect(sexprs(openapiElement)).toMatchSnapshot();
});
});

context('OpenapiElement 3.0.2', function () {
specify('should refract to semantic ApiDOM tree', function () {
const openapiElement = OpenapiElement.refract('3.0.2');

expect(sexprs(openapiElement)).toMatchSnapshot();
});
});

context('OpenapiElement 3.0.3', function () {
specify('should refract to semantic ApiDOM tree', function () {
const openapiElement = OpenapiElement.refract('3.0.3');

expect(sexprs(openapiElement)).toMatchSnapshot();
});
});

context('OpenapiElement 3.0.4', function () {
specify('should refract to semantic ApiDOM tree', function () {
const openapiElement = OpenapiElement.refract('3.0.4');

expect(sexprs(openapiElement)).toMatchSnapshot();
});
});
});
});

0 comments on commit e1c2eb7

Please sign in to comment.