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.
Files changed (57) hide show
  1. package/README.md +10 -2
  2. package/dist/swagger-client.browser.js +24191 -0
  3. package/dist/swagger-client.browser.min.js +3 -0
  4. package/dist/swagger-client.browser.min.js.map +1 -0
  5. package/es/commonjs.js +9 -0
  6. package/es/constants.js +2 -0
  7. package/es/execute/index.js +391 -0
  8. package/es/execute/oas3/build-request.js +149 -0
  9. package/es/execute/oas3/content-serializer.js +18 -0
  10. package/es/execute/oas3/parameter-builders.js +119 -0
  11. package/es/execute/oas3/style-serializer.js +232 -0
  12. package/es/execute/swagger2/build-request.js +119 -0
  13. package/es/execute/swagger2/parameter-builders.js +78 -0
  14. package/es/helpers.js +272 -0
  15. package/es/http.js +621 -0
  16. package/es/index.js +116 -0
  17. package/es/interfaces.js +145 -0
  18. package/es/internal/form-data-monkey-patch.js +94 -0
  19. package/es/resolver.js +123 -0
  20. package/es/specmap/helpers.js +62 -0
  21. package/es/specmap/index.js +613 -0
  22. package/es/specmap/lib/all-of.js +81 -0
  23. package/es/specmap/lib/context-tree.js +111 -0
  24. package/es/specmap/lib/create-error.js +24 -0
  25. package/es/specmap/lib/index.js +391 -0
  26. package/es/specmap/lib/parameters.js +31 -0
  27. package/es/specmap/lib/properties.js +23 -0
  28. package/es/specmap/lib/refs.js +516 -0
  29. package/es/subtree-resolver/index.js +92 -0
  30. package/lib/commonjs.js +10 -0
  31. package/lib/constants.js +7 -0
  32. package/lib/execute/index.js +421 -0
  33. package/lib/execute/oas3/build-request.js +161 -0
  34. package/lib/execute/oas3/content-serializer.js +21 -0
  35. package/lib/execute/oas3/parameter-builders.js +138 -0
  36. package/lib/execute/oas3/style-serializer.js +208 -0
  37. package/lib/execute/swagger2/build-request.js +120 -0
  38. package/lib/execute/swagger2/parameter-builders.js +88 -0
  39. package/lib/helpers.js +261 -0
  40. package/lib/http.js +470 -0
  41. package/lib/index.js +142 -0
  42. package/lib/interfaces.js +159 -0
  43. package/lib/internal/form-data-monkey-patch.js +83 -0
  44. package/lib/resolver.js +125 -0
  45. package/lib/specmap/helpers.js +65 -0
  46. package/lib/specmap/index.js +446 -0
  47. package/lib/specmap/lib/all-of.js +89 -0
  48. package/lib/specmap/lib/context-tree.js +111 -0
  49. package/lib/specmap/lib/create-error.js +25 -0
  50. package/lib/specmap/lib/index.js +402 -0
  51. package/lib/specmap/lib/parameters.js +42 -0
  52. package/lib/specmap/lib/properties.js +38 -0
  53. package/lib/specmap/lib/refs.js +509 -0
  54. package/lib/subtree-resolver/index.js +55 -0
  55. package/package.json +80 -106
  56. package/browser/index.js +0 -54
  57. package/dist/index.js +0 -4372
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.makeExecute = makeExecute;
5
+ exports.makeApisTagOperationsOperationExecute = makeApisTagOperationsOperationExecute;
6
+ exports.makeApisTagOperation = makeApisTagOperation;
7
+ exports.mapTagOperations = mapTagOperations;
8
+ exports.self = void 0;
9
+
10
+ var _pick = _interopRequireDefault(require("lodash/pick"));
11
+
12
+ var _helpers = require("./helpers");
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
17
+
18
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
19
+
20
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
21
+
22
+ const nullFn = () => null;
23
+
24
+ const normalizeArray = arg => {
25
+ return Array.isArray(arg) ? arg : [arg];
26
+ }; // To allow stubbing of functions
27
+
28
+
29
+ const self = {
30
+ mapTagOperations,
31
+ makeExecute
32
+ }; // Make an execute, bound to arguments defined in mapTagOperation's callback (cb)
33
+
34
+ exports.self = self;
35
+
36
+ function makeExecute(swaggerJs = {}) {
37
+ return ({
38
+ pathName,
39
+ method,
40
+ operationId
41
+ }) => (parameters, opts = {}) => {
42
+ return swaggerJs.execute(_objectSpread(_objectSpread({
43
+ spec: swaggerJs.spec
44
+ }, (0, _pick.default)(swaggerJs, 'requestInterceptor', 'responseInterceptor', 'userFetch')), {}, {
45
+ pathName,
46
+ method,
47
+ parameters,
48
+ operationId
49
+ }, opts));
50
+ };
51
+ } // Creates an interface with tags+operations = execute
52
+ // The shape
53
+ // { apis: { [tag]: { operations: [operation]: { execute }}}}
54
+ // NOTE: this is mostly for compatibility
55
+
56
+
57
+ function makeApisTagOperationsOperationExecute(swaggerJs = {}) {
58
+ // { apis: tag: operations: execute }
59
+ const cb = self.makeExecute(swaggerJs);
60
+ const tagOperations = self.mapTagOperations({
61
+ v2OperationIdCompatibilityMode: swaggerJs.v2OperationIdCompatibilityMode,
62
+ spec: swaggerJs.spec,
63
+ cb
64
+ });
65
+ const apis = {}; // eslint-disable-next-line no-restricted-syntax, guard-for-in
66
+
67
+ for (const tag in tagOperations) {
68
+ apis[tag] = {
69
+ operations: {}
70
+ }; // eslint-disable-next-line no-restricted-syntax, guard-for-in
71
+
72
+ for (const op in tagOperations[tag]) {
73
+ apis[tag].operations[op] = {
74
+ execute: tagOperations[tag][op]
75
+ };
76
+ }
77
+ }
78
+
79
+ return {
80
+ apis
81
+ };
82
+ } // .apis[tag][operationId]:ExecuteFunction interface
83
+
84
+
85
+ function makeApisTagOperation(swaggerJs = {}) {
86
+ const cb = self.makeExecute(swaggerJs);
87
+ return {
88
+ apis: self.mapTagOperations({
89
+ v2OperationIdCompatibilityMode: swaggerJs.v2OperationIdCompatibilityMode,
90
+ spec: swaggerJs.spec,
91
+ cb
92
+ })
93
+ };
94
+ }
95
+ /**
96
+ * Iterates over a spec, creating a hash of {[tag]: { [operationId], ... }, ...}
97
+ * with the value of calling `cb`.
98
+ *
99
+ * `spec` is a OAI v2.0 compliant specification object
100
+ * `cb` is called with ({ spec, operation, path, method })
101
+ * `defaultTag` will house all non-tagged operations
102
+ *
103
+ */
104
+
105
+
106
+ function mapTagOperations({
107
+ spec,
108
+ cb = nullFn,
109
+ defaultTag = 'default',
110
+ v2OperationIdCompatibilityMode
111
+ }) {
112
+ const operationIdCounter = {};
113
+ const tagOperations = {}; // Will house all tags + operations
114
+
115
+ (0, _helpers.eachOperation)(spec, ({
116
+ pathName,
117
+ method,
118
+ operation
119
+ }) => {
120
+ const tags = operation.tags ? normalizeArray(operation.tags) : [defaultTag];
121
+ tags.forEach(tag => {
122
+ if (typeof tag !== 'string') {
123
+ return;
124
+ }
125
+
126
+ tagOperations[tag] = tagOperations[tag] || {};
127
+ const tagObj = tagOperations[tag];
128
+ const id = (0, _helpers.opId)(operation, pathName, method, {
129
+ v2OperationIdCompatibilityMode
130
+ });
131
+ const cbResult = cb({
132
+ spec,
133
+ pathName,
134
+ method,
135
+ operation,
136
+ operationId: id
137
+ });
138
+
139
+ if (operationIdCounter[id]) {
140
+ operationIdCounter[id] += 1;
141
+ tagObj[`${id}${operationIdCounter[id]}`] = cbResult;
142
+ } else if (typeof tagObj[id] !== 'undefined') {
143
+ // Bump counter ( for this operationId )
144
+ const originalCounterValue = operationIdCounter[id] || 1;
145
+ operationIdCounter[id] = originalCounterValue + 1; // Append _x to the operationId
146
+
147
+ tagObj[`${id}${operationIdCounter[id]}`] = cbResult; // Rename the first operationId
148
+
149
+ const temp = tagObj[id];
150
+ delete tagObj[id];
151
+ tagObj[`${id}${originalCounterValue}`] = temp;
152
+ } else {
153
+ // Assign callback result ( usually a bound function )
154
+ tagObj[id] = cbResult;
155
+ }
156
+ });
157
+ });
158
+ return tagOperations;
159
+ }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = exports.patch = void 0;
5
+
6
+ var _isFunction = _interopRequireDefault(require("lodash/isFunction"));
7
+
8
+ var _isomorphicFormData = _interopRequireDefault(require("isomorphic-form-data"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ // patches FormData type by mutating it.
13
+ // patch :: FormData -> PatchedFormData
14
+ const patch = FormData => {
15
+ const createEntry = (field, value) => ({
16
+ name: field,
17
+ value
18
+ });
19
+ /** We return original type if prototype already contains one of methods we're trying to patch.
20
+ * Reasoning: if one of the methods already exists, it would access data in other
21
+ * property than our `_entryList`. That could potentially create nasty
22
+ * hardly detectable bugs if `form-data` library implements only couple of
23
+ * methods that it misses, instead of implementing all of them.
24
+ * Current solution will fail the tests to let us know that form-data library
25
+ * already implements some of the methods that we try to monkey-patch, and our
26
+ * monkey-patch code should then compensate the library changes easily.
27
+ */
28
+
29
+
30
+ if ((0, _isFunction.default)(FormData.prototype.set) || (0, _isFunction.default)(FormData.prototype.get) || (0, _isFunction.default)(FormData.prototype.getAll) || (0, _isFunction.default)(FormData.prototype.has)) {
31
+ return FormData;
32
+ }
33
+
34
+ class PatchedFormData extends FormData {
35
+ constructor(form) {
36
+ super(form);
37
+ this.entryList = [];
38
+ }
39
+
40
+ append(field, value, options) {
41
+ this.entryList.push(createEntry(field, value));
42
+ return super.append(field, value, options);
43
+ }
44
+
45
+ set(field, value) {
46
+ const newEntry = createEntry(field, value);
47
+ this.entryList = this.entryList.filter(entry => {
48
+ return entry.name !== field;
49
+ });
50
+ this.entryList.push(newEntry);
51
+ }
52
+
53
+ get(field) {
54
+ const foundEntry = this.entryList.find(entry => {
55
+ return entry.name === field;
56
+ });
57
+ return foundEntry === undefined ? null : foundEntry;
58
+ }
59
+
60
+ getAll(field) {
61
+ return this.entryList.filter(entry => {
62
+ return entry.name === field;
63
+ }).map(entry => {
64
+ return entry.value;
65
+ });
66
+ }
67
+
68
+ has(field) {
69
+ return this.entryList.some(entry => {
70
+ return entry.name === field;
71
+ });
72
+ }
73
+
74
+ }
75
+
76
+ return PatchedFormData;
77
+ };
78
+
79
+ exports.patch = patch;
80
+
81
+ var _default = patch(_isomorphicFormData.default);
82
+
83
+ exports.default = _default;
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.makeFetchJSON = makeFetchJSON;
5
+ exports.clearCache = clearCache;
6
+ exports.default = resolve;
7
+
8
+ var _http = _interopRequireDefault(require("./http"));
9
+
10
+ var _specmap = _interopRequireWildcard(require("./specmap"));
11
+
12
+ var _helpers = require("./helpers");
13
+
14
+ var _constants = require("./constants");
15
+
16
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
17
+
18
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
22
+ function makeFetchJSON(http, opts = {}) {
23
+ const {
24
+ requestInterceptor,
25
+ responseInterceptor
26
+ } = opts; // Set credentials with 'http.withCredentials' value
27
+
28
+ const credentials = http.withCredentials ? 'include' : 'same-origin';
29
+ return docPath => {
30
+ return http({
31
+ url: docPath,
32
+ loadSpec: true,
33
+ requestInterceptor,
34
+ responseInterceptor,
35
+ headers: {
36
+ Accept: _constants.ACCEPT_HEADER_VALUE_FOR_DOCUMENTS
37
+ },
38
+ credentials
39
+ }).then(res => {
40
+ return res.body;
41
+ });
42
+ };
43
+ } // Wipe out the http cache
44
+
45
+
46
+ function clearCache() {
47
+ _specmap.plugins.refs.clearCache();
48
+ }
49
+
50
+ function resolve(obj) {
51
+ const {
52
+ fetch,
53
+ spec,
54
+ url,
55
+ mode,
56
+ allowMetaPatches = true,
57
+ pathDiscriminator,
58
+ modelPropertyMacro,
59
+ parameterMacro,
60
+ requestInterceptor,
61
+ responseInterceptor,
62
+ skipNormalization,
63
+ useCircularStructures
64
+ } = obj;
65
+ let {
66
+ http,
67
+ baseDoc
68
+ } = obj; // @TODO Swagger-UI uses baseDoc instead of url, this is to allow both
69
+ // need to fix and pick one.
70
+
71
+ baseDoc = baseDoc || url; // Provide a default fetch implementation
72
+ // TODO fetch should be removed, and http used instead
73
+
74
+ http = fetch || http || _http.default;
75
+
76
+ if (!spec) {
77
+ return makeFetchJSON(http, {
78
+ requestInterceptor,
79
+ responseInterceptor
80
+ })(baseDoc).then(doResolve);
81
+ }
82
+
83
+ return doResolve(spec);
84
+
85
+ function doResolve(_spec) {
86
+ if (baseDoc) {
87
+ _specmap.plugins.refs.docCache[baseDoc] = _spec;
88
+ } // Build a json-fetcher ( ie: give it a URL and get json out )
89
+
90
+
91
+ _specmap.plugins.refs.fetchJSON = makeFetchJSON(http, {
92
+ requestInterceptor,
93
+ responseInterceptor
94
+ });
95
+ const plugs = [_specmap.plugins.refs];
96
+
97
+ if (typeof parameterMacro === 'function') {
98
+ plugs.push(_specmap.plugins.parameters);
99
+ }
100
+
101
+ if (typeof modelPropertyMacro === 'function') {
102
+ plugs.push(_specmap.plugins.properties);
103
+ }
104
+
105
+ if (mode !== 'strict') {
106
+ plugs.push(_specmap.plugins.allOf);
107
+ } // mapSpec is where the hard work happens, see https://github.com/swagger-api/specmap for more details
108
+
109
+
110
+ return (0, _specmap.default)({
111
+ spec: _spec,
112
+ context: {
113
+ baseDoc
114
+ },
115
+ plugins: plugs,
116
+ allowMetaPatches,
117
+ // allows adding .meta patches, which include adding `$$ref`s to the spec
118
+ pathDiscriminator,
119
+ // for lazy resolution
120
+ parameterMacro,
121
+ modelPropertyMacro,
122
+ useCircularStructures
123
+ }).then(skipNormalization ? async a => a : _helpers.normalizeSwagger);
124
+ }
125
+ }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.isFreelyNamed = isFreelyNamed;
5
+ exports.generateAbsoluteRefPatches = generateAbsoluteRefPatches;
6
+ exports.absolutifyPointer = absolutifyPointer;
7
+
8
+ var _traverse = _interopRequireDefault(require("traverse"));
9
+
10
+ var _url = _interopRequireDefault(require("url"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ // This will match if the direct parent's key exactly matches an item.
15
+ const freelyNamedKeyParents = ['properties']; // This will match if the grandparent's key exactly matches an item.
16
+ // NOTE that this is for finding non-free paths!
17
+
18
+ const nonFreelyNamedKeyGrandparents = ['properties']; // This will match if the joined parent path exactly matches an item.
19
+ //
20
+ // This is mostly useful for filtering out root-level reusable item names,
21
+ // for example `["definitions", "$ref"]`
22
+
23
+ const freelyNamedPaths = [// Swagger 2.0
24
+ 'definitions', 'parameters', 'responses', 'securityDefinitions', // OpenAPI 3.0
25
+ 'components/schemas', 'components/responses', 'components/parameters', 'components/securitySchemes']; // This will match if any of these items are substrings of the joined
26
+ // parent path.
27
+ //
28
+ // Warning! These are powerful. Beware of edge cases.
29
+
30
+ const freelyNamedAncestors = ['schema/example', 'items/example'];
31
+
32
+ function isFreelyNamed(parentPath) {
33
+ const parentKey = parentPath[parentPath.length - 1];
34
+ const grandparentKey = parentPath[parentPath.length - 2];
35
+ const parentStr = parentPath.join('/');
36
+ return (// eslint-disable-next-line max-len
37
+ freelyNamedKeyParents.indexOf(parentKey) > -1 && nonFreelyNamedKeyGrandparents.indexOf(grandparentKey) === -1 || freelyNamedPaths.indexOf(parentStr) > -1 || freelyNamedAncestors.some(el => parentStr.indexOf(el) > -1)
38
+ );
39
+ }
40
+
41
+ function generateAbsoluteRefPatches(obj, basePath, {
42
+ specmap,
43
+ getBaseUrlForNodePath = path => specmap.getContext([...basePath, ...path]).baseDoc,
44
+ targetKeys = ['$ref', '$$ref']
45
+ } = {}) {
46
+ const patches = [];
47
+ (0, _traverse.default)(obj).forEach(function callback() {
48
+ if (targetKeys.indexOf(this.key) > -1) {
49
+ const nodePath = this.path; // this node's path, relative to `obj`
50
+
51
+ const fullPath = basePath.concat(this.path);
52
+ const absolutifiedRefValue = absolutifyPointer(this.node, getBaseUrlForNodePath(nodePath));
53
+ patches.push(specmap.replace(fullPath, absolutifiedRefValue));
54
+ }
55
+ });
56
+ return patches;
57
+ }
58
+
59
+ function absolutifyPointer(pointer, baseUrl) {
60
+ const [urlPart, fragmentPart] = pointer.split('#');
61
+
62
+ const newRefUrlPart = _url.default.resolve(urlPart || '', baseUrl || '');
63
+
64
+ return fragmentPart ? `${newRefUrlPart}#${fragmentPart}` : newRefUrlPart;
65
+ }