httpsnippet-client-api 5.0.0-beta.3 → 5.0.0
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -22
- package/package.json +5 -5
- package/src/index.ts +11 -25
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { OASDocument } from 'oas/dist/rmoas.types';
|
|
2
1
|
import type { Client } from '@readme/httpsnippet/dist/targets/targets';
|
|
2
|
+
import type { OASDocument } from 'oas/dist/rmoas.types';
|
|
3
3
|
export interface APIOptions {
|
|
4
4
|
apiDefinition: OASDocument;
|
|
5
5
|
apiDefinitionUri: string;
|
package/dist/index.js
CHANGED
|
@@ -25,10 +25,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
25
25
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
26
|
};
|
|
27
27
|
exports.__esModule = true;
|
|
28
|
-
var stringify_object_1 = __importDefault(require("stringify-object"));
|
|
29
28
|
var code_builder_1 = require("@readme/httpsnippet/dist/helpers/code-builder");
|
|
30
29
|
var content_type_1 = __importDefault(require("content-type"));
|
|
31
30
|
var oas_1 = __importDefault(require("oas"));
|
|
31
|
+
var stringify_object_1 = __importDefault(require("stringify-object"));
|
|
32
32
|
function stringify(obj, opts) {
|
|
33
33
|
if (opts === void 0) { opts = {}; }
|
|
34
34
|
return (0, stringify_object_1["default"])(obj, __assign({ indent: ' ' }, opts));
|
|
@@ -157,16 +157,13 @@ var client = {
|
|
|
157
157
|
// snippet generator.
|
|
158
158
|
metadata[cookie] = cookiesObj[cookie];
|
|
159
159
|
});
|
|
160
|
-
// If we have path parameters present
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
metadata[param.substring(1)] = value;
|
|
168
|
-
});
|
|
169
|
-
}
|
|
160
|
+
// If we have path parameters present we should add them into the metadata object.
|
|
161
|
+
Array.from(Object.entries(operationSlugs)).forEach(function (_a) {
|
|
162
|
+
var param = _a[0], value = _a[1];
|
|
163
|
+
// The keys in `operationSlugs` will always be prefixed with a `:` in the `oas` library so
|
|
164
|
+
// we can safely do this substring here without asserting this context.
|
|
165
|
+
metadata[param.substring(1)] = value;
|
|
166
|
+
});
|
|
170
167
|
if (Object.keys(headersObj).length) {
|
|
171
168
|
var headers_1 = headersObj;
|
|
172
169
|
var requestHeaders_1 = {};
|
|
@@ -257,16 +254,7 @@ var client = {
|
|
|
257
254
|
}
|
|
258
255
|
}
|
|
259
256
|
var args = [];
|
|
260
|
-
var accessor =
|
|
261
|
-
if (operation.hasOperationId()) {
|
|
262
|
-
accessor = operation.getOperationId({ camelCase: true });
|
|
263
|
-
}
|
|
264
|
-
else {
|
|
265
|
-
// Since we're not using an operationId as our primary accessor we need to take the current
|
|
266
|
-
// operation that we're working with and transpile back our path parameters on top of it.
|
|
267
|
-
var slugs = Object.fromEntries(Object.keys(operationSlugs).map(function (slug) { return [slug.replace(/:(.*)/, '$1'), operationSlugs[slug]]; }));
|
|
268
|
-
args.push("'".concat(decodeURIComponent(oas.replaceUrl(path, slugs)), "'"));
|
|
269
|
-
}
|
|
257
|
+
var accessor = operation.getOperationId({ camelCase: true });
|
|
270
258
|
// If we're going to be rendering out body params and metadata we should cut their character
|
|
271
259
|
// limit in half because we'll be rendering them in their own lines.
|
|
272
260
|
var inlineCharacterLimit = typeof body !== 'undefined' && Object.keys(metadata).length > 0 ? 40 : 80;
|
|
@@ -283,7 +271,7 @@ var client = {
|
|
|
283
271
|
push(configData.join('\n'));
|
|
284
272
|
}
|
|
285
273
|
push("sdk.".concat(accessor, "(").concat(args.join(', '), ")"));
|
|
286
|
-
push('.then(
|
|
274
|
+
push('.then(({ data }) => console.log(data))', 1);
|
|
287
275
|
push('.catch(err => console.error(err));', 1);
|
|
288
276
|
return join();
|
|
289
277
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "httpsnippet-client-api",
|
|
3
|
-
"version": "5.0.0
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "An HTTPSnippet client for generating snippets for the `api` module.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@readme/httpsnippet": "^4.0.3",
|
|
32
|
-
"oas": "^
|
|
32
|
+
"oas": "^20.0.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@readme/oas-examples": "^5.
|
|
35
|
+
"@readme/oas-examples": "^5.7.1",
|
|
36
36
|
"@readme/openapi-parser": "^2.2.0",
|
|
37
37
|
"@types/content-type": "^1.1.5",
|
|
38
38
|
"@types/stringify-object": "^4.0.1",
|
|
39
|
-
"api": "^5.0.0
|
|
39
|
+
"api": "^5.0.0",
|
|
40
40
|
"chai": "^4.3.6",
|
|
41
41
|
"fetch-mock": "^9.11.0",
|
|
42
42
|
"isomorphic-fetch": "^3.0.0",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"test/"
|
|
54
54
|
]
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "bb044ecdb3296c24838056764553fa7f18e6d228"
|
|
57
57
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import type { ReducedHelperObject } from '@readme/httpsnippet/dist/helpers/reducer';
|
|
2
|
+
import type { Client } from '@readme/httpsnippet/dist/targets/targets';
|
|
1
3
|
import type { Operation } from 'oas';
|
|
2
4
|
import type { HttpMethods, OASDocument } from 'oas/dist/rmoas.types';
|
|
3
|
-
import type { Client } from '@readme/httpsnippet/dist/targets/targets';
|
|
4
|
-
import type { ReducedHelperObject } from '@readme/httpsnippet/dist/helpers/reducer';
|
|
5
5
|
|
|
6
|
-
import stringifyObject from 'stringify-object';
|
|
7
6
|
import { CodeBuilder } from '@readme/httpsnippet/dist/helpers/code-builder';
|
|
8
7
|
import contentType from 'content-type';
|
|
9
8
|
import Oas from 'oas';
|
|
9
|
+
import stringifyObject from 'stringify-object';
|
|
10
10
|
|
|
11
11
|
// This should really be an exported type in `oas`.
|
|
12
12
|
type SecurityType = 'Basic' | 'Bearer' | 'Query' | 'Header' | 'Cookie' | 'OAuth2' | 'http' | 'apiKey';
|
|
@@ -165,15 +165,12 @@ const client: Client<APIOptions> = {
|
|
|
165
165
|
metadata[cookie] = cookiesObj[cookie];
|
|
166
166
|
});
|
|
167
167
|
|
|
168
|
-
// If we have path parameters present
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
metadata[param.substring(1)] = value;
|
|
175
|
-
});
|
|
176
|
-
}
|
|
168
|
+
// If we have path parameters present we should add them into the metadata object.
|
|
169
|
+
Array.from(Object.entries(operationSlugs)).forEach(([param, value]) => {
|
|
170
|
+
// The keys in `operationSlugs` will always be prefixed with a `:` in the `oas` library so
|
|
171
|
+
// we can safely do this substring here without asserting this context.
|
|
172
|
+
metadata[param.substring(1)] = value;
|
|
173
|
+
});
|
|
177
174
|
|
|
178
175
|
if (Object.keys(headersObj).length) {
|
|
179
176
|
const headers = headersObj;
|
|
@@ -275,18 +272,7 @@ const client: Client<APIOptions> = {
|
|
|
275
272
|
|
|
276
273
|
const args = [];
|
|
277
274
|
|
|
278
|
-
|
|
279
|
-
if (operation.hasOperationId()) {
|
|
280
|
-
accessor = operation.getOperationId({ camelCase: true });
|
|
281
|
-
} else {
|
|
282
|
-
// Since we're not using an operationId as our primary accessor we need to take the current
|
|
283
|
-
// operation that we're working with and transpile back our path parameters on top of it.
|
|
284
|
-
const slugs = Object.fromEntries(
|
|
285
|
-
Object.keys(operationSlugs).map(slug => [slug.replace(/:(.*)/, '$1'), operationSlugs[slug]])
|
|
286
|
-
);
|
|
287
|
-
|
|
288
|
-
args.push(`'${decodeURIComponent(oas.replaceUrl(path, slugs))}'`);
|
|
289
|
-
}
|
|
275
|
+
const accessor = operation.getOperationId({ camelCase: true });
|
|
290
276
|
|
|
291
277
|
// If we're going to be rendering out body params and metadata we should cut their character
|
|
292
278
|
// limit in half because we'll be rendering them in their own lines.
|
|
@@ -308,7 +294,7 @@ const client: Client<APIOptions> = {
|
|
|
308
294
|
}
|
|
309
295
|
|
|
310
296
|
push(`sdk.${accessor}(${args.join(', ')})`);
|
|
311
|
-
push('.then(
|
|
297
|
+
push('.then(({ data }) => console.log(data))', 1);
|
|
312
298
|
push('.catch(err => console.error(err));', 1);
|
|
313
299
|
|
|
314
300
|
return join();
|