From f4395a4b737feb8874c7b21f7ad1a280d2b60fdd Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Fri, 9 Aug 2024 15:04:06 +0200 Subject: [PATCH] feat(resolver): loosen requirement for file extensions Refs https://github.com/swagger-api/apidom/issues/4298 --- package-lock.json | 10 +++++----- package.json | 10 +++++----- .../apidom/reference/parse/parsers/json/index.js | 3 +-- .../reference/parse/parsers/openapi-json-3-1/index.js | 3 +-- .../reference/parse/parsers/openapi-yaml-3-1/index.js | 3 +-- .../apidom/reference/parse/parsers/yaml-1-2/index.js | 3 +-- .../__fixtures__/external-value-text/dereferenced.json | 4 ++-- .../__fixtures__/external-value-text/ex.csv | 1 - .../__fixtures__/external-value-text/ex.dat | 1 + .../__fixtures__/external-value-text/root.json | 2 +- .../reference/parse/parsers/openapi-json-3-1/index.js | 4 ++-- .../reference/parse/parsers/openapi-yaml-3-1/index.js | 4 ++-- .../apidom/reference/parse/parsers/yaml-1-2/index.js | 4 ++-- 13 files changed, 24 insertions(+), 28 deletions(-) delete mode 100644 test/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/example-object/__fixtures__/external-value-text/ex.csv create mode 100644 test/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/example-object/__fixtures__/external-value-text/ex.dat diff --git a/package-lock.json b/package-lock.json index 5f9234f0a..d740992e0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,11 +10,11 @@ "license": "Apache-2.0", "dependencies": { "@babel/runtime-corejs3": "^7.22.15", - "@swagger-api/apidom-core": ">=1.0.0-alpha.6 <1.0.0-beta.0", - "@swagger-api/apidom-error": ">=1.0.0-alpha.6 <1.0.0-beta.0", - "@swagger-api/apidom-json-pointer": ">=1.0.0-alpha.6 <1.0.0-beta.0", - "@swagger-api/apidom-ns-openapi-3-1": ">=1.0.0-alpha.6 <1.0.0-beta.0", - "@swagger-api/apidom-reference": ">=1.0.0-alpha.6 <1.0.0-beta.0", + "@swagger-api/apidom-core": ">=1.0.0-alpha.8 <1.0.0-beta.0", + "@swagger-api/apidom-error": ">=1.0.0-alpha.8 <1.0.0-beta.0", + "@swagger-api/apidom-json-pointer": ">=1.0.0-alpha.8 <1.0.0-beta.0", + "@swagger-api/apidom-ns-openapi-3-1": ">=1.0.0-alpha.8 <1.0.0-beta.0", + "@swagger-api/apidom-reference": ">=1.0.0-alpha.8 <1.0.0-beta.0", "cookie": "~0.6.0", "deepmerge": "~4.3.0", "fast-json-patch": "^3.0.0-1", diff --git a/package.json b/package.json index 4ef7fe573..bf2cbdd7e 100644 --- a/package.json +++ b/package.json @@ -73,11 +73,11 @@ "license": "Apache-2.0", "dependencies": { "@babel/runtime-corejs3": "^7.22.15", - "@swagger-api/apidom-core": ">=1.0.0-alpha.6 <1.0.0-beta.0", - "@swagger-api/apidom-error": ">=1.0.0-alpha.6 <1.0.0-beta.0", - "@swagger-api/apidom-json-pointer": ">=1.0.0-alpha.6 <1.0.0-beta.0", - "@swagger-api/apidom-ns-openapi-3-1": ">=1.0.0-alpha.6 <1.0.0-beta.0", - "@swagger-api/apidom-reference": ">=1.0.0-alpha.6 <1.0.0-beta.0", + "@swagger-api/apidom-core": ">=1.0.0-alpha.8 <1.0.0-beta.0", + "@swagger-api/apidom-error": ">=1.0.0-alpha.8 <1.0.0-beta.0", + "@swagger-api/apidom-json-pointer": ">=1.0.0-alpha.8 <1.0.0-beta.0", + "@swagger-api/apidom-ns-openapi-3-1": ">=1.0.0-alpha.8 <1.0.0-beta.0", + "@swagger-api/apidom-reference": ">=1.0.0-alpha.8 <1.0.0-beta.0", "cookie": "~0.6.0", "deepmerge": "~4.3.0", "fast-json-patch": "^3.0.0-1", diff --git a/src/resolver/apidom/reference/parse/parsers/json/index.js b/src/resolver/apidom/reference/parse/parsers/json/index.js index cd5c346d3..5d621883b 100644 --- a/src/resolver/apidom/reference/parse/parsers/json/index.js +++ b/src/resolver/apidom/reference/parse/parsers/json/index.js @@ -4,10 +4,9 @@ import { ParserError, Parser } from '@swagger-api/apidom-reference/configuration class JSONParser extends Parser { constructor(options = {}) { super({ - ...options, name: 'json-swagger-client', - fileExtensions: ['.json'], mediaTypes: ['application/json'], + ...options, }); } diff --git a/src/resolver/apidom/reference/parse/parsers/openapi-json-3-1/index.js b/src/resolver/apidom/reference/parse/parsers/openapi-json-3-1/index.js index 7c9fb6f03..c0b0aaf95 100644 --- a/src/resolver/apidom/reference/parse/parsers/openapi-json-3-1/index.js +++ b/src/resolver/apidom/reference/parse/parsers/openapi-json-3-1/index.js @@ -12,13 +12,12 @@ class OpenAPIJSON3_1Parser extends Parser { constructor(options = {}) { super({ - ...options, name: 'openapi-json-3-1-swagger-client', - fileExtensions: ['.json'], mediaTypes: new OpenAPIMediaTypes( ...mediaTypes.filterByFormat('generic'), ...mediaTypes.filterByFormat('json') ), + ...options, }); } diff --git a/src/resolver/apidom/reference/parse/parsers/openapi-yaml-3-1/index.js b/src/resolver/apidom/reference/parse/parsers/openapi-yaml-3-1/index.js index 0c0452934..a2fb66dd7 100644 --- a/src/resolver/apidom/reference/parse/parsers/openapi-yaml-3-1/index.js +++ b/src/resolver/apidom/reference/parse/parsers/openapi-yaml-3-1/index.js @@ -15,12 +15,11 @@ class OpenAPIYAML31Parser extends Parser { constructor(options = {}) { super({ name: 'openapi-yaml-3-1-swagger-client', - ...options, - fileExtensions: ['.yaml', '.yml'], mediaTypes: new OpenAPIMediaTypes( ...mediaTypes.filterByFormat('generic'), ...mediaTypes.filterByFormat('yaml') ), + ...options, }); } diff --git a/src/resolver/apidom/reference/parse/parsers/yaml-1-2/index.js b/src/resolver/apidom/reference/parse/parsers/yaml-1-2/index.js index 9805759b1..056b5b923 100644 --- a/src/resolver/apidom/reference/parse/parsers/yaml-1-2/index.js +++ b/src/resolver/apidom/reference/parse/parsers/yaml-1-2/index.js @@ -5,10 +5,9 @@ import { ParserError, Parser } from '@swagger-api/apidom-reference/configuration class YAMLParser extends Parser { constructor(options = {}) { super({ - ...options, name: 'yaml-1-2-swagger-client', - fileExtensions: ['.yaml', '.yml'], mediaTypes: ['text/yaml', 'application/yaml'], + ...options, }); } diff --git a/test/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/example-object/__fixtures__/external-value-text/dereferenced.json b/test/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/example-object/__fixtures__/external-value-text/dereferenced.json index ce48fb16f..2b3a244bb 100644 --- a/test/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/example-object/__fixtures__/external-value-text/dereferenced.json +++ b/test/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/example-object/__fixtures__/external-value-text/dereferenced.json @@ -5,8 +5,8 @@ "examples": { "example1": { "description": "example1 description", - "value": "dmFsMTt2YWwyO3ZhbDMK", - "externalValue": "./ex.csv" + "value": "a2V5OiAidmFsdWU6IHdpdGggOiBjb2xvbnMiIDogYW5vdGhlcl92YWx1ZQo=", + "externalValue": "./ex.dat" } } } diff --git a/test/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/example-object/__fixtures__/external-value-text/ex.csv b/test/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/example-object/__fixtures__/external-value-text/ex.csv deleted file mode 100644 index afd194d0e..000000000 --- a/test/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/example-object/__fixtures__/external-value-text/ex.csv +++ /dev/null @@ -1 +0,0 @@ -val1;val2;val3 diff --git a/test/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/example-object/__fixtures__/external-value-text/ex.dat b/test/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/example-object/__fixtures__/external-value-text/ex.dat new file mode 100644 index 000000000..8cc4fe07b --- /dev/null +++ b/test/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/example-object/__fixtures__/external-value-text/ex.dat @@ -0,0 +1 @@ +key: "value: with : colons" : another_value diff --git a/test/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/example-object/__fixtures__/external-value-text/root.json b/test/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/example-object/__fixtures__/external-value-text/root.json index fb347a776..171902f4c 100644 --- a/test/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/example-object/__fixtures__/external-value-text/root.json +++ b/test/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/example-object/__fixtures__/external-value-text/root.json @@ -4,7 +4,7 @@ "examples": { "example1": { "description": "example1 description", - "externalValue": "./ex.csv" + "externalValue": "./ex.dat" } } } diff --git a/test/resolver/apidom/reference/parse/parsers/openapi-json-3-1/index.js b/test/resolver/apidom/reference/parse/parsers/openapi-json-3-1/index.js index 3b9495fc2..62c43834a 100644 --- a/test/resolver/apidom/reference/parse/parsers/openapi-json-3-1/index.js +++ b/test/resolver/apidom/reference/parse/parsers/openapi-json-3-1/index.js @@ -46,7 +46,7 @@ describe('OpenAPIJson3_1Parser', () => { uri: '/path/to/openapi.yaml', mediaType: mediaTypes.latest('json'), }); - const parser = new OpenAPIJson3_1Parser(); + const parser = new OpenAPIJson3_1Parser({ fileExtensions: ['.json'] }); expect(await parser.canParse(file)).toBe(false); }); @@ -58,7 +58,7 @@ describe('OpenAPIJson3_1Parser', () => { uri: '/path/to/openapi', mediaType: mediaTypes.latest('json'), }); - const parser = new OpenAPIJson3_1Parser(); + const parser = new OpenAPIJson3_1Parser({ fileExtensions: ['.json'] }); expect(await parser.canParse(file)).toBe(false); }); diff --git a/test/resolver/apidom/reference/parse/parsers/openapi-yaml-3-1/index.js b/test/resolver/apidom/reference/parse/parsers/openapi-yaml-3-1/index.js index 1b6e3e243..69b0057cc 100644 --- a/test/resolver/apidom/reference/parse/parsers/openapi-yaml-3-1/index.js +++ b/test/resolver/apidom/reference/parse/parsers/openapi-yaml-3-1/index.js @@ -77,7 +77,7 @@ describe('OpenAPIYaml3_1Parser', () => { uri: '/path/to/openapi.json', mediaType: mediaTypes.latest('yaml'), }); - const parser = new OpenAPIYaml3_1Parser(); + const parser = new OpenAPIYaml3_1Parser({ fileExtensions: ['.yaml', '.yml'] }); expect(await parser.canParse(file)).toBe(false); }); @@ -89,7 +89,7 @@ describe('OpenAPIYaml3_1Parser', () => { uri: '/path/to/openapi', mediaType: mediaTypes.latest('yaml'), }); - const parser = new OpenAPIYaml3_1Parser(); + const parser = new OpenAPIYaml3_1Parser({ fileExtensions: ['.yaml', '.yml'] }); expect(await parser.canParse(file)).toBe(false); }); diff --git a/test/resolver/apidom/reference/parse/parsers/yaml-1-2/index.js b/test/resolver/apidom/reference/parse/parsers/yaml-1-2/index.js index 89ad65795..946ed3c8d 100644 --- a/test/resolver/apidom/reference/parse/parsers/yaml-1-2/index.js +++ b/test/resolver/apidom/reference/parse/parsers/yaml-1-2/index.js @@ -27,7 +27,7 @@ describe('YAMLParser', () => { describe('given file with unknown extension', () => { test('should return false', async () => { const file = new File({ uri: '/path/to/file.txt' }); - const parser = new YAMLParser(); + const parser = new YAMLParser({ fileExtensions: ['.yaml', '.yml'] }); expect(await parser.canParse(file)).toBe(false); }); @@ -36,7 +36,7 @@ describe('YAMLParser', () => { describe('given file with no extension', () => { test('should return false', async () => { const file = new File({ uri: '/path/to/file' }); - const parser = new YAMLParser(); + const parser = new YAMLParser({ fileExtensions: ['.yaml', '.yml'] }); expect(await parser.canParse(file)).toBe(false); });