swagger-client 3.10.8 → 3.10.12
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/README.md +10 -2
- package/dist/swagger-client.browser.js +24191 -0
- package/dist/swagger-client.browser.min.js +3 -0
- package/dist/swagger-client.browser.min.js.map +1 -0
- package/es/commonjs.js +9 -0
- package/es/constants.js +2 -0
- package/es/execute/index.js +391 -0
- package/es/execute/oas3/build-request.js +149 -0
- package/es/execute/oas3/content-serializer.js +18 -0
- package/es/execute/oas3/parameter-builders.js +119 -0
- package/es/execute/oas3/style-serializer.js +232 -0
- package/es/execute/swagger2/build-request.js +119 -0
- package/es/execute/swagger2/parameter-builders.js +78 -0
- package/es/helpers.js +272 -0
- package/es/http.js +621 -0
- package/es/index.js +116 -0
- package/es/interfaces.js +145 -0
- package/es/internal/form-data-monkey-patch.js +94 -0
- package/es/resolver.js +123 -0
- package/es/specmap/helpers.js +62 -0
- package/es/specmap/index.js +613 -0
- package/es/specmap/lib/all-of.js +81 -0
- package/es/specmap/lib/context-tree.js +111 -0
- package/es/specmap/lib/create-error.js +24 -0
- package/es/specmap/lib/index.js +391 -0
- package/es/specmap/lib/parameters.js +31 -0
- package/es/specmap/lib/properties.js +23 -0
- package/es/specmap/lib/refs.js +516 -0
- package/es/subtree-resolver/index.js +92 -0
- package/lib/commonjs.js +10 -0
- package/lib/constants.js +7 -0
- package/lib/execute/index.js +421 -0
- package/lib/execute/oas3/build-request.js +161 -0
- package/lib/execute/oas3/content-serializer.js +21 -0
- package/lib/execute/oas3/parameter-builders.js +138 -0
- package/lib/execute/oas3/style-serializer.js +208 -0
- package/lib/execute/swagger2/build-request.js +120 -0
- package/lib/execute/swagger2/parameter-builders.js +88 -0
- package/lib/helpers.js +261 -0
- package/lib/http.js +470 -0
- package/lib/index.js +142 -0
- package/lib/interfaces.js +159 -0
- package/lib/internal/form-data-monkey-patch.js +83 -0
- package/lib/resolver.js +125 -0
- package/lib/specmap/helpers.js +65 -0
- package/lib/specmap/index.js +446 -0
- package/lib/specmap/lib/all-of.js +89 -0
- package/lib/specmap/lib/context-tree.js +111 -0
- package/lib/specmap/lib/create-error.js +25 -0
- package/lib/specmap/lib/index.js +402 -0
- package/lib/specmap/lib/parameters.js +42 -0
- package/lib/specmap/lib/properties.js +38 -0
- package/lib/specmap/lib/refs.js +509 -0
- package/lib/subtree-resolver/index.js +55 -0
- package/package.json +80 -106
- package/browser/index.js +0 -54
- package/dist/index.js +0 -4372
package/es/index.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime-corejs2/helpers/objectSpread2";
|
|
2
|
+
import assign from 'lodash/assign';
|
|
3
|
+
import startsWith from 'lodash/startsWith';
|
|
4
|
+
import Url from 'url';
|
|
5
|
+
import Http, { makeHttp, serializeRes, serializeHeaders } from './http';
|
|
6
|
+
import Resolver, { clearCache } from './resolver';
|
|
7
|
+
import resolveSubtree from './subtree-resolver';
|
|
8
|
+
import { makeApisTagOperation } from './interfaces';
|
|
9
|
+
import { execute, buildRequest, baseUrl } from './execute';
|
|
10
|
+
import { opId } from './helpers';
|
|
11
|
+
Swagger.http = Http;
|
|
12
|
+
Swagger.makeHttp = makeHttp.bind(null, Swagger.http);
|
|
13
|
+
Swagger.resolve = Resolver;
|
|
14
|
+
Swagger.resolveSubtree = resolveSubtree;
|
|
15
|
+
Swagger.execute = execute;
|
|
16
|
+
Swagger.serializeRes = serializeRes;
|
|
17
|
+
Swagger.serializeHeaders = serializeHeaders;
|
|
18
|
+
Swagger.clearCache = clearCache;
|
|
19
|
+
Swagger.makeApisTagOperation = makeApisTagOperation;
|
|
20
|
+
Swagger.buildRequest = buildRequest;
|
|
21
|
+
Swagger.helpers = {
|
|
22
|
+
opId: opId
|
|
23
|
+
};
|
|
24
|
+
Swagger.getBaseUrl = baseUrl;
|
|
25
|
+
|
|
26
|
+
function Swagger(url) {
|
|
27
|
+
var _this = this;
|
|
28
|
+
|
|
29
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
30
|
+
|
|
31
|
+
// Allow url as a separate argument
|
|
32
|
+
if (typeof url === 'string') {
|
|
33
|
+
opts.url = url;
|
|
34
|
+
} else {
|
|
35
|
+
opts = url;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!(this instanceof Swagger)) {
|
|
39
|
+
return new Swagger(opts);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
assign(this, opts);
|
|
43
|
+
var prom = this.resolve().then(function () {
|
|
44
|
+
if (!_this.disableInterfaces) {
|
|
45
|
+
assign(_this, Swagger.makeApisTagOperation(_this));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return _this;
|
|
49
|
+
}); // Expose this instance on the promise that gets returned
|
|
50
|
+
|
|
51
|
+
prom.client = this;
|
|
52
|
+
return prom;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
Swagger.prototype = {
|
|
56
|
+
http: Http,
|
|
57
|
+
execute: function execute(options) {
|
|
58
|
+
this.applyDefaults();
|
|
59
|
+
return Swagger.execute(_objectSpread({
|
|
60
|
+
spec: this.spec,
|
|
61
|
+
http: this.http,
|
|
62
|
+
securities: {
|
|
63
|
+
authorized: this.authorizations
|
|
64
|
+
},
|
|
65
|
+
contextUrl: typeof this.url === 'string' ? this.url : undefined,
|
|
66
|
+
requestInterceptor: this.requestInterceptor || null,
|
|
67
|
+
responseInterceptor: this.responseInterceptor || null
|
|
68
|
+
}, options));
|
|
69
|
+
},
|
|
70
|
+
resolve: function resolve() {
|
|
71
|
+
var _this2 = this;
|
|
72
|
+
|
|
73
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
74
|
+
return Swagger.resolve(_objectSpread({
|
|
75
|
+
spec: this.spec,
|
|
76
|
+
url: this.url,
|
|
77
|
+
http: this.http || this.fetch,
|
|
78
|
+
allowMetaPatches: this.allowMetaPatches,
|
|
79
|
+
useCircularStructures: this.useCircularStructures,
|
|
80
|
+
requestInterceptor: this.requestInterceptor || null,
|
|
81
|
+
responseInterceptor: this.responseInterceptor || null
|
|
82
|
+
}, options)).then(function (obj) {
|
|
83
|
+
_this2.originalSpec = _this2.spec;
|
|
84
|
+
_this2.spec = obj.spec;
|
|
85
|
+
_this2.errors = obj.errors;
|
|
86
|
+
return _this2;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
Swagger.prototype.applyDefaults = function applyDefaults() {
|
|
92
|
+
var spec = this.spec;
|
|
93
|
+
var specUrl = this.url; // TODO: OAS3: support servers here
|
|
94
|
+
|
|
95
|
+
if (specUrl && startsWith(specUrl, 'http')) {
|
|
96
|
+
var parsed = Url.parse(specUrl);
|
|
97
|
+
|
|
98
|
+
if (!spec.host) {
|
|
99
|
+
spec.host = parsed.host;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!spec.schemes) {
|
|
103
|
+
spec.schemes = [parsed.protocol.replace(':', '')];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (!spec.basePath) {
|
|
107
|
+
spec.basePath = '/';
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}; // add backwards compatibility with older versions of swagger-ui
|
|
111
|
+
// Refs https://github.com/swagger-api/swagger-ui/issues/6210
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
var helpers = Swagger.helpers;
|
|
115
|
+
export { helpers };
|
|
116
|
+
export default Swagger;
|
package/es/interfaces.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime-corejs2/helpers/objectSpread2";
|
|
2
|
+
import _Array$isArray from "@babel/runtime-corejs2/core-js/array/is-array";
|
|
3
|
+
import pick from 'lodash/pick';
|
|
4
|
+
import { eachOperation, opId } from './helpers';
|
|
5
|
+
|
|
6
|
+
var nullFn = function nullFn() {
|
|
7
|
+
return null;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
var normalizeArray = function normalizeArray(arg) {
|
|
11
|
+
return _Array$isArray(arg) ? arg : [arg];
|
|
12
|
+
}; // To allow stubbing of functions
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export var self = {
|
|
16
|
+
mapTagOperations: mapTagOperations,
|
|
17
|
+
makeExecute: makeExecute
|
|
18
|
+
}; // Make an execute, bound to arguments defined in mapTagOperation's callback (cb)
|
|
19
|
+
|
|
20
|
+
export function makeExecute() {
|
|
21
|
+
var swaggerJs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
22
|
+
return function (_ref) {
|
|
23
|
+
var pathName = _ref.pathName,
|
|
24
|
+
method = _ref.method,
|
|
25
|
+
operationId = _ref.operationId;
|
|
26
|
+
return function (parameters) {
|
|
27
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
28
|
+
return swaggerJs.execute(_objectSpread(_objectSpread({
|
|
29
|
+
spec: swaggerJs.spec
|
|
30
|
+
}, pick(swaggerJs, 'requestInterceptor', 'responseInterceptor', 'userFetch')), {}, {
|
|
31
|
+
pathName: pathName,
|
|
32
|
+
method: method,
|
|
33
|
+
parameters: parameters,
|
|
34
|
+
operationId: operationId
|
|
35
|
+
}, opts));
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
} // Creates an interface with tags+operations = execute
|
|
39
|
+
// The shape
|
|
40
|
+
// { apis: { [tag]: { operations: [operation]: { execute }}}}
|
|
41
|
+
// NOTE: this is mostly for compatibility
|
|
42
|
+
|
|
43
|
+
export function makeApisTagOperationsOperationExecute() {
|
|
44
|
+
var swaggerJs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
45
|
+
// { apis: tag: operations: execute }
|
|
46
|
+
var cb = self.makeExecute(swaggerJs);
|
|
47
|
+
var tagOperations = self.mapTagOperations({
|
|
48
|
+
v2OperationIdCompatibilityMode: swaggerJs.v2OperationIdCompatibilityMode,
|
|
49
|
+
spec: swaggerJs.spec,
|
|
50
|
+
cb: cb
|
|
51
|
+
});
|
|
52
|
+
var apis = {}; // eslint-disable-next-line no-restricted-syntax, guard-for-in
|
|
53
|
+
|
|
54
|
+
for (var tag in tagOperations) {
|
|
55
|
+
apis[tag] = {
|
|
56
|
+
operations: {}
|
|
57
|
+
}; // eslint-disable-next-line no-restricted-syntax, guard-for-in
|
|
58
|
+
|
|
59
|
+
for (var op in tagOperations[tag]) {
|
|
60
|
+
apis[tag].operations[op] = {
|
|
61
|
+
execute: tagOperations[tag][op]
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
apis: apis
|
|
68
|
+
};
|
|
69
|
+
} // .apis[tag][operationId]:ExecuteFunction interface
|
|
70
|
+
|
|
71
|
+
export function makeApisTagOperation() {
|
|
72
|
+
var swaggerJs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
73
|
+
var cb = self.makeExecute(swaggerJs);
|
|
74
|
+
return {
|
|
75
|
+
apis: self.mapTagOperations({
|
|
76
|
+
v2OperationIdCompatibilityMode: swaggerJs.v2OperationIdCompatibilityMode,
|
|
77
|
+
spec: swaggerJs.spec,
|
|
78
|
+
cb: cb
|
|
79
|
+
})
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Iterates over a spec, creating a hash of {[tag]: { [operationId], ... }, ...}
|
|
84
|
+
* with the value of calling `cb`.
|
|
85
|
+
*
|
|
86
|
+
* `spec` is a OAI v2.0 compliant specification object
|
|
87
|
+
* `cb` is called with ({ spec, operation, path, method })
|
|
88
|
+
* `defaultTag` will house all non-tagged operations
|
|
89
|
+
*
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
export function mapTagOperations(_ref2) {
|
|
93
|
+
var spec = _ref2.spec,
|
|
94
|
+
_ref2$cb = _ref2.cb,
|
|
95
|
+
cb = _ref2$cb === void 0 ? nullFn : _ref2$cb,
|
|
96
|
+
_ref2$defaultTag = _ref2.defaultTag,
|
|
97
|
+
defaultTag = _ref2$defaultTag === void 0 ? 'default' : _ref2$defaultTag,
|
|
98
|
+
v2OperationIdCompatibilityMode = _ref2.v2OperationIdCompatibilityMode;
|
|
99
|
+
var operationIdCounter = {};
|
|
100
|
+
var tagOperations = {}; // Will house all tags + operations
|
|
101
|
+
|
|
102
|
+
eachOperation(spec, function (_ref3) {
|
|
103
|
+
var pathName = _ref3.pathName,
|
|
104
|
+
method = _ref3.method,
|
|
105
|
+
operation = _ref3.operation;
|
|
106
|
+
var tags = operation.tags ? normalizeArray(operation.tags) : [defaultTag];
|
|
107
|
+
tags.forEach(function (tag) {
|
|
108
|
+
if (typeof tag !== 'string') {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
tagOperations[tag] = tagOperations[tag] || {};
|
|
113
|
+
var tagObj = tagOperations[tag];
|
|
114
|
+
var id = opId(operation, pathName, method, {
|
|
115
|
+
v2OperationIdCompatibilityMode: v2OperationIdCompatibilityMode
|
|
116
|
+
});
|
|
117
|
+
var cbResult = cb({
|
|
118
|
+
spec: spec,
|
|
119
|
+
pathName: pathName,
|
|
120
|
+
method: method,
|
|
121
|
+
operation: operation,
|
|
122
|
+
operationId: id
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
if (operationIdCounter[id]) {
|
|
126
|
+
operationIdCounter[id] += 1;
|
|
127
|
+
tagObj["".concat(id).concat(operationIdCounter[id])] = cbResult;
|
|
128
|
+
} else if (typeof tagObj[id] !== 'undefined') {
|
|
129
|
+
// Bump counter ( for this operationId )
|
|
130
|
+
var originalCounterValue = operationIdCounter[id] || 1;
|
|
131
|
+
operationIdCounter[id] = originalCounterValue + 1; // Append _x to the operationId
|
|
132
|
+
|
|
133
|
+
tagObj["".concat(id).concat(operationIdCounter[id])] = cbResult; // Rename the first operationId
|
|
134
|
+
|
|
135
|
+
var temp = tagObj[id];
|
|
136
|
+
delete tagObj[id];
|
|
137
|
+
tagObj["".concat(id).concat(originalCounterValue)] = temp;
|
|
138
|
+
} else {
|
|
139
|
+
// Assign callback result ( usually a bound function )
|
|
140
|
+
tagObj[id] = cbResult;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
return tagOperations;
|
|
145
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime-corejs2/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime-corejs2/helpers/createClass";
|
|
3
|
+
import _get from "@babel/runtime-corejs2/helpers/get";
|
|
4
|
+
import _getPrototypeOf from "@babel/runtime-corejs2/helpers/getPrototypeOf";
|
|
5
|
+
import _inherits from "@babel/runtime-corejs2/helpers/inherits";
|
|
6
|
+
import _createSuper from "@babel/runtime-corejs2/helpers/createSuper";
|
|
7
|
+
import isFunction from 'lodash/isFunction';
|
|
8
|
+
import IsomorphicFormData from 'isomorphic-form-data'; // patches FormData type by mutating it.
|
|
9
|
+
// patch :: FormData -> PatchedFormData
|
|
10
|
+
|
|
11
|
+
export var patch = function patch(FormData) {
|
|
12
|
+
var createEntry = function createEntry(field, value) {
|
|
13
|
+
return {
|
|
14
|
+
name: field,
|
|
15
|
+
value: value
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
/** We return original type if prototype already contains one of methods we're trying to patch.
|
|
19
|
+
* Reasoning: if one of the methods already exists, it would access data in other
|
|
20
|
+
* property than our `_entryList`. That could potentially create nasty
|
|
21
|
+
* hardly detectable bugs if `form-data` library implements only couple of
|
|
22
|
+
* methods that it misses, instead of implementing all of them.
|
|
23
|
+
* Current solution will fail the tests to let us know that form-data library
|
|
24
|
+
* already implements some of the methods that we try to monkey-patch, and our
|
|
25
|
+
* monkey-patch code should then compensate the library changes easily.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
if (isFunction(FormData.prototype.set) || isFunction(FormData.prototype.get) || isFunction(FormData.prototype.getAll) || isFunction(FormData.prototype.has)) {
|
|
30
|
+
return FormData;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var PatchedFormData = /*#__PURE__*/function (_FormData) {
|
|
34
|
+
_inherits(PatchedFormData, _FormData);
|
|
35
|
+
|
|
36
|
+
var _super = _createSuper(PatchedFormData);
|
|
37
|
+
|
|
38
|
+
function PatchedFormData(form) {
|
|
39
|
+
var _this;
|
|
40
|
+
|
|
41
|
+
_classCallCheck(this, PatchedFormData);
|
|
42
|
+
|
|
43
|
+
_this = _super.call(this, form);
|
|
44
|
+
_this.entryList = [];
|
|
45
|
+
return _this;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
_createClass(PatchedFormData, [{
|
|
49
|
+
key: "append",
|
|
50
|
+
value: function append(field, value, options) {
|
|
51
|
+
this.entryList.push(createEntry(field, value));
|
|
52
|
+
return _get(_getPrototypeOf(PatchedFormData.prototype), "append", this).call(this, field, value, options);
|
|
53
|
+
}
|
|
54
|
+
}, {
|
|
55
|
+
key: "set",
|
|
56
|
+
value: function set(field, value) {
|
|
57
|
+
var newEntry = createEntry(field, value);
|
|
58
|
+
this.entryList = this.entryList.filter(function (entry) {
|
|
59
|
+
return entry.name !== field;
|
|
60
|
+
});
|
|
61
|
+
this.entryList.push(newEntry);
|
|
62
|
+
}
|
|
63
|
+
}, {
|
|
64
|
+
key: "get",
|
|
65
|
+
value: function get(field) {
|
|
66
|
+
var foundEntry = this.entryList.find(function (entry) {
|
|
67
|
+
return entry.name === field;
|
|
68
|
+
});
|
|
69
|
+
return foundEntry === undefined ? null : foundEntry;
|
|
70
|
+
}
|
|
71
|
+
}, {
|
|
72
|
+
key: "getAll",
|
|
73
|
+
value: function getAll(field) {
|
|
74
|
+
return this.entryList.filter(function (entry) {
|
|
75
|
+
return entry.name === field;
|
|
76
|
+
}).map(function (entry) {
|
|
77
|
+
return entry.value;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}, {
|
|
81
|
+
key: "has",
|
|
82
|
+
value: function has(field) {
|
|
83
|
+
return this.entryList.some(function (entry) {
|
|
84
|
+
return entry.name === field;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}]);
|
|
88
|
+
|
|
89
|
+
return PatchedFormData;
|
|
90
|
+
}(FormData);
|
|
91
|
+
|
|
92
|
+
return PatchedFormData;
|
|
93
|
+
};
|
|
94
|
+
export default patch(IsomorphicFormData);
|
package/es/resolver.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime-corejs2/regenerator";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime-corejs2/helpers/asyncToGenerator";
|
|
3
|
+
import Http from './http';
|
|
4
|
+
import mapSpec, { plugins } from './specmap';
|
|
5
|
+
import { normalizeSwagger } from './helpers';
|
|
6
|
+
import { ACCEPT_HEADER_VALUE_FOR_DOCUMENTS } from './constants';
|
|
7
|
+
export function makeFetchJSON(http) {
|
|
8
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
9
|
+
var requestInterceptor = opts.requestInterceptor,
|
|
10
|
+
responseInterceptor = opts.responseInterceptor; // Set credentials with 'http.withCredentials' value
|
|
11
|
+
|
|
12
|
+
var credentials = http.withCredentials ? 'include' : 'same-origin';
|
|
13
|
+
return function (docPath) {
|
|
14
|
+
return http({
|
|
15
|
+
url: docPath,
|
|
16
|
+
loadSpec: true,
|
|
17
|
+
requestInterceptor: requestInterceptor,
|
|
18
|
+
responseInterceptor: responseInterceptor,
|
|
19
|
+
headers: {
|
|
20
|
+
Accept: ACCEPT_HEADER_VALUE_FOR_DOCUMENTS
|
|
21
|
+
},
|
|
22
|
+
credentials: credentials
|
|
23
|
+
}).then(function (res) {
|
|
24
|
+
return res.body;
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
} // Wipe out the http cache
|
|
28
|
+
|
|
29
|
+
export function clearCache() {
|
|
30
|
+
plugins.refs.clearCache();
|
|
31
|
+
}
|
|
32
|
+
export default function resolve(obj) {
|
|
33
|
+
var fetch = obj.fetch,
|
|
34
|
+
spec = obj.spec,
|
|
35
|
+
url = obj.url,
|
|
36
|
+
mode = obj.mode,
|
|
37
|
+
_obj$allowMetaPatches = obj.allowMetaPatches,
|
|
38
|
+
allowMetaPatches = _obj$allowMetaPatches === void 0 ? true : _obj$allowMetaPatches,
|
|
39
|
+
pathDiscriminator = obj.pathDiscriminator,
|
|
40
|
+
modelPropertyMacro = obj.modelPropertyMacro,
|
|
41
|
+
parameterMacro = obj.parameterMacro,
|
|
42
|
+
requestInterceptor = obj.requestInterceptor,
|
|
43
|
+
responseInterceptor = obj.responseInterceptor,
|
|
44
|
+
skipNormalization = obj.skipNormalization,
|
|
45
|
+
useCircularStructures = obj.useCircularStructures;
|
|
46
|
+
var http = obj.http,
|
|
47
|
+
baseDoc = obj.baseDoc; // @TODO Swagger-UI uses baseDoc instead of url, this is to allow both
|
|
48
|
+
// need to fix and pick one.
|
|
49
|
+
|
|
50
|
+
baseDoc = baseDoc || url; // Provide a default fetch implementation
|
|
51
|
+
// TODO fetch should be removed, and http used instead
|
|
52
|
+
|
|
53
|
+
http = fetch || http || Http;
|
|
54
|
+
|
|
55
|
+
if (!spec) {
|
|
56
|
+
return makeFetchJSON(http, {
|
|
57
|
+
requestInterceptor: requestInterceptor,
|
|
58
|
+
responseInterceptor: responseInterceptor
|
|
59
|
+
})(baseDoc).then(doResolve);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return doResolve(spec);
|
|
63
|
+
|
|
64
|
+
function doResolve(_spec) {
|
|
65
|
+
if (baseDoc) {
|
|
66
|
+
plugins.refs.docCache[baseDoc] = _spec;
|
|
67
|
+
} // Build a json-fetcher ( ie: give it a URL and get json out )
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
plugins.refs.fetchJSON = makeFetchJSON(http, {
|
|
71
|
+
requestInterceptor: requestInterceptor,
|
|
72
|
+
responseInterceptor: responseInterceptor
|
|
73
|
+
});
|
|
74
|
+
var plugs = [plugins.refs];
|
|
75
|
+
|
|
76
|
+
if (typeof parameterMacro === 'function') {
|
|
77
|
+
plugs.push(plugins.parameters);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (typeof modelPropertyMacro === 'function') {
|
|
81
|
+
plugs.push(plugins.properties);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (mode !== 'strict') {
|
|
85
|
+
plugs.push(plugins.allOf);
|
|
86
|
+
} // mapSpec is where the hard work happens, see https://github.com/swagger-api/specmap for more details
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
return mapSpec({
|
|
90
|
+
spec: _spec,
|
|
91
|
+
context: {
|
|
92
|
+
baseDoc: baseDoc
|
|
93
|
+
},
|
|
94
|
+
plugins: plugs,
|
|
95
|
+
allowMetaPatches: allowMetaPatches,
|
|
96
|
+
// allows adding .meta patches, which include adding `$$ref`s to the spec
|
|
97
|
+
pathDiscriminator: pathDiscriminator,
|
|
98
|
+
// for lazy resolution
|
|
99
|
+
parameterMacro: parameterMacro,
|
|
100
|
+
modelPropertyMacro: modelPropertyMacro,
|
|
101
|
+
useCircularStructures: useCircularStructures
|
|
102
|
+
}).then(skipNormalization ? /*#__PURE__*/function () {
|
|
103
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(a) {
|
|
104
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
105
|
+
while (1) {
|
|
106
|
+
switch (_context.prev = _context.next) {
|
|
107
|
+
case 0:
|
|
108
|
+
return _context.abrupt("return", a);
|
|
109
|
+
|
|
110
|
+
case 1:
|
|
111
|
+
case "end":
|
|
112
|
+
return _context.stop();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}, _callee);
|
|
116
|
+
}));
|
|
117
|
+
|
|
118
|
+
return function (_x) {
|
|
119
|
+
return _ref.apply(this, arguments);
|
|
120
|
+
};
|
|
121
|
+
}() : normalizeSwagger);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime-corejs2/helpers/slicedToArray";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime-corejs2/helpers/toConsumableArray";
|
|
3
|
+
import traverse from 'traverse';
|
|
4
|
+
import URL from 'url'; // This will match if the direct parent's key exactly matches an item.
|
|
5
|
+
|
|
6
|
+
var freelyNamedKeyParents = ['properties']; // This will match if the grandparent's key exactly matches an item.
|
|
7
|
+
// NOTE that this is for finding non-free paths!
|
|
8
|
+
|
|
9
|
+
var nonFreelyNamedKeyGrandparents = ['properties']; // This will match if the joined parent path exactly matches an item.
|
|
10
|
+
//
|
|
11
|
+
// This is mostly useful for filtering out root-level reusable item names,
|
|
12
|
+
// for example `["definitions", "$ref"]`
|
|
13
|
+
|
|
14
|
+
var freelyNamedPaths = [// Swagger 2.0
|
|
15
|
+
'definitions', 'parameters', 'responses', 'securityDefinitions', // OpenAPI 3.0
|
|
16
|
+
'components/schemas', 'components/responses', 'components/parameters', 'components/securitySchemes']; // This will match if any of these items are substrings of the joined
|
|
17
|
+
// parent path.
|
|
18
|
+
//
|
|
19
|
+
// Warning! These are powerful. Beware of edge cases.
|
|
20
|
+
|
|
21
|
+
var freelyNamedAncestors = ['schema/example', 'items/example'];
|
|
22
|
+
export function isFreelyNamed(parentPath) {
|
|
23
|
+
var parentKey = parentPath[parentPath.length - 1];
|
|
24
|
+
var grandparentKey = parentPath[parentPath.length - 2];
|
|
25
|
+
var parentStr = parentPath.join('/');
|
|
26
|
+
return (// eslint-disable-next-line max-len
|
|
27
|
+
freelyNamedKeyParents.indexOf(parentKey) > -1 && nonFreelyNamedKeyGrandparents.indexOf(grandparentKey) === -1 || freelyNamedPaths.indexOf(parentStr) > -1 || freelyNamedAncestors.some(function (el) {
|
|
28
|
+
return parentStr.indexOf(el) > -1;
|
|
29
|
+
})
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
export function generateAbsoluteRefPatches(obj, basePath) {
|
|
33
|
+
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
34
|
+
specmap = _ref.specmap,
|
|
35
|
+
_ref$getBaseUrlForNod = _ref.getBaseUrlForNodePath,
|
|
36
|
+
getBaseUrlForNodePath = _ref$getBaseUrlForNod === void 0 ? function (path) {
|
|
37
|
+
return specmap.getContext([].concat(_toConsumableArray(basePath), _toConsumableArray(path))).baseDoc;
|
|
38
|
+
} : _ref$getBaseUrlForNod,
|
|
39
|
+
_ref$targetKeys = _ref.targetKeys,
|
|
40
|
+
targetKeys = _ref$targetKeys === void 0 ? ['$ref', '$$ref'] : _ref$targetKeys;
|
|
41
|
+
|
|
42
|
+
var patches = [];
|
|
43
|
+
traverse(obj).forEach(function callback() {
|
|
44
|
+
if (targetKeys.indexOf(this.key) > -1) {
|
|
45
|
+
var nodePath = this.path; // this node's path, relative to `obj`
|
|
46
|
+
|
|
47
|
+
var fullPath = basePath.concat(this.path);
|
|
48
|
+
var absolutifiedRefValue = absolutifyPointer(this.node, getBaseUrlForNodePath(nodePath));
|
|
49
|
+
patches.push(specmap.replace(fullPath, absolutifiedRefValue));
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return patches;
|
|
53
|
+
}
|
|
54
|
+
export function absolutifyPointer(pointer, baseUrl) {
|
|
55
|
+
var _pointer$split = pointer.split('#'),
|
|
56
|
+
_pointer$split2 = _slicedToArray(_pointer$split, 2),
|
|
57
|
+
urlPart = _pointer$split2[0],
|
|
58
|
+
fragmentPart = _pointer$split2[1];
|
|
59
|
+
|
|
60
|
+
var newRefUrlPart = URL.resolve(urlPart || '', baseUrl || '');
|
|
61
|
+
return fragmentPart ? "".concat(newRefUrlPart, "#").concat(fragmentPart) : newRefUrlPart;
|
|
62
|
+
}
|