Skip to content

Commit 174ca57

Browse files
authored
feat(parser-adapter-openapi-json-3-0): add support for OpenAPI 3.0.4 (#4616)
Refs #4612
1 parent 6f1d4a6 commit 174ca57

File tree

5 files changed

+48
-8
lines changed

5 files changed

+48
-8
lines changed

packages/apidom-parser-adapter-openapi-json-3-0/src/adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export { default as mediaTypes } from './media-types.ts';
99
/**
1010
* @public
1111
*/
12-
export const detectionRegExp = /"openapi"\s*:\s*"(?<version_json>3\.0\.([0123]))"/;
12+
export const detectionRegExp = /"openapi"\s*:\s*"(?<version_json>3\.0\.(?:[1-9]\d*|0))"/;
1313

1414
/**
1515
* @public

packages/apidom-parser-adapter-openapi-json-3-0/test/adapter.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ describe('adapter', function () {
2121
assert.isFalse(await adapter.detect('{"openapi": "3.1.0"}'));
2222
});
2323

24-
specify('should not detect patch version bump', async function () {
25-
assert.isFalse(await adapter.detect('{"openapi": "3.0.4"}'));
24+
specify('should detect patch version bump', async function () {
25+
assert.isTrue(await adapter.detect('{"openapi": "3.0.24"}'));
2626
});
2727

2828
specify('should not detect minor and patch version bump', async function () {
@@ -75,8 +75,24 @@ describe('adapter', function () {
7575
});
7676

7777
context('detectionRegExp', function () {
78+
specify('should detect version ranges in forward compatible way', function () {
79+
assert.isTrue(adapter.detectionRegExp.test('"openapi": "3.0.0"'));
80+
assert.isTrue(adapter.detectionRegExp.test('"openapi": "3.0.1"'));
81+
assert.isTrue(adapter.detectionRegExp.test('"openapi": "3.0.2"'));
82+
assert.isTrue(adapter.detectionRegExp.test('"openapi": "3.0.3"'));
83+
assert.isTrue(adapter.detectionRegExp.test('"openapi": "3.0.4"'));
84+
assert.isTrue(adapter.detectionRegExp.test('"openapi": "3.0.5"'));
85+
assert.isTrue(adapter.detectionRegExp.test('"openapi": "3.0.6"'));
86+
assert.isTrue(adapter.detectionRegExp.test('"openapi": "3.0.145"'));
87+
});
88+
89+
specify('should reject rc version ranges', function () {
90+
assert.isFalse(adapter.detectionRegExp.test('"openapi": "3.0.0-rc2"'));
91+
assert.isFalse(adapter.detectionRegExp.test('"openapi": "3.0.0-rc1"'));
92+
assert.isFalse(adapter.detectionRegExp.test('"openapi": "3.0.0-rc0"'));
93+
});
94+
7895
specify('should reject invalid version ranges', function () {
79-
assert.isFalse(adapter.detectionRegExp.test('"openapi": "3.0.4"'));
8096
assert.isFalse(adapter.detectionRegExp.test('"openapi": "3.1.145"'));
8197
assert.isFalse(adapter.detectionRegExp.test('"openapi": "3.1.0"'));
8298
assert.isFalse(adapter.detectionRegExp.test('"openapi": "3.01.0"'));

packages/apidom-parser-adapter-openapi-json-3-0/test/fixtures/sample-api.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"openapi": "3.0.3",
2+
"openapi": "3.0.4",
33
"info": {
44
"title": "Sample Pet Store App",
55
"description": "This is a sample server for a pet store.",

packages/apidom-parser-adapter-openapi-json-3-0/test/fixtures/sample-api.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
openapi: 3.0.3
2+
openapi: 3.0.4
33
info:
44
title: Sample Pet Store App
55
description: This is a sample server for a pet store.

packages/apidom-parser-adapter-openapi-json-3-0/test/media-types.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ import * as openApiJsonAdapter from '../src/adapter.ts';
66
describe('given adapter is used in parser', function () {
77
const parser = new ApiDOMParser().use(openApiJsonAdapter);
88

9+
context('given OpenAPI 3.0.4 definition in JSON format', function () {
10+
specify('should find appropriate media type', async function () {
11+
const mediaType = await parser.findMediaType('{"openapi": "3.0.4"}');
12+
13+
assert.strictEqual(mediaType, 'application/vnd.oai.openapi+json;version=3.0.4');
14+
});
15+
});
16+
917
context('given OpenAPI 3.0.3 definition in JSON format', function () {
1018
specify('should find appropriate media type', async function () {
1119
const mediaType = await parser.findMediaType('{"openapi": "3.0.3"}');
@@ -38,9 +46,25 @@ describe('given adapter is used in parser', function () {
3846
});
3947
});
4048

41-
context('given OpenAPI 3.0.3-rc3 definition in JSON format', function () {
49+
context('given OpenAPI 3.0.0-rc2 definition in JSON format', function () {
50+
specify('should not find appropriate media type', async function () {
51+
const mediaType = await parser.findMediaType('{"openapi": "3.0.0-rc2"}');
52+
53+
assert.strictEqual(mediaType, 'application/octet-stream');
54+
});
55+
});
56+
57+
context('given OpenAPI 3.0.0-rc1 definition in JSON format', function () {
58+
specify('should not find appropriate media type', async function () {
59+
const mediaType = await parser.findMediaType('{"openapi": "3.0.0-rc1"}');
60+
61+
assert.strictEqual(mediaType, 'application/octet-stream');
62+
});
63+
});
64+
65+
context('given OpenAPI 3.0.0-rc0 definition in JSON format', function () {
4266
specify('should not find appropriate media type', async function () {
43-
const mediaType = await parser.findMediaType('{"openapi": "3.0.3-rc3"}');
67+
const mediaType = await parser.findMediaType('{"openapi": "3.0.0-rc0"}');
4468

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

0 commit comments

Comments
 (0)