From e1c2eb71e478c63f0dfc03baa7316a6d82e58b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Tue, 24 Dec 2024 07:28:08 +0100 Subject: [PATCH] feat(ns-openapi-3-0): add support for OpenAPI 3.0.4 (#4613) Refs #4612 --- .../apidom-ns-openapi-3-0/src/media-types.ts | 5 +- .../plugins/replace-empty-element.ts | 4 +- .../OpenApi3-0/__snapshots__/index.mjs.snap | 126 +++++++++++++++++- .../refractor/elements/OpenApi3-0/index.ts | 62 ++++++++- .../Openapi/__snapshots__/index.mjs.snap | 10 ++ .../test/refractor/elements/Openapi/index.ts | 34 ++++- 6 files changed, 235 insertions(+), 6 deletions(-) diff --git a/packages/apidom-ns-openapi-3-0/src/media-types.ts b/packages/apidom-ns-openapi-3-0/src/media-types.ts index da1d18ff25..682cc6a54a 100644 --- a/packages/apidom-ns-openapi-3-0/src/media-types.ts +++ b/packages/apidom-ns-openapi-3-0/src/media-types.ts @@ -15,7 +15,7 @@ export class OpenAPIMediaTypes extends MediaTypes { 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}` @@ -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; diff --git a/packages/apidom-ns-openapi-3-0/src/refractor/plugins/replace-empty-element.ts b/packages/apidom-ns-openapi-3-0/src/refractor/plugins/replace-empty-element.ts index 332d63316b..655ef37f96 100644 --- a/packages/apidom-ns-openapi-3-0/src/refractor/plugins/replace-empty-element.ts +++ b/packages/apidom-ns-openapi-3-0/src/refractor/plugins/replace-empty-element.ts @@ -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'; @@ -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: diff --git a/packages/apidom-ns-openapi-3-0/test/refractor/elements/OpenApi3-0/__snapshots__/index.mjs.snap b/packages/apidom-ns-openapi-3-0/test/refractor/elements/OpenApi3-0/__snapshots__/index.mjs.snap index 05dbbf6842..16062f7c05 100644 --- a/packages/apidom-ns-openapi-3-0/test/refractor/elements/OpenApi3-0/__snapshots__/index.mjs.snap +++ b/packages/apidom-ns-openapi-3-0/test/refractor/elements/OpenApi3-0/__snapshots__/index.mjs.snap @@ -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) diff --git a/packages/apidom-ns-openapi-3-0/test/refractor/elements/OpenApi3-0/index.ts b/packages/apidom-ns-openapi-3-0/test/refractor/elements/OpenApi3-0/index.ts index 4aabc68364..7834ee77cd 100644 --- a/packages/apidom-ns-openapi-3-0/test/refractor/elements/OpenApi3-0/index.ts +++ b/packages/apidom-ns-openapi-3-0/test/refractor/elements/OpenApi3-0/index.ts @@ -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: {}, @@ -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(); + }); }); }); }); diff --git a/packages/apidom-ns-openapi-3-0/test/refractor/elements/Openapi/__snapshots__/index.mjs.snap b/packages/apidom-ns-openapi-3-0/test/refractor/elements/Openapi/__snapshots__/index.mjs.snap index fce4e69122..18c78424ef 100644 --- a/packages/apidom-ns-openapi-3-0/test/refractor/elements/Openapi/__snapshots__/index.mjs.snap +++ b/packages/apidom-ns-openapi-3-0/test/refractor/elements/Openapi/__snapshots__/index.mjs.snap @@ -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)`; diff --git a/packages/apidom-ns-openapi-3-0/test/refractor/elements/Openapi/index.ts b/packages/apidom-ns-openapi-3-0/test/refractor/elements/Openapi/index.ts index 14ebb78197..7fbf00f378 100644 --- a/packages/apidom-ns-openapi-3-0/test/refractor/elements/Openapi/index.ts +++ b/packages/apidom-ns-openapi-3-0/test/refractor/elements/Openapi/index.ts @@ -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(); + }); + }); }); });