swagger-client 3.27.9 → 3.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/swagger-client.browser.js +12494 -12585
- package/dist/swagger-client.browser.min.js +1 -1
- package/dist/swagger-client.browser.min.js.map +1 -1
- package/es/index.js +2 -2
- package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/index.js +81 -119
- package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/all-of.js +66 -69
- package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js +569 -588
- package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/parameters.js +31 -34
- package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/properties.js +25 -28
- package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/root.js +45 -0
- package/es/resolver/apidom/reference/parse/parsers/json/index.js +43 -42
- package/es/resolver/apidom/reference/parse/parsers/openapi-json-3-1/index.js +46 -45
- package/es/resolver/apidom/reference/parse/parsers/openapi-yaml-3-1/index.js +46 -45
- package/es/resolver/apidom/reference/parse/parsers/yaml-1-2/index.js +44 -43
- package/es/resolver/apidom/reference/resolve/resolvers/http-swagger-client/index.js +62 -60
- package/es/resolver/strategies/openapi-3-1-apidom/resolve.js +18 -18
- package/lib/index.js +1 -1
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/index.js +79 -117
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/all-of.js +66 -69
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js +568 -587
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/parameters.js +31 -34
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/properties.js +25 -28
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/root.js +51 -0
- package/lib/resolver/apidom/reference/parse/parsers/json/index.js +43 -42
- package/lib/resolver/apidom/reference/parse/parsers/openapi-json-3-1/index.js +46 -45
- package/lib/resolver/apidom/reference/parse/parsers/openapi-yaml-3-1/index.js +46 -45
- package/lib/resolver/apidom/reference/parse/parsers/yaml-1-2/index.js +44 -43
- package/lib/resolver/apidom/reference/resolve/resolvers/http-swagger-client/index.js +61 -59
- package/lib/resolver/strategies/openapi-3-1-apidom/resolve.js +11 -11
- package/package.json +23 -22
- package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/utils/compose.js +0 -5
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/utils/compose.js +0 -11
|
@@ -1,43 +1,40 @@
|
|
|
1
1
|
import { toValue } from '@swagger-api/apidom-core';
|
|
2
|
-
import compose from '../utils/compose.js';
|
|
3
2
|
import toPath from '../utils/to-path.js';
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
class ParameterMacroVisitor {
|
|
4
|
+
parameterMacro;
|
|
5
|
+
options;
|
|
6
|
+
#macroOperation;
|
|
7
|
+
OperationElement = {
|
|
8
|
+
enter: operationElement => {
|
|
9
|
+
this.#macroOperation = operationElement;
|
|
10
|
+
},
|
|
11
|
+
leave: () => {
|
|
12
|
+
this.#macroOperation = undefined;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
ParameterElement = {
|
|
16
|
+
leave: (parameterElement, key, parent, path, ancestors) => {
|
|
17
|
+
const pojoOperation = this.#macroOperation ? toValue(this.#macroOperation) : null;
|
|
18
|
+
const pojoParameter = toValue(parameterElement);
|
|
19
|
+
try {
|
|
20
|
+
const macroValue = this.parameterMacro(pojoOperation, pojoParameter);
|
|
21
|
+
parameterElement.set('default', macroValue);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
var _this$options$derefer, _this$options$derefer2;
|
|
24
|
+
const macroError = new Error(error, {
|
|
25
|
+
cause: error
|
|
26
|
+
});
|
|
27
|
+
macroError.fullPath = toPath([...ancestors, parent]);
|
|
28
|
+
(_this$options$derefer = this.options.dereference.dereferenceOpts) === null || _this$options$derefer === void 0 || (_this$options$derefer = _this$options$derefer.errors) === null || _this$options$derefer === void 0 || (_this$options$derefer2 = _this$options$derefer.push) === null || _this$options$derefer2 === void 0 || _this$options$derefer2.call(_this$options$derefer, macroError);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
constructor({
|
|
6
33
|
parameterMacro,
|
|
7
34
|
options
|
|
8
35
|
}) {
|
|
9
36
|
this.parameterMacro = parameterMacro;
|
|
10
37
|
this.options = options;
|
|
11
|
-
},
|
|
12
|
-
props: {
|
|
13
|
-
parameterMacro: null,
|
|
14
|
-
options: null,
|
|
15
|
-
macroOperation: null,
|
|
16
|
-
OperationElement: {
|
|
17
|
-
enter(operationElement) {
|
|
18
|
-
this.macroOperation = operationElement;
|
|
19
|
-
},
|
|
20
|
-
leave() {
|
|
21
|
-
this.macroOperation = null;
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
ParameterElement: {
|
|
25
|
-
leave(parameterElement, key, parent, path, ancestors) {
|
|
26
|
-
const pojoOperation = this.macroOperation === null ? null : toValue(this.macroOperation);
|
|
27
|
-
const pojoParameter = toValue(parameterElement);
|
|
28
|
-
try {
|
|
29
|
-
const macroValue = this.parameterMacro(pojoOperation, pojoParameter);
|
|
30
|
-
parameterElement.set('default', macroValue);
|
|
31
|
-
} catch (error) {
|
|
32
|
-
var _this$options$derefer, _this$options$derefer2;
|
|
33
|
-
const macroError = new Error(error, {
|
|
34
|
-
cause: error
|
|
35
|
-
});
|
|
36
|
-
macroError.fullPath = toPath([...ancestors, parent]);
|
|
37
|
-
(_this$options$derefer = this.options.dereference.dereferenceOpts) === null || _this$options$derefer === void 0 || (_this$options$derefer = _this$options$derefer.errors) === null || _this$options$derefer === void 0 || (_this$options$derefer2 = _this$options$derefer.push) === null || _this$options$derefer2 === void 0 || _this$options$derefer2.call(_this$options$derefer, macroError);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
38
|
}
|
|
42
|
-
}
|
|
39
|
+
}
|
|
43
40
|
export default ParameterMacroVisitor;
|
|
@@ -1,37 +1,34 @@
|
|
|
1
1
|
import { isObjectElement, toValue } from '@swagger-api/apidom-core';
|
|
2
|
-
import compose from '../utils/compose.js';
|
|
3
2
|
import toPath from '../utils/to-path.js';
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
class ModelPropertyMacroVisitor {
|
|
4
|
+
modelPropertyMacro;
|
|
5
|
+
options;
|
|
6
|
+
SchemaElement = {
|
|
7
|
+
leave: (schemaElement, key, parent, path, ancestors) => {
|
|
8
|
+
if (typeof schemaElement.properties === 'undefined') return;
|
|
9
|
+
if (!isObjectElement(schemaElement.properties)) return;
|
|
10
|
+
schemaElement.properties.forEach(property => {
|
|
11
|
+
if (!isObjectElement(property)) return;
|
|
12
|
+
try {
|
|
13
|
+
const macroValue = this.modelPropertyMacro(toValue(property));
|
|
14
|
+
property.set('default', macroValue);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
var _this$options$derefer, _this$options$derefer2;
|
|
17
|
+
const macroError = new Error(error, {
|
|
18
|
+
cause: error
|
|
19
|
+
});
|
|
20
|
+
macroError.fullPath = [...toPath([...ancestors, parent, schemaElement]), 'properties'];
|
|
21
|
+
(_this$options$derefer = this.options.dereference.dereferenceOpts) === null || _this$options$derefer === void 0 || (_this$options$derefer = _this$options$derefer.errors) === null || _this$options$derefer === void 0 || (_this$options$derefer2 = _this$options$derefer.push) === null || _this$options$derefer2 === void 0 || _this$options$derefer2.call(_this$options$derefer, macroError);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
constructor({
|
|
6
27
|
modelPropertyMacro,
|
|
7
28
|
options
|
|
8
29
|
}) {
|
|
9
30
|
this.modelPropertyMacro = modelPropertyMacro;
|
|
10
31
|
this.options = options;
|
|
11
|
-
},
|
|
12
|
-
props: {
|
|
13
|
-
modelPropertyMacro: null,
|
|
14
|
-
options: null,
|
|
15
|
-
SchemaElement: {
|
|
16
|
-
leave(schemaElement, key, parent, path, ancestors) {
|
|
17
|
-
if (typeof schemaElement.properties === 'undefined') return;
|
|
18
|
-
if (!isObjectElement(schemaElement.properties)) return;
|
|
19
|
-
schemaElement.properties.forEach(property => {
|
|
20
|
-
if (!isObjectElement(property)) return;
|
|
21
|
-
try {
|
|
22
|
-
const macroValue = this.modelPropertyMacro(toValue(property));
|
|
23
|
-
property.set('default', macroValue);
|
|
24
|
-
} catch (error) {
|
|
25
|
-
var _this$options$derefer, _this$options$derefer2;
|
|
26
|
-
const macroError = new Error(error, {
|
|
27
|
-
cause: error
|
|
28
|
-
});
|
|
29
|
-
macroError.fullPath = [...toPath([...ancestors, parent, schemaElement]), 'properties'];
|
|
30
|
-
(_this$options$derefer = this.options.dereference.dereferenceOpts) === null || _this$options$derefer === void 0 || (_this$options$derefer = _this$options$derefer.errors) === null || _this$options$derefer === void 0 || (_this$options$derefer2 = _this$options$derefer.push) === null || _this$options$derefer2 === void 0 || _this$options$derefer2.call(_this$options$derefer, macroError);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
32
|
}
|
|
36
|
-
}
|
|
33
|
+
}
|
|
37
34
|
export default ModelPropertyMacroVisitor;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { mergeAllVisitors } from '@swagger-api/apidom-core';
|
|
2
|
+
import { getNodeType } from '@swagger-api/apidom-ns-openapi-3-1';
|
|
3
|
+
import ModelPropertyMacroVisitor from './properties.js';
|
|
4
|
+
import AllOfVisitor from './all-of.js';
|
|
5
|
+
import ParameterMacroVisitor from './parameters.js';
|
|
6
|
+
import OpenAPI3_1SwaggerClientDereferenceVisitor from './dereference.js'; // eslint-disable-line camelcase
|
|
7
|
+
|
|
8
|
+
const mergeAllVisitorsAsync = mergeAllVisitors[Symbol.for('nodejs.util.promisify.custom')];
|
|
9
|
+
class RootVisitor {
|
|
10
|
+
constructor({
|
|
11
|
+
parameterMacro,
|
|
12
|
+
modelPropertyMacro,
|
|
13
|
+
mode,
|
|
14
|
+
options,
|
|
15
|
+
...rest
|
|
16
|
+
}) {
|
|
17
|
+
const visitors = [];
|
|
18
|
+
visitors.push(new OpenAPI3_1SwaggerClientDereferenceVisitor({
|
|
19
|
+
...rest,
|
|
20
|
+
options
|
|
21
|
+
}));
|
|
22
|
+
if (typeof modelPropertyMacro === 'function') {
|
|
23
|
+
visitors.push(new ModelPropertyMacroVisitor({
|
|
24
|
+
modelPropertyMacro,
|
|
25
|
+
options
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
if (mode !== 'strict') {
|
|
29
|
+
visitors.push(new AllOfVisitor({
|
|
30
|
+
options
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
if (typeof parameterMacro === 'function') {
|
|
34
|
+
visitors.push(new ParameterMacroVisitor({
|
|
35
|
+
parameterMacro,
|
|
36
|
+
options
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
const mergedVisitor = mergeAllVisitorsAsync(visitors, {
|
|
40
|
+
nodeTypeGetter: getNodeType
|
|
41
|
+
});
|
|
42
|
+
Object.assign(this, mergedVisitor);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export default RootVisitor;
|
|
@@ -1,49 +1,50 @@
|
|
|
1
1
|
import { from, ParseResultElement } from '@swagger-api/apidom-core';
|
|
2
2
|
import { ParserError, Parser } from '@swagger-api/apidom-reference/configuration/empty';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return true;
|
|
19
|
-
} catch (error) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return false;
|
|
24
|
-
},
|
|
25
|
-
async parse(file) {
|
|
26
|
-
if (this.sourceMap) {
|
|
27
|
-
throw new ParserError("json-swagger-client parser plugin doesn't support sourceMaps option");
|
|
28
|
-
}
|
|
29
|
-
const parseResultElement = new ParseResultElement();
|
|
30
|
-
const source = file.toString();
|
|
31
|
-
|
|
32
|
-
// allow empty files
|
|
33
|
-
if (this.allowEmpty && source.trim() === '') {
|
|
34
|
-
return parseResultElement;
|
|
35
|
-
}
|
|
3
|
+
class JSONParser extends Parser {
|
|
4
|
+
constructor(options = {}) {
|
|
5
|
+
super({
|
|
6
|
+
...options,
|
|
7
|
+
name: 'json-swagger-client',
|
|
8
|
+
fileExtensions: ['.json'],
|
|
9
|
+
mediaTypes: ['application/json']
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
async canParse(file) {
|
|
13
|
+
const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
|
14
|
+
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
|
15
|
+
if (!hasSupportedFileExtension) return false;
|
|
16
|
+
if (hasSupportedMediaType) return true;
|
|
17
|
+
if (!hasSupportedMediaType) {
|
|
36
18
|
try {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
parseResultElement.push(element);
|
|
40
|
-
return parseResultElement;
|
|
19
|
+
JSON.parse(file.toString());
|
|
20
|
+
return true;
|
|
41
21
|
} catch (error) {
|
|
42
|
-
|
|
43
|
-
cause: error
|
|
44
|
-
});
|
|
22
|
+
return false;
|
|
45
23
|
}
|
|
46
24
|
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
async parse(file) {
|
|
28
|
+
if (this.sourceMap) {
|
|
29
|
+
throw new ParserError("json-swagger-client parser plugin doesn't support sourceMaps option");
|
|
30
|
+
}
|
|
31
|
+
const parseResultElement = new ParseResultElement();
|
|
32
|
+
const source = file.toString();
|
|
33
|
+
|
|
34
|
+
// allow empty files
|
|
35
|
+
if (this.allowEmpty && source.trim() === '') {
|
|
36
|
+
return parseResultElement;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const element = from(JSON.parse(source));
|
|
40
|
+
element.classes.push('result');
|
|
41
|
+
parseResultElement.push(element);
|
|
42
|
+
return parseResultElement;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
throw new ParserError(`Error parsing "${file.uri}"`, {
|
|
45
|
+
cause: error
|
|
46
|
+
});
|
|
47
|
+
}
|
|
47
48
|
}
|
|
48
|
-
}
|
|
49
|
-
export default
|
|
49
|
+
}
|
|
50
|
+
export default JSONParser;
|
|
@@ -2,54 +2,55 @@
|
|
|
2
2
|
import { ParseResultElement } from '@swagger-api/apidom-core';
|
|
3
3
|
import { ParserError, Parser } from '@swagger-api/apidom-reference/configuration/empty';
|
|
4
4
|
import { mediaTypes, OpenApi3_1Element, OpenAPIMediaTypes } from '@swagger-api/apidom-ns-openapi-3-1';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
JSON.parse(source);
|
|
22
|
-
return this.detectionRegExp.test(source);
|
|
23
|
-
} catch (error) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return false;
|
|
28
|
-
},
|
|
29
|
-
async parse(file) {
|
|
30
|
-
if (this.sourceMap) {
|
|
31
|
-
throw new ParserError("openapi-json-3-1-swagger-client parser plugin doesn't support sourceMaps option");
|
|
32
|
-
}
|
|
33
|
-
const parseResultElement = new ParseResultElement();
|
|
34
|
-
const source = file.toString();
|
|
35
|
-
|
|
36
|
-
// allow empty files
|
|
37
|
-
if (this.allowEmpty && source.trim() === '') {
|
|
38
|
-
return parseResultElement;
|
|
39
|
-
}
|
|
5
|
+
class OpenAPIJSON3_1Parser extends Parser {
|
|
6
|
+
detectionRegExp = /"openapi"\s*:\s*"(?<version_json>3\.1\.(?:[1-9]\d*|0))"/;
|
|
7
|
+
constructor(options = {}) {
|
|
8
|
+
super({
|
|
9
|
+
...options,
|
|
10
|
+
name: 'openapi-json-3-1-swagger-client',
|
|
11
|
+
fileExtensions: ['.json'],
|
|
12
|
+
mediaTypes: new OpenAPIMediaTypes(...mediaTypes.filterByFormat('generic'), ...mediaTypes.filterByFormat('json'))
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
async canParse(file) {
|
|
16
|
+
const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
|
17
|
+
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
|
18
|
+
if (!hasSupportedFileExtension) return false;
|
|
19
|
+
if (hasSupportedMediaType) return true;
|
|
20
|
+
if (!hasSupportedMediaType) {
|
|
40
21
|
try {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
parseResultElement.push(element);
|
|
45
|
-
return parseResultElement;
|
|
22
|
+
const source = file.toString();
|
|
23
|
+
JSON.parse(source);
|
|
24
|
+
return this.detectionRegExp.test(source);
|
|
46
25
|
} catch (error) {
|
|
47
|
-
|
|
48
|
-
cause: error
|
|
49
|
-
});
|
|
26
|
+
return false;
|
|
50
27
|
}
|
|
51
28
|
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
async parse(file) {
|
|
32
|
+
if (this.sourceMap) {
|
|
33
|
+
throw new ParserError("openapi-json-3-1-swagger-client parser plugin doesn't support sourceMaps option");
|
|
34
|
+
}
|
|
35
|
+
const parseResultElement = new ParseResultElement();
|
|
36
|
+
const source = file.toString();
|
|
37
|
+
|
|
38
|
+
// allow empty files
|
|
39
|
+
if (this.allowEmpty && source.trim() === '') {
|
|
40
|
+
return parseResultElement;
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const pojo = JSON.parse(source);
|
|
44
|
+
const element = OpenApi3_1Element.refract(pojo, this.refractorOpts);
|
|
45
|
+
element.classes.push('result');
|
|
46
|
+
parseResultElement.push(element);
|
|
47
|
+
return parseResultElement;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
throw new ParserError(`Error parsing "${file.uri}"`, {
|
|
50
|
+
cause: error
|
|
51
|
+
});
|
|
52
|
+
}
|
|
52
53
|
}
|
|
53
|
-
}
|
|
54
|
-
export default
|
|
54
|
+
}
|
|
55
|
+
export default OpenAPIJSON3_1Parser;
|
|
55
56
|
/* eslint-enable camelcase */
|
|
@@ -3,54 +3,55 @@ import YAML, { JSON_SCHEMA } from 'js-yaml';
|
|
|
3
3
|
import { ParseResultElement } from '@swagger-api/apidom-core';
|
|
4
4
|
import { ParserError, Parser } from '@swagger-api/apidom-reference/configuration/empty';
|
|
5
5
|
import { mediaTypes, OpenApi3_1Element, OpenAPIMediaTypes } from '@swagger-api/apidom-ns-openapi-3-1';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
YAML.load(source);
|
|
23
|
-
return this.detectionRegExp.test(source);
|
|
24
|
-
} catch (error) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
29
|
-
},
|
|
30
|
-
async parse(file) {
|
|
31
|
-
if (this.sourceMap) {
|
|
32
|
-
throw new ParserError("openapi-yaml-3-1-swagger-client parser plugin doesn't support sourceMaps option");
|
|
33
|
-
}
|
|
34
|
-
const parseResultElement = new ParseResultElement();
|
|
35
|
-
const source = file.toString();
|
|
6
|
+
class OpenAPIYAML31Parser extends Parser {
|
|
7
|
+
detectionRegExp = /(?<YAML>^(["']?)openapi\2\s*:\s*(["']?)(?<version_yaml>3\.1\.(?:[1-9]\d*|0))\3(?:\s+|$))|(?<JSON>"openapi"\s*:\s*"(?<version_json>3\.1\.(?:[1-9]\d*|0))")/m;
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
super({
|
|
10
|
+
name: 'openapi-yaml-3-1-swagger-client',
|
|
11
|
+
...options,
|
|
12
|
+
fileExtensions: ['.yaml', '.yml'],
|
|
13
|
+
mediaTypes: new OpenAPIMediaTypes(...mediaTypes.filterByFormat('generic'), ...mediaTypes.filterByFormat('yaml'))
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
async canParse(file) {
|
|
17
|
+
const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
|
18
|
+
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
|
19
|
+
if (!hasSupportedFileExtension) return false;
|
|
20
|
+
if (hasSupportedMediaType) return true;
|
|
21
|
+
if (!hasSupportedMediaType) {
|
|
36
22
|
try {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (this.allowEmpty && typeof pojo === 'undefined') {
|
|
41
|
-
return parseResultElement;
|
|
42
|
-
}
|
|
43
|
-
const element = OpenApi3_1Element.refract(pojo, this.refractorOpts);
|
|
44
|
-
element.classes.push('result');
|
|
45
|
-
parseResultElement.push(element);
|
|
46
|
-
return parseResultElement;
|
|
23
|
+
const source = file.toString();
|
|
24
|
+
YAML.load(source);
|
|
25
|
+
return this.detectionRegExp.test(source);
|
|
47
26
|
} catch (error) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
async parse(file) {
|
|
33
|
+
if (this.sourceMap) {
|
|
34
|
+
throw new ParserError("openapi-yaml-3-1-swagger-client parser plugin doesn't support sourceMaps option");
|
|
35
|
+
}
|
|
36
|
+
const parseResultElement = new ParseResultElement();
|
|
37
|
+
const source = file.toString();
|
|
38
|
+
try {
|
|
39
|
+
const pojo = YAML.load(source, {
|
|
40
|
+
schema: JSON_SCHEMA
|
|
41
|
+
});
|
|
42
|
+
if (this.allowEmpty && typeof pojo === 'undefined') {
|
|
43
|
+
return parseResultElement;
|
|
51
44
|
}
|
|
45
|
+
const element = OpenApi3_1Element.refract(pojo, this.refractorOpts);
|
|
46
|
+
element.classes.push('result');
|
|
47
|
+
parseResultElement.push(element);
|
|
48
|
+
return parseResultElement;
|
|
49
|
+
} catch (error) {
|
|
50
|
+
throw new ParserError(`Error parsing "${file.uri}"`, {
|
|
51
|
+
cause: error
|
|
52
|
+
});
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
|
-
}
|
|
55
|
-
export default
|
|
55
|
+
}
|
|
56
|
+
export default OpenAPIYAML31Parser;
|
|
56
57
|
/* eslint-enable camelcase */
|
|
@@ -1,53 +1,54 @@
|
|
|
1
1
|
import YAML, { JSON_SCHEMA } from 'js-yaml';
|
|
2
2
|
import { from, ParseResultElement } from '@swagger-api/apidom-core';
|
|
3
3
|
import { ParserError, Parser } from '@swagger-api/apidom-reference/configuration/empty';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
schema: JSON_SCHEMA
|
|
20
|
-
});
|
|
21
|
-
return true;
|
|
22
|
-
} catch (error) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return false;
|
|
27
|
-
},
|
|
28
|
-
async parse(file) {
|
|
29
|
-
if (this.sourceMap) {
|
|
30
|
-
throw new ParserError("yaml-1-2-swagger-client parser plugin doesn't support sourceMaps option");
|
|
31
|
-
}
|
|
32
|
-
const parseResultElement = new ParseResultElement();
|
|
33
|
-
const source = file.toString();
|
|
4
|
+
class YAMLParser extends Parser {
|
|
5
|
+
constructor(options = {}) {
|
|
6
|
+
super({
|
|
7
|
+
...options,
|
|
8
|
+
name: 'yaml-1-2-swagger-client',
|
|
9
|
+
fileExtensions: ['.yaml', '.yml'],
|
|
10
|
+
mediaTypes: ['text/yaml', 'application/yaml']
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
async canParse(file) {
|
|
14
|
+
const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
|
15
|
+
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
|
16
|
+
if (!hasSupportedFileExtension) return false;
|
|
17
|
+
if (hasSupportedMediaType) return true;
|
|
18
|
+
if (!hasSupportedMediaType) {
|
|
34
19
|
try {
|
|
35
|
-
|
|
20
|
+
YAML.load(file.toString(), {
|
|
36
21
|
schema: JSON_SCHEMA
|
|
37
22
|
});
|
|
38
|
-
|
|
39
|
-
return parseResultElement;
|
|
40
|
-
}
|
|
41
|
-
const element = from(pojo);
|
|
42
|
-
element.classes.push('result');
|
|
43
|
-
parseResultElement.push(element);
|
|
44
|
-
return parseResultElement;
|
|
23
|
+
return true;
|
|
45
24
|
} catch (error) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
async parse(file) {
|
|
31
|
+
if (this.sourceMap) {
|
|
32
|
+
throw new ParserError("yaml-1-2-swagger-client parser plugin doesn't support sourceMaps option");
|
|
33
|
+
}
|
|
34
|
+
const parseResultElement = new ParseResultElement();
|
|
35
|
+
const source = file.toString();
|
|
36
|
+
try {
|
|
37
|
+
const pojo = YAML.load(source, {
|
|
38
|
+
schema: JSON_SCHEMA
|
|
39
|
+
});
|
|
40
|
+
if (this.allowEmpty && typeof pojo === 'undefined') {
|
|
41
|
+
return parseResultElement;
|
|
49
42
|
}
|
|
43
|
+
const element = from(pojo);
|
|
44
|
+
element.classes.push('result');
|
|
45
|
+
parseResultElement.push(element);
|
|
46
|
+
return parseResultElement;
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw new ParserError(`Error parsing "${file.uri}"`, {
|
|
49
|
+
cause: error
|
|
50
|
+
});
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
|
-
}
|
|
53
|
-
export default
|
|
53
|
+
}
|
|
54
|
+
export default YAMLParser;
|