Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(parser-adapter-openapi-yaml-3-0): add support for OpenAPI 3.0.4 #4617

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export { default as mediaTypes } from './media-types.ts';
* @public
*/
export const detectionRegExp =
/(?<YAML>^(["']?)openapi\2\s*:\s*(["']?)(?<version_yaml>3\.0\.[0123](?:-rc[012])?)\3(?:\s+|$))|(?<JSON>"openapi"\s*:\s*"(?<version_json>3\.0\.[0123](?:-rc[012])?)")/m;
/(?<YAML>^(["']?)openapi\2\s*:\s*(["']?)(?<version_yaml>3\.0\.(?:[1-9]\d*|0))\3(?:\s+|$))|(?<JSON>"openapi"\s*:\s*"(?<version_json>3\.0\.(?:[1-9]\d*|0))")/m;

/**
* @public
Expand Down
27 changes: 22 additions & 5 deletions packages/apidom-parser-adapter-openapi-yaml-3-0/test/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ describe('adapter', function () {
assert.isFalse(await adapter.detect('openapi: "3.1.0"'));
});

specify('should not detect patch version bump', async function () {
assert.isFalse(await adapter.detect('openapi: "3.0.4"'));
specify('should detect patch version bump', async function () {
assert.isTrue(await adapter.detect('openapi: "3.0.24"'));
char0n marked this conversation as resolved.
Show resolved Hide resolved
});

specify('should not detect minor and patch version bump', async function () {
Expand Down Expand Up @@ -91,12 +91,29 @@ describe('adapter', function () {
});

context('detectionRegExp', function () {
specify('should detect version ranges in forward compatible way', function () {
assert.isTrue(adapter.detectionRegExp.test('openapi: 3.0.0'));
assert.isTrue(adapter.detectionRegExp.test('openapi: 3.0.1'));
assert.isTrue(adapter.detectionRegExp.test('openapi: 3.0.2'));
assert.isTrue(adapter.detectionRegExp.test('openapi: 3.0.3'));
assert.isTrue(adapter.detectionRegExp.test('openapi: 3.0.4'));
assert.isTrue(adapter.detectionRegExp.test('openapi: 3.0.5'));
assert.isTrue(adapter.detectionRegExp.test('openapi: 3.0.6'));
assert.isTrue(adapter.detectionRegExp.test('openapi: 3.0.145'));
});

specify('should reject rc version ranges', function () {
assert.isFalse(adapter.detectionRegExp.test('openapi: 3.0.0-rc2'));
assert.isFalse(adapter.detectionRegExp.test('openapi: 3.0.0-rc1'));
assert.isFalse(adapter.detectionRegExp.test('openapi: 3.0.0-rc0'));
});

specify('should reject invalid version ranges', function () {
assert.isFalse(adapter.detectionRegExp.test('openapi: 3.1.145'));
assert.isFalse(adapter.detectionRegExp.test('openapi: 3.1.0'));
assert.isFalse(adapter.detectionRegExp.test('openapi: 3.01.0'));
assert.isFalse(adapter.detectionRegExp.test('openapi: 3.0.01'));
assert.isFalse(adapter.detectionRegExp.test('openapi: 3.1.0'));
assert.isFalse(adapter.detectionRegExp.test('openapi: 3.1.1'));
assert.isFalse(adapter.detectionRegExp.test('openapi: 3.0.15'));
assert.isFalse(adapter.detectionRegExp.test('openapi: 3.0.1-rc1'));
});
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"openapi": "3.0.3",
"openapi": "3.0.4",
"info": {
"title": "Sample Pet Store App",
"description": "This is a sample server for a pet store.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
openapi: 3.0.3
openapi: 3.0.4
info:
title: Sample Pet Store App
description: This is a sample server for a pet store.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import * as openApiYAMLAdapter from '../src/adapter.ts';
describe('given adapter is used in parser', function () {
const parser = new ApiDOMParser().use(openApiYAMLAdapter);

context('given OpenAPI 3.0.4 definition in YAML format', function () {
specify('should find appropriate media type', async function () {
const mediaType = await parser.findMediaType('openapi: "3.0.4"');

assert.strictEqual(mediaType, 'application/vnd.oai.openapi+yaml;version=3.0.4');
});
});

context('given OpenAPI 3.0.3 definition in YAML format', function () {
specify('should find appropriate media type', async function () {
const mediaType = await parser.findMediaType('openapi: "3.0.3"');
Expand Down Expand Up @@ -38,9 +46,25 @@ describe('given adapter is used in parser', function () {
});
});

context('given OpenAPI 3.0.3-rc3 definition in YAML format', function () {
context('given OpenAPI 3.0.3-rc2 definition in YAML format', function () {
specify('should not find appropriate media type', async function () {
const mediaType = await parser.findMediaType('openapi: "3.0.3-rc2"');

assert.strictEqual(mediaType, 'application/octet-stream');
});
});

context('given OpenAPI 3.0.3-rc1 definition in YAML format', function () {
specify('should not find appropriate media type', async function () {
const mediaType = await parser.findMediaType('openapi: "3.0.3-rc1"');

assert.strictEqual(mediaType, 'application/octet-stream');
});
});

context('given OpenAPI 3.0.3-rc0 definition in YAML format', function () {
specify('should not find appropriate media type', async function () {
const mediaType = await parser.findMediaType('openapi: "3.0.3-rc3"');
const mediaType = await parser.findMediaType('openapi: "3.0.3-rc0"');

assert.strictEqual(mediaType, 'application/octet-stream');
});
Expand Down
Loading