httpsnippet-client-api 4.0.0 → 4.1.3
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/package.json +5 -6
- package/src/index.js +19 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "httpsnippet-client-api",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.3",
|
|
4
4
|
"description": "An HTTP Snippet client for generating snippets for the api module.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@readme/httpsnippet": "^3.0.0",
|
|
32
|
-
"oas": "^
|
|
32
|
+
"oas": "^17.1.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@readme/eslint-config": "^
|
|
35
|
+
"@readme/eslint-config": "^8.0.2",
|
|
36
36
|
"@readme/oas-examples": "^4.3.2",
|
|
37
|
-
"eslint": "^
|
|
37
|
+
"eslint": "^8.3.0",
|
|
38
38
|
"jest": "^27.3.1",
|
|
39
39
|
"prettier": "^2.4.1"
|
|
40
40
|
},
|
|
@@ -43,6 +43,5 @@
|
|
|
43
43
|
"testPathIgnorePatterns": [
|
|
44
44
|
"__tests__/__fixtures__/"
|
|
45
45
|
]
|
|
46
|
-
}
|
|
47
|
-
"gitHead": "f1d2c251f1468bceb78e39731e20f30c6745c419"
|
|
46
|
+
}
|
|
48
47
|
}
|
package/src/index.js
CHANGED
|
@@ -2,7 +2,7 @@ const { match } = require('path-to-regexp');
|
|
|
2
2
|
const stringifyObject = require('stringify-object');
|
|
3
3
|
const CodeBuilder = require('@readme/httpsnippet/src/helpers/code-builder');
|
|
4
4
|
const contentType = require('content-type');
|
|
5
|
-
const Oas = require('oas');
|
|
5
|
+
const Oas = require('oas').default;
|
|
6
6
|
|
|
7
7
|
function stringify(obj, opts = {}) {
|
|
8
8
|
return stringifyObject(obj, { indent: ' ', ...opts });
|
|
@@ -90,6 +90,7 @@ module.exports = function (source, options) {
|
|
|
90
90
|
|
|
91
91
|
const method = source.method.toLowerCase();
|
|
92
92
|
const oas = new Oas(opts.apiDefinition);
|
|
93
|
+
const apiDefinition = oas.getDefinition();
|
|
93
94
|
const foundOperation = oas.findOperation(source.url, method);
|
|
94
95
|
if (!foundOperation) {
|
|
95
96
|
throw new Error(
|
|
@@ -112,7 +113,7 @@ module.exports = function (source, options) {
|
|
|
112
113
|
// `oas` library then the URL either has server variables contained in it (that don't match the defaults), or the
|
|
113
114
|
// OAS offers alternate server URLs and we should expose that in the generated snippet.
|
|
114
115
|
const configData = [];
|
|
115
|
-
if ((
|
|
116
|
+
if ((apiDefinition.servers || []).length > 1) {
|
|
116
117
|
const stockUrl = oas.url();
|
|
117
118
|
const baseUrl = source.url.replace(path, '');
|
|
118
119
|
if (baseUrl !== stockUrl) {
|
|
@@ -212,22 +213,24 @@ module.exports = function (source, options) {
|
|
|
212
213
|
break;
|
|
213
214
|
|
|
214
215
|
case 'multipart/form-data':
|
|
215
|
-
|
|
216
|
+
if (source.postData.params) {
|
|
217
|
+
body = {};
|
|
218
|
+
|
|
219
|
+
// If there's a `Content-Type` header present in the metadata, but it's for the form-data
|
|
220
|
+
// request then dump it off the snippet. We shouldn't offload that unnecessary bloat to the
|
|
221
|
+
// user, instead letting the SDK handle it automatically.
|
|
222
|
+
if ('content-type' in metadata && metadata['content-type'].indexOf('multipart/form-data') === 0) {
|
|
223
|
+
delete metadata['content-type'];
|
|
224
|
+
}
|
|
216
225
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
226
|
+
source.postData.params.forEach(function (param) {
|
|
227
|
+
if (param.fileName) {
|
|
228
|
+
body[param.name] = param.fileName;
|
|
229
|
+
} else {
|
|
230
|
+
body[param.name] = param.value;
|
|
231
|
+
}
|
|
232
|
+
});
|
|
222
233
|
}
|
|
223
|
-
|
|
224
|
-
source.postData.params.forEach(function (param) {
|
|
225
|
-
if (param.fileName) {
|
|
226
|
-
body[param.name] = param.fileName;
|
|
227
|
-
} else {
|
|
228
|
-
body[param.name] = param.value;
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
234
|
break;
|
|
232
235
|
|
|
233
236
|
default:
|