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,138 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.path = path;
5
+ exports.query = query;
6
+ exports.header = header;
7
+ exports.cookie = cookie;
8
+
9
+ var _pick = _interopRequireDefault(require("lodash/pick"));
10
+
11
+ var _styleSerializer = _interopRequireWildcard(require("./style-serializer"));
12
+
13
+ var _contentSerializer = _interopRequireDefault(require("./content-serializer"));
14
+
15
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
16
+
17
+ 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; }
18
+
19
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
+
21
+ function path({
22
+ req,
23
+ value,
24
+ parameter
25
+ }) {
26
+ const {
27
+ name,
28
+ style,
29
+ explode,
30
+ content
31
+ } = parameter;
32
+
33
+ if (content) {
34
+ const effectiveMediaType = Object.keys(content)[0];
35
+ req.url = req.url.split(`{${name}}`).join((0, _styleSerializer.encodeDisallowedCharacters)((0, _contentSerializer.default)(value, effectiveMediaType), {
36
+ escape: true
37
+ }));
38
+ return;
39
+ }
40
+
41
+ const styledValue = (0, _styleSerializer.default)({
42
+ key: parameter.name,
43
+ value,
44
+ style: style || 'simple',
45
+ explode: explode || false,
46
+ escape: true
47
+ });
48
+ req.url = req.url.split(`{${name}}`).join(styledValue);
49
+ }
50
+
51
+ function query({
52
+ req,
53
+ value,
54
+ parameter
55
+ }) {
56
+ req.query = req.query || {};
57
+
58
+ if (parameter.content) {
59
+ const effectiveMediaType = Object.keys(parameter.content)[0];
60
+ req.query[parameter.name] = (0, _contentSerializer.default)(value, effectiveMediaType);
61
+ return;
62
+ }
63
+
64
+ if (value === false) {
65
+ value = 'false';
66
+ }
67
+
68
+ if (value === 0) {
69
+ value = '0';
70
+ }
71
+
72
+ if (value) {
73
+ req.query[parameter.name] = {
74
+ value,
75
+ serializationOption: (0, _pick.default)(parameter, ['style', 'explode', 'allowReserved'])
76
+ };
77
+ } else if (parameter.allowEmptyValue && value !== undefined) {
78
+ const paramName = parameter.name;
79
+ req.query[paramName] = req.query[paramName] || {};
80
+ req.query[paramName].allowEmptyValue = true;
81
+ }
82
+ }
83
+
84
+ const PARAMETER_HEADER_BLACKLIST = ['accept', 'authorization', 'content-type'];
85
+
86
+ function header({
87
+ req,
88
+ parameter,
89
+ value
90
+ }) {
91
+ req.headers = req.headers || {};
92
+
93
+ if (PARAMETER_HEADER_BLACKLIST.indexOf(parameter.name.toLowerCase()) > -1) {
94
+ return;
95
+ }
96
+
97
+ if (parameter.content) {
98
+ const effectiveMediaType = Object.keys(parameter.content)[0];
99
+ req.headers[parameter.name] = (0, _contentSerializer.default)(value, effectiveMediaType);
100
+ return;
101
+ }
102
+
103
+ if (typeof value !== 'undefined') {
104
+ req.headers[parameter.name] = (0, _styleSerializer.default)({
105
+ key: parameter.name,
106
+ value,
107
+ style: parameter.style || 'simple',
108
+ explode: typeof parameter.explode === 'undefined' ? false : parameter.explode,
109
+ escape: false
110
+ });
111
+ }
112
+ }
113
+
114
+ function cookie({
115
+ req,
116
+ parameter,
117
+ value
118
+ }) {
119
+ req.headers = req.headers || {};
120
+ const type = typeof value;
121
+
122
+ if (parameter.content) {
123
+ const effectiveMediaType = Object.keys(parameter.content)[0];
124
+ req.headers.Cookie = `${parameter.name}=${(0, _contentSerializer.default)(value, effectiveMediaType)}`;
125
+ return;
126
+ }
127
+
128
+ if (type !== 'undefined') {
129
+ const prefix = type === 'object' && !Array.isArray(value) && parameter.explode ? '' : `${parameter.name}=`;
130
+ req.headers.Cookie = prefix + (0, _styleSerializer.default)({
131
+ key: parameter.name,
132
+ value,
133
+ escape: false,
134
+ style: parameter.style || 'form',
135
+ explode: typeof parameter.explode === 'undefined' ? false : parameter.explode
136
+ });
137
+ }
138
+ }
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.encodeDisallowedCharacters = encodeDisallowedCharacters;
5
+ exports.default = stylize;
6
+
7
+ const {
8
+ Buffer
9
+ } = require('buffer');
10
+
11
+ const isRfc3986Reserved = char => ":/?#[]@!$&'()*+,;=".indexOf(char) > -1;
12
+
13
+ const isRrc3986Unreserved = char => {
14
+ return /^[a-z0-9\-._~]+$/i.test(char);
15
+ };
16
+
17
+ function encodeDisallowedCharacters(str, {
18
+ escape
19
+ } = {}, parse) {
20
+ if (typeof str === 'number') {
21
+ str = str.toString();
22
+ }
23
+
24
+ if (typeof str !== 'string' || !str.length) {
25
+ return str;
26
+ }
27
+
28
+ if (!escape) {
29
+ return str;
30
+ }
31
+
32
+ if (parse) {
33
+ return JSON.parse(str);
34
+ } // In ES6 you can do this quite easily by using the new ... spread operator.
35
+ // This causes the string iterator (another new ES6 feature) to be used internally,
36
+ // and because that iterator is designed to deal with
37
+ // code points rather than UCS-2/UTF-16 code units.
38
+
39
+
40
+ return [...str].map(char => {
41
+ if (isRrc3986Unreserved(char)) {
42
+ return char;
43
+ }
44
+
45
+ if (isRfc3986Reserved(char) && escape === 'unsafe') {
46
+ return char;
47
+ }
48
+
49
+ const encoded = (Buffer.from(char).toJSON().data || []).map(byte => `0${byte.toString(16).toUpperCase()}`.slice(-2)).map(encodedByte => `%${encodedByte}`).join('');
50
+ return encoded;
51
+ }).join('');
52
+ }
53
+
54
+ function stylize(config) {
55
+ const {
56
+ value
57
+ } = config;
58
+
59
+ if (Array.isArray(value)) {
60
+ return encodeArray(config);
61
+ }
62
+
63
+ if (typeof value === 'object') {
64
+ return encodeObject(config);
65
+ }
66
+
67
+ return encodePrimitive(config);
68
+ }
69
+
70
+ function encodeArray({
71
+ key,
72
+ value,
73
+ style,
74
+ explode,
75
+ escape
76
+ }) {
77
+ const valueEncoder = str => encodeDisallowedCharacters(str, {
78
+ escape
79
+ });
80
+
81
+ if (style === 'simple') {
82
+ return value.map(val => valueEncoder(val)).join(',');
83
+ }
84
+
85
+ if (style === 'label') {
86
+ return `.${value.map(val => valueEncoder(val)).join('.')}`;
87
+ }
88
+
89
+ if (style === 'matrix') {
90
+ return value.map(val => valueEncoder(val)).reduce((prev, curr) => {
91
+ if (!prev || explode) {
92
+ return `${prev || ''};${key}=${curr}`;
93
+ }
94
+
95
+ return `${prev},${curr}`;
96
+ }, '');
97
+ }
98
+
99
+ if (style === 'form') {
100
+ const after = explode ? `&${key}=` : ',';
101
+ return value.map(val => valueEncoder(val)).join(after);
102
+ }
103
+
104
+ if (style === 'spaceDelimited') {
105
+ const after = explode ? `${key}=` : '';
106
+ return value.map(val => valueEncoder(val)).join(` ${after}`);
107
+ }
108
+
109
+ if (style === 'pipeDelimited') {
110
+ const after = explode ? `${key}=` : '';
111
+ return value.map(val => valueEncoder(val)).join(`|${after}`);
112
+ }
113
+
114
+ return undefined;
115
+ }
116
+
117
+ function encodeObject({
118
+ key,
119
+ value,
120
+ style,
121
+ explode,
122
+ escape
123
+ }) {
124
+ const valueEncoder = str => encodeDisallowedCharacters(str, {
125
+ escape
126
+ });
127
+
128
+ const valueKeys = Object.keys(value);
129
+
130
+ if (style === 'simple') {
131
+ return valueKeys.reduce((prev, curr) => {
132
+ const val = valueEncoder(value[curr]);
133
+ const middleChar = explode ? '=' : ',';
134
+ const prefix = prev ? `${prev},` : '';
135
+ return `${prefix}${curr}${middleChar}${val}`;
136
+ }, '');
137
+ }
138
+
139
+ if (style === 'label') {
140
+ return valueKeys.reduce((prev, curr) => {
141
+ const val = valueEncoder(value[curr]);
142
+ const middleChar = explode ? '=' : '.';
143
+ const prefix = prev ? `${prev}.` : '.';
144
+ return `${prefix}${curr}${middleChar}${val}`;
145
+ }, '');
146
+ }
147
+
148
+ if (style === 'matrix' && explode) {
149
+ return valueKeys.reduce((prev, curr) => {
150
+ const val = valueEncoder(value[curr]);
151
+ const prefix = prev ? `${prev};` : ';';
152
+ return `${prefix}${curr}=${val}`;
153
+ }, '');
154
+ }
155
+
156
+ if (style === 'matrix') {
157
+ // no explode
158
+ return valueKeys.reduce((prev, curr) => {
159
+ const val = valueEncoder(value[curr]);
160
+ const prefix = prev ? `${prev},` : `;${key}=`;
161
+ return `${prefix}${curr},${val}`;
162
+ }, '');
163
+ }
164
+
165
+ if (style === 'form') {
166
+ return valueKeys.reduce((prev, curr) => {
167
+ const val = valueEncoder(value[curr]);
168
+ const prefix = prev ? `${prev}${explode ? '&' : ','}` : '';
169
+ const separator = explode ? '=' : ',';
170
+ return `${prefix}${curr}${separator}${val}`;
171
+ }, '');
172
+ }
173
+
174
+ return undefined;
175
+ }
176
+
177
+ function encodePrimitive({
178
+ key,
179
+ value,
180
+ style,
181
+ escape
182
+ }) {
183
+ const valueEncoder = str => encodeDisallowedCharacters(str, {
184
+ escape
185
+ });
186
+
187
+ if (style === 'simple') {
188
+ return valueEncoder(value);
189
+ }
190
+
191
+ if (style === 'label') {
192
+ return `.${valueEncoder(value)}`;
193
+ }
194
+
195
+ if (style === 'matrix') {
196
+ return `;${key}=${valueEncoder(value)}`;
197
+ }
198
+
199
+ if (style === 'form') {
200
+ return valueEncoder(value);
201
+ }
202
+
203
+ if (style === 'deepObject') {
204
+ return valueEncoder(value, {}, true);
205
+ }
206
+
207
+ return undefined;
208
+ }
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = buildRequest;
5
+ exports.applySecurities = applySecurities;
6
+
7
+ var _btoa = _interopRequireDefault(require("btoa"));
8
+
9
+ var _assign = _interopRequireDefault(require("lodash/assign"));
10
+
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+
13
+ // This function runs after the common function,
14
+ // `src/execute/index.js#buildRequest`
15
+ function buildRequest(options, req) {
16
+ const {
17
+ spec,
18
+ operation,
19
+ securities,
20
+ requestContentType,
21
+ attachContentTypeForEmptyPayload
22
+ } = options; // Add securities, which are applicable
23
+
24
+ req = applySecurities({
25
+ request: req,
26
+ securities,
27
+ operation,
28
+ spec
29
+ });
30
+
31
+ if (req.body || req.form || attachContentTypeForEmptyPayload) {
32
+ // all following conditionals are Swagger2 only
33
+ if (requestContentType) {
34
+ req.headers['Content-Type'] = requestContentType;
35
+ } else if (Array.isArray(operation.consumes)) {
36
+ [req.headers['Content-Type']] = operation.consumes;
37
+ } else if (Array.isArray(spec.consumes)) {
38
+ [req.headers['Content-Type']] = spec.consumes;
39
+ } else if (operation.parameters && operation.parameters.filter(p => p.type === 'file').length) {
40
+ req.headers['Content-Type'] = 'multipart/form-data';
41
+ } else if (operation.parameters && operation.parameters.filter(p => p.in === 'formData').length) {
42
+ req.headers['Content-Type'] = 'application/x-www-form-urlencoded';
43
+ }
44
+ } else if (requestContentType) {
45
+ const isBodyParamPresent = operation.parameters && operation.parameters.filter(p => p.in === 'body').length > 0;
46
+ const isFormDataParamPresent = operation.parameters && operation.parameters.filter(p => p.in === 'formData').length > 0;
47
+
48
+ if (isBodyParamPresent || isFormDataParamPresent) {
49
+ req.headers['Content-Type'] = requestContentType;
50
+ }
51
+ }
52
+
53
+ return req;
54
+ } // Add security values, to operations - that declare their need on them
55
+
56
+
57
+ function applySecurities({
58
+ request,
59
+ securities = {},
60
+ operation = {},
61
+ spec
62
+ }) {
63
+ const result = (0, _assign.default)({}, request);
64
+ const {
65
+ authorized = {},
66
+ specSecurity = []
67
+ } = securities;
68
+ const security = operation.security || specSecurity;
69
+ const isAuthorized = authorized && !!Object.keys(authorized).length;
70
+ const securityDef = spec.securityDefinitions;
71
+ result.headers = result.headers || {};
72
+ result.query = result.query || {};
73
+
74
+ if (!Object.keys(securities).length || !isAuthorized || !security || Array.isArray(operation.security) && !operation.security.length) {
75
+ return request;
76
+ }
77
+
78
+ security.forEach(securityObj => {
79
+ Object.keys(securityObj).forEach(key => {
80
+ const auth = authorized[key];
81
+
82
+ if (!auth) {
83
+ return;
84
+ }
85
+
86
+ const {
87
+ token
88
+ } = auth;
89
+ const value = auth.value || auth;
90
+ const schema = securityDef[key];
91
+ const {
92
+ type
93
+ } = schema;
94
+ const tokenName = schema['x-tokenName'] || 'access_token';
95
+ const oauthToken = token && token[tokenName];
96
+ let tokenType = token && token.token_type;
97
+
98
+ if (auth) {
99
+ if (type === 'apiKey') {
100
+ const inType = schema.in === 'query' ? 'query' : 'headers';
101
+ result[inType] = result[inType] || {};
102
+ result[inType][schema.name] = value;
103
+ } else if (type === 'basic') {
104
+ if (value.header) {
105
+ result.headers.authorization = value.header;
106
+ } else {
107
+ const username = value.username || '';
108
+ const password = value.password || '';
109
+ value.base64 = (0, _btoa.default)(`${username}:${password}`);
110
+ result.headers.authorization = `Basic ${value.base64}`;
111
+ }
112
+ } else if (type === 'oauth2' && oauthToken) {
113
+ tokenType = !tokenType || tokenType.toLowerCase() === 'bearer' ? 'Bearer' : tokenType;
114
+ result.headers.authorization = `${tokenType} ${oauthToken}`;
115
+ }
116
+ }
117
+ });
118
+ });
119
+ return result;
120
+ }
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ // These functions will update the request.
6
+ // They'll be given {req, value, paramter, spec, operation}.
7
+ var _default = {
8
+ body: bodyBuilder,
9
+ header: headerBuilder,
10
+ query: queryBuilder,
11
+ path: pathBuilder,
12
+ formData: formDataBuilder
13
+ }; // Add the body to the request
14
+
15
+ exports.default = _default;
16
+
17
+ function bodyBuilder({
18
+ req,
19
+ value
20
+ }) {
21
+ req.body = value;
22
+ } // Add a form data object.
23
+
24
+
25
+ function formDataBuilder({
26
+ req,
27
+ value,
28
+ parameter
29
+ }) {
30
+ if (value || parameter.allowEmptyValue) {
31
+ req.form = req.form || {};
32
+ req.form[parameter.name] = {
33
+ value,
34
+ allowEmptyValue: parameter.allowEmptyValue,
35
+ collectionFormat: parameter.collectionFormat
36
+ };
37
+ }
38
+ } // Add a header to the request
39
+
40
+
41
+ function headerBuilder({
42
+ req,
43
+ parameter,
44
+ value
45
+ }) {
46
+ req.headers = req.headers || {};
47
+
48
+ if (typeof value !== 'undefined') {
49
+ req.headers[parameter.name] = value;
50
+ }
51
+ } // Replace path paramters, with values ( ie: the URL )
52
+
53
+
54
+ function pathBuilder({
55
+ req,
56
+ value,
57
+ parameter
58
+ }) {
59
+ req.url = req.url.split(`{${parameter.name}}`).join(encodeURIComponent(value));
60
+ } // Add a query to the `query` object, which will later be stringified into the URL's search
61
+
62
+
63
+ function queryBuilder({
64
+ req,
65
+ value,
66
+ parameter
67
+ }) {
68
+ req.query = req.query || {};
69
+
70
+ if (value === false && parameter.type === 'boolean') {
71
+ value = 'false';
72
+ }
73
+
74
+ if (value === 0 && ['number', 'integer'].indexOf(parameter.type) > -1) {
75
+ value = '0';
76
+ }
77
+
78
+ if (value) {
79
+ req.query[parameter.name] = {
80
+ collectionFormat: parameter.collectionFormat,
81
+ value
82
+ };
83
+ } else if (parameter.allowEmptyValue && value !== undefined) {
84
+ const paramName = parameter.name;
85
+ req.query[paramName] = req.query[paramName] || {};
86
+ req.query[paramName].allowEmptyValue = true;
87
+ }
88
+ }