Skip to content

Commit

Permalink
feat(resolver): loosen requirement for file extensions in ApiDOM pars…
Browse files Browse the repository at this point in the history
…er plugins (#3630)

Refs swagger-api/apidom#4298
  • Loading branch information
char0n authored Aug 9, 2024
1 parent f54afc3 commit e15eb3d
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 28 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions src/resolver/apidom/reference/parse/parsers/json/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"examples": {
"example1": {
"description": "example1 description",
"value": "dmFsMTt2YWwyO3ZhbDMK",
"externalValue": "./ex.csv"
"value": "a2V5OiAidmFsdWU6IHdpdGggOiBjb2xvbnMiIDogYW5vdGhlcl92YWx1ZQo=",
"externalValue": "./ex.dat"
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
key: "value: with : colons" : another_value
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"examples": {
"example1": {
"description": "example1 description",
"externalValue": "./ex.csv"
"externalValue": "./ex.dat"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand Down

0 comments on commit e15eb3d

Please sign in to comment.