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
|
@@ -4,45 +4,42 @@ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequ
|
|
|
4
4
|
exports.__esModule = true;
|
|
5
5
|
exports.default = void 0;
|
|
6
6
|
var _apidomCore = require("@swagger-api/apidom-core");
|
|
7
|
-
var _compose = _interopRequireDefault(require("../utils/compose.js"));
|
|
8
7
|
var _toPath = _interopRequireDefault(require("../utils/to-path.js"));
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
class ParameterMacroVisitor {
|
|
9
|
+
parameterMacro;
|
|
10
|
+
options;
|
|
11
|
+
#macroOperation;
|
|
12
|
+
OperationElement = {
|
|
13
|
+
enter: operationElement => {
|
|
14
|
+
this.#macroOperation = operationElement;
|
|
15
|
+
},
|
|
16
|
+
leave: () => {
|
|
17
|
+
this.#macroOperation = undefined;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
ParameterElement = {
|
|
21
|
+
leave: (parameterElement, key, parent, path, ancestors) => {
|
|
22
|
+
const pojoOperation = this.#macroOperation ? (0, _apidomCore.toValue)(this.#macroOperation) : null;
|
|
23
|
+
const pojoParameter = (0, _apidomCore.toValue)(parameterElement);
|
|
24
|
+
try {
|
|
25
|
+
const macroValue = this.parameterMacro(pojoOperation, pojoParameter);
|
|
26
|
+
parameterElement.set('default', macroValue);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
var _this$options$derefer;
|
|
29
|
+
const macroError = new Error(error, {
|
|
30
|
+
cause: error
|
|
31
|
+
});
|
|
32
|
+
macroError.fullPath = (0, _toPath.default)([...ancestors, parent]);
|
|
33
|
+
(_this$options$derefer = this.options.dereference.dereferenceOpts) == null || (_this$options$derefer = _this$options$derefer.errors) == null || _this$options$derefer.push == null || _this$options$derefer.push(macroError);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
constructor({
|
|
11
38
|
parameterMacro,
|
|
12
39
|
options
|
|
13
40
|
}) {
|
|
14
41
|
this.parameterMacro = parameterMacro;
|
|
15
42
|
this.options = options;
|
|
16
|
-
},
|
|
17
|
-
props: {
|
|
18
|
-
parameterMacro: null,
|
|
19
|
-
options: null,
|
|
20
|
-
macroOperation: null,
|
|
21
|
-
OperationElement: {
|
|
22
|
-
enter(operationElement) {
|
|
23
|
-
this.macroOperation = operationElement;
|
|
24
|
-
},
|
|
25
|
-
leave() {
|
|
26
|
-
this.macroOperation = null;
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
ParameterElement: {
|
|
30
|
-
leave(parameterElement, key, parent, path, ancestors) {
|
|
31
|
-
const pojoOperation = this.macroOperation === null ? null : (0, _apidomCore.toValue)(this.macroOperation);
|
|
32
|
-
const pojoParameter = (0, _apidomCore.toValue)(parameterElement);
|
|
33
|
-
try {
|
|
34
|
-
const macroValue = this.parameterMacro(pojoOperation, pojoParameter);
|
|
35
|
-
parameterElement.set('default', macroValue);
|
|
36
|
-
} catch (error) {
|
|
37
|
-
var _this$options$derefer;
|
|
38
|
-
const macroError = new Error(error, {
|
|
39
|
-
cause: error
|
|
40
|
-
});
|
|
41
|
-
macroError.fullPath = (0, _toPath.default)([...ancestors, parent]);
|
|
42
|
-
(_this$options$derefer = this.options.dereference.dereferenceOpts) == null || (_this$options$derefer = _this$options$derefer.errors) == null || _this$options$derefer.push == null || _this$options$derefer.push(macroError);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
43
|
}
|
|
47
|
-
}
|
|
44
|
+
}
|
|
48
45
|
var _default = exports.default = ParameterMacroVisitor;
|
|
@@ -4,39 +4,36 @@ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequ
|
|
|
4
4
|
exports.__esModule = true;
|
|
5
5
|
exports.default = void 0;
|
|
6
6
|
var _apidomCore = require("@swagger-api/apidom-core");
|
|
7
|
-
var _compose = _interopRequireDefault(require("../utils/compose.js"));
|
|
8
7
|
var _toPath = _interopRequireDefault(require("../utils/to-path.js"));
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
class ModelPropertyMacroVisitor {
|
|
9
|
+
modelPropertyMacro;
|
|
10
|
+
options;
|
|
11
|
+
SchemaElement = {
|
|
12
|
+
leave: (schemaElement, key, parent, path, ancestors) => {
|
|
13
|
+
if (typeof schemaElement.properties === 'undefined') return;
|
|
14
|
+
if (!(0, _apidomCore.isObjectElement)(schemaElement.properties)) return;
|
|
15
|
+
schemaElement.properties.forEach(property => {
|
|
16
|
+
if (!(0, _apidomCore.isObjectElement)(property)) return;
|
|
17
|
+
try {
|
|
18
|
+
const macroValue = this.modelPropertyMacro((0, _apidomCore.toValue)(property));
|
|
19
|
+
property.set('default', macroValue);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
var _this$options$derefer;
|
|
22
|
+
const macroError = new Error(error, {
|
|
23
|
+
cause: error
|
|
24
|
+
});
|
|
25
|
+
macroError.fullPath = [...(0, _toPath.default)([...ancestors, parent, schemaElement]), 'properties'];
|
|
26
|
+
(_this$options$derefer = this.options.dereference.dereferenceOpts) == null || (_this$options$derefer = _this$options$derefer.errors) == null || _this$options$derefer.push == null || _this$options$derefer.push(macroError);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
constructor({
|
|
11
32
|
modelPropertyMacro,
|
|
12
33
|
options
|
|
13
34
|
}) {
|
|
14
35
|
this.modelPropertyMacro = modelPropertyMacro;
|
|
15
36
|
this.options = options;
|
|
16
|
-
},
|
|
17
|
-
props: {
|
|
18
|
-
modelPropertyMacro: null,
|
|
19
|
-
options: null,
|
|
20
|
-
SchemaElement: {
|
|
21
|
-
leave(schemaElement, key, parent, path, ancestors) {
|
|
22
|
-
if (typeof schemaElement.properties === 'undefined') return;
|
|
23
|
-
if (!(0, _apidomCore.isObjectElement)(schemaElement.properties)) return;
|
|
24
|
-
schemaElement.properties.forEach(property => {
|
|
25
|
-
if (!(0, _apidomCore.isObjectElement)(property)) return;
|
|
26
|
-
try {
|
|
27
|
-
const macroValue = this.modelPropertyMacro((0, _apidomCore.toValue)(property));
|
|
28
|
-
property.set('default', macroValue);
|
|
29
|
-
} catch (error) {
|
|
30
|
-
var _this$options$derefer;
|
|
31
|
-
const macroError = new Error(error, {
|
|
32
|
-
cause: error
|
|
33
|
-
});
|
|
34
|
-
macroError.fullPath = [...(0, _toPath.default)([...ancestors, parent, schemaElement]), 'properties'];
|
|
35
|
-
(_this$options$derefer = this.options.dereference.dereferenceOpts) == null || (_this$options$derefer = _this$options$derefer.errors) == null || _this$options$derefer.push == null || _this$options$derefer.push(macroError);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
37
|
}
|
|
41
|
-
}
|
|
38
|
+
}
|
|
42
39
|
var _default = exports.default = ModelPropertyMacroVisitor;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _apidomCore = require("@swagger-api/apidom-core");
|
|
7
|
+
var _apidomNsOpenapi = require("@swagger-api/apidom-ns-openapi-3-1");
|
|
8
|
+
var _properties = _interopRequireDefault(require("./properties.js"));
|
|
9
|
+
var _allOf = _interopRequireDefault(require("./all-of.js"));
|
|
10
|
+
var _parameters = _interopRequireDefault(require("./parameters.js"));
|
|
11
|
+
var _dereference = _interopRequireDefault(require("./dereference.js"));
|
|
12
|
+
// eslint-disable-line camelcase
|
|
13
|
+
|
|
14
|
+
const mergeAllVisitorsAsync = _apidomCore.mergeAllVisitors[Symbol.for('nodejs.util.promisify.custom')];
|
|
15
|
+
class RootVisitor {
|
|
16
|
+
constructor({
|
|
17
|
+
parameterMacro,
|
|
18
|
+
modelPropertyMacro,
|
|
19
|
+
mode,
|
|
20
|
+
options,
|
|
21
|
+
...rest
|
|
22
|
+
}) {
|
|
23
|
+
const visitors = [];
|
|
24
|
+
visitors.push(new _dereference.default({
|
|
25
|
+
...rest,
|
|
26
|
+
options
|
|
27
|
+
}));
|
|
28
|
+
if (typeof modelPropertyMacro === 'function') {
|
|
29
|
+
visitors.push(new _properties.default({
|
|
30
|
+
modelPropertyMacro,
|
|
31
|
+
options
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
if (mode !== 'strict') {
|
|
35
|
+
visitors.push(new _allOf.default({
|
|
36
|
+
options
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
if (typeof parameterMacro === 'function') {
|
|
40
|
+
visitors.push(new _parameters.default({
|
|
41
|
+
parameterMacro,
|
|
42
|
+
options
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
const mergedVisitor = mergeAllVisitorsAsync(visitors, {
|
|
46
|
+
nodeTypeGetter: _apidomNsOpenapi.getNodeType
|
|
47
|
+
});
|
|
48
|
+
Object.assign(this, mergedVisitor);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
var _default = exports.default = RootVisitor;
|
|
@@ -4,50 +4,51 @@ exports.__esModule = true;
|
|
|
4
4
|
exports.default = void 0;
|
|
5
5
|
var _apidomCore = require("@swagger-api/apidom-core");
|
|
6
6
|
var _empty = require("@swagger-api/apidom-reference/configuration/empty");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return true;
|
|
23
|
-
} catch (error) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return false;
|
|
28
|
-
},
|
|
29
|
-
async parse(file) {
|
|
30
|
-
if (this.sourceMap) {
|
|
31
|
-
throw new _empty.ParserError("json-swagger-client parser plugin doesn't support sourceMaps option");
|
|
32
|
-
}
|
|
33
|
-
const parseResultElement = new _apidomCore.ParseResultElement();
|
|
34
|
-
const source = file.toString();
|
|
35
|
-
|
|
36
|
-
// allow empty files
|
|
37
|
-
if (this.allowEmpty && source.trim() === '') {
|
|
38
|
-
return parseResultElement;
|
|
39
|
-
}
|
|
7
|
+
class JSONParser extends _empty.Parser {
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
super({
|
|
10
|
+
...options,
|
|
11
|
+
name: 'json-swagger-client',
|
|
12
|
+
fileExtensions: ['.json'],
|
|
13
|
+
mediaTypes: ['application/json']
|
|
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) {
|
|
40
22
|
try {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
parseResultElement.push(element);
|
|
44
|
-
return parseResultElement;
|
|
23
|
+
JSON.parse(file.toString());
|
|
24
|
+
return true;
|
|
45
25
|
} catch (error) {
|
|
46
|
-
|
|
47
|
-
cause: error
|
|
48
|
-
});
|
|
26
|
+
return false;
|
|
49
27
|
}
|
|
50
28
|
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
async parse(file) {
|
|
32
|
+
if (this.sourceMap) {
|
|
33
|
+
throw new _empty.ParserError("json-swagger-client parser plugin doesn't support sourceMaps option");
|
|
34
|
+
}
|
|
35
|
+
const parseResultElement = new _apidomCore.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 element = (0, _apidomCore.from)(JSON.parse(source));
|
|
44
|
+
element.classes.push('result');
|
|
45
|
+
parseResultElement.push(element);
|
|
46
|
+
return parseResultElement;
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw new _empty.ParserError(`Error parsing "${file.uri}"`, {
|
|
49
|
+
cause: error
|
|
50
|
+
});
|
|
51
|
+
}
|
|
51
52
|
}
|
|
52
|
-
}
|
|
53
|
-
var _default = exports.default =
|
|
53
|
+
}
|
|
54
|
+
var _default = exports.default = JSONParser;
|
|
@@ -7,54 +7,55 @@ var _empty = require("@swagger-api/apidom-reference/configuration/empty");
|
|
|
7
7
|
var _apidomNsOpenapi = require("@swagger-api/apidom-ns-openapi-3-1");
|
|
8
8
|
/* eslint-disable camelcase */
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
JSON.parse(source);
|
|
27
|
-
return this.detectionRegExp.test(source);
|
|
28
|
-
} catch (error) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return false;
|
|
33
|
-
},
|
|
34
|
-
async parse(file) {
|
|
35
|
-
if (this.sourceMap) {
|
|
36
|
-
throw new _empty.ParserError("openapi-json-3-1-swagger-client parser plugin doesn't support sourceMaps option");
|
|
37
|
-
}
|
|
38
|
-
const parseResultElement = new _apidomCore.ParseResultElement();
|
|
39
|
-
const source = file.toString();
|
|
40
|
-
|
|
41
|
-
// allow empty files
|
|
42
|
-
if (this.allowEmpty && source.trim() === '') {
|
|
43
|
-
return parseResultElement;
|
|
44
|
-
}
|
|
10
|
+
class OpenAPIJSON3_1Parser extends _empty.Parser {
|
|
11
|
+
detectionRegExp = /"openapi"\s*:\s*"(?<version_json>3\.1\.(?:[1-9]\d*|0))"/;
|
|
12
|
+
constructor(options = {}) {
|
|
13
|
+
super({
|
|
14
|
+
...options,
|
|
15
|
+
name: 'openapi-json-3-1-swagger-client',
|
|
16
|
+
fileExtensions: ['.json'],
|
|
17
|
+
mediaTypes: new _apidomNsOpenapi.OpenAPIMediaTypes(..._apidomNsOpenapi.mediaTypes.filterByFormat('generic'), ..._apidomNsOpenapi.mediaTypes.filterByFormat('json'))
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async canParse(file) {
|
|
21
|
+
const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
|
22
|
+
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
|
23
|
+
if (!hasSupportedFileExtension) return false;
|
|
24
|
+
if (hasSupportedMediaType) return true;
|
|
25
|
+
if (!hasSupportedMediaType) {
|
|
45
26
|
try {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
parseResultElement.push(element);
|
|
50
|
-
return parseResultElement;
|
|
27
|
+
const source = file.toString();
|
|
28
|
+
JSON.parse(source);
|
|
29
|
+
return this.detectionRegExp.test(source);
|
|
51
30
|
} catch (error) {
|
|
52
|
-
|
|
53
|
-
cause: error
|
|
54
|
-
});
|
|
31
|
+
return false;
|
|
55
32
|
}
|
|
56
33
|
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
async parse(file) {
|
|
37
|
+
if (this.sourceMap) {
|
|
38
|
+
throw new _empty.ParserError("openapi-json-3-1-swagger-client parser plugin doesn't support sourceMaps option");
|
|
39
|
+
}
|
|
40
|
+
const parseResultElement = new _apidomCore.ParseResultElement();
|
|
41
|
+
const source = file.toString();
|
|
42
|
+
|
|
43
|
+
// allow empty files
|
|
44
|
+
if (this.allowEmpty && source.trim() === '') {
|
|
45
|
+
return parseResultElement;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const pojo = JSON.parse(source);
|
|
49
|
+
const element = _apidomNsOpenapi.OpenApi3_1Element.refract(pojo, this.refractorOpts);
|
|
50
|
+
element.classes.push('result');
|
|
51
|
+
parseResultElement.push(element);
|
|
52
|
+
return parseResultElement;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
throw new _empty.ParserError(`Error parsing "${file.uri}"`, {
|
|
55
|
+
cause: error
|
|
56
|
+
});
|
|
57
|
+
}
|
|
57
58
|
}
|
|
58
|
-
}
|
|
59
|
-
var _default = exports.default =
|
|
59
|
+
}
|
|
60
|
+
var _default = exports.default = OpenAPIJSON3_1Parser;
|
|
60
61
|
/* eslint-enable camelcase */
|
|
@@ -9,54 +9,55 @@ var _empty = require("@swagger-api/apidom-reference/configuration/empty");
|
|
|
9
9
|
var _apidomNsOpenapi = require("@swagger-api/apidom-ns-openapi-3-1");
|
|
10
10
|
/* eslint-disable camelcase */
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
_jsYaml.default.load(source);
|
|
29
|
-
return this.detectionRegExp.test(source);
|
|
30
|
-
} catch (error) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
},
|
|
36
|
-
async parse(file) {
|
|
37
|
-
if (this.sourceMap) {
|
|
38
|
-
throw new _empty.ParserError("openapi-yaml-3-1-swagger-client parser plugin doesn't support sourceMaps option");
|
|
39
|
-
}
|
|
40
|
-
const parseResultElement = new _apidomCore.ParseResultElement();
|
|
41
|
-
const source = file.toString();
|
|
12
|
+
class OpenAPIYAML31Parser extends _empty.Parser {
|
|
13
|
+
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;
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
super({
|
|
16
|
+
name: 'openapi-yaml-3-1-swagger-client',
|
|
17
|
+
...options,
|
|
18
|
+
fileExtensions: ['.yaml', '.yml'],
|
|
19
|
+
mediaTypes: new _apidomNsOpenapi.OpenAPIMediaTypes(..._apidomNsOpenapi.mediaTypes.filterByFormat('generic'), ..._apidomNsOpenapi.mediaTypes.filterByFormat('yaml'))
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
async canParse(file) {
|
|
23
|
+
const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
|
24
|
+
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
|
25
|
+
if (!hasSupportedFileExtension) return false;
|
|
26
|
+
if (hasSupportedMediaType) return true;
|
|
27
|
+
if (!hasSupportedMediaType) {
|
|
42
28
|
try {
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (this.allowEmpty && typeof pojo === 'undefined') {
|
|
47
|
-
return parseResultElement;
|
|
48
|
-
}
|
|
49
|
-
const element = _apidomNsOpenapi.OpenApi3_1Element.refract(pojo, this.refractorOpts);
|
|
50
|
-
element.classes.push('result');
|
|
51
|
-
parseResultElement.push(element);
|
|
52
|
-
return parseResultElement;
|
|
29
|
+
const source = file.toString();
|
|
30
|
+
_jsYaml.default.load(source);
|
|
31
|
+
return this.detectionRegExp.test(source);
|
|
53
32
|
} catch (error) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
async parse(file) {
|
|
39
|
+
if (this.sourceMap) {
|
|
40
|
+
throw new _empty.ParserError("openapi-yaml-3-1-swagger-client parser plugin doesn't support sourceMaps option");
|
|
41
|
+
}
|
|
42
|
+
const parseResultElement = new _apidomCore.ParseResultElement();
|
|
43
|
+
const source = file.toString();
|
|
44
|
+
try {
|
|
45
|
+
const pojo = _jsYaml.default.load(source, {
|
|
46
|
+
schema: _jsYaml.JSON_SCHEMA
|
|
47
|
+
});
|
|
48
|
+
if (this.allowEmpty && typeof pojo === 'undefined') {
|
|
49
|
+
return parseResultElement;
|
|
57
50
|
}
|
|
51
|
+
const element = _apidomNsOpenapi.OpenApi3_1Element.refract(pojo, this.refractorOpts);
|
|
52
|
+
element.classes.push('result');
|
|
53
|
+
parseResultElement.push(element);
|
|
54
|
+
return parseResultElement;
|
|
55
|
+
} catch (error) {
|
|
56
|
+
throw new _empty.ParserError(`Error parsing "${file.uri}"`, {
|
|
57
|
+
cause: error
|
|
58
|
+
});
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
|
-
}
|
|
61
|
-
var _default = exports.default =
|
|
61
|
+
}
|
|
62
|
+
var _default = exports.default = OpenAPIYAML31Parser;
|
|
62
63
|
/* eslint-enable camelcase */
|
|
@@ -6,53 +6,54 @@ exports.default = void 0;
|
|
|
6
6
|
var _jsYaml = _interopRequireWildcard(require("js-yaml"));
|
|
7
7
|
var _apidomCore = require("@swagger-api/apidom-core");
|
|
8
8
|
var _empty = require("@swagger-api/apidom-reference/configuration/empty");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
schema: _jsYaml.JSON_SCHEMA
|
|
25
|
-
});
|
|
26
|
-
return true;
|
|
27
|
-
} catch (error) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return false;
|
|
32
|
-
},
|
|
33
|
-
async parse(file) {
|
|
34
|
-
if (this.sourceMap) {
|
|
35
|
-
throw new _empty.ParserError("yaml-1-2-swagger-client parser plugin doesn't support sourceMaps option");
|
|
36
|
-
}
|
|
37
|
-
const parseResultElement = new _apidomCore.ParseResultElement();
|
|
38
|
-
const source = file.toString();
|
|
9
|
+
class YAMLParser extends _empty.Parser {
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
super({
|
|
12
|
+
...options,
|
|
13
|
+
name: 'yaml-1-2-swagger-client',
|
|
14
|
+
fileExtensions: ['.yaml', '.yml'],
|
|
15
|
+
mediaTypes: ['text/yaml', 'application/yaml']
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
async canParse(file) {
|
|
19
|
+
const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
|
20
|
+
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
|
21
|
+
if (!hasSupportedFileExtension) return false;
|
|
22
|
+
if (hasSupportedMediaType) return true;
|
|
23
|
+
if (!hasSupportedMediaType) {
|
|
39
24
|
try {
|
|
40
|
-
|
|
25
|
+
_jsYaml.default.load(file.toString(), {
|
|
41
26
|
schema: _jsYaml.JSON_SCHEMA
|
|
42
27
|
});
|
|
43
|
-
|
|
44
|
-
return parseResultElement;
|
|
45
|
-
}
|
|
46
|
-
const element = (0, _apidomCore.from)(pojo);
|
|
47
|
-
element.classes.push('result');
|
|
48
|
-
parseResultElement.push(element);
|
|
49
|
-
return parseResultElement;
|
|
28
|
+
return true;
|
|
50
29
|
} catch (error) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
async parse(file) {
|
|
36
|
+
if (this.sourceMap) {
|
|
37
|
+
throw new _empty.ParserError("yaml-1-2-swagger-client parser plugin doesn't support sourceMaps option");
|
|
38
|
+
}
|
|
39
|
+
const parseResultElement = new _apidomCore.ParseResultElement();
|
|
40
|
+
const source = file.toString();
|
|
41
|
+
try {
|
|
42
|
+
const pojo = _jsYaml.default.load(source, {
|
|
43
|
+
schema: _jsYaml.JSON_SCHEMA
|
|
44
|
+
});
|
|
45
|
+
if (this.allowEmpty && typeof pojo === 'undefined') {
|
|
46
|
+
return parseResultElement;
|
|
54
47
|
}
|
|
48
|
+
const element = (0, _apidomCore.from)(pojo);
|
|
49
|
+
element.classes.push('result');
|
|
50
|
+
parseResultElement.push(element);
|
|
51
|
+
return parseResultElement;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
throw new _empty.ParserError(`Error parsing "${file.uri}"`, {
|
|
54
|
+
cause: error
|
|
55
|
+
});
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
|
-
}
|
|
58
|
-
var _default = exports.default =
|
|
58
|
+
}
|
|
59
|
+
var _default = exports.default = YAMLParser;
|