httpsnippet-client-api 6.0.1 → 6.1.1
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/dist/index.d.ts +1 -1
- package/dist/index.js +28 -5
- package/package.json +8 -16
- package/src/index.ts +9 -8
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import type { OASDocument } from 'oas/dist/rmoas.types';
|
|
|
3
3
|
export interface APIOptions {
|
|
4
4
|
apiDefinition: OASDocument;
|
|
5
5
|
apiDefinitionUri: string;
|
|
6
|
-
indent?: string | false;
|
|
7
6
|
escapeBrackets?: boolean;
|
|
7
|
+
indent?: string | false;
|
|
8
8
|
}
|
|
9
9
|
declare const client: Client<APIOptions>;
|
|
10
10
|
export default client;
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,29 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
13
36
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
37
|
var t = {};
|
|
15
38
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -27,8 +50,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
50
|
exports.__esModule = true;
|
|
28
51
|
var code_builder_1 = require("@readme/httpsnippet/dist/helpers/code-builder");
|
|
29
52
|
var content_type_1 = __importDefault(require("content-type"));
|
|
30
|
-
var oas_1 =
|
|
53
|
+
var oas_1 = __importStar(require("oas"));
|
|
31
54
|
var stringify_object_1 = __importDefault(require("stringify-object"));
|
|
55
|
+
var matchesMimeType = oas_1.utils.matchesMimeType;
|
|
32
56
|
function stringify(obj, opts) {
|
|
33
57
|
if (opts === void 0) { opts = {}; }
|
|
34
58
|
return (0, stringify_object_1["default"])(obj, __assign({ indent: ' ' }, opts));
|
|
@@ -214,10 +238,9 @@ var client = {
|
|
|
214
238
|
}
|
|
215
239
|
}
|
|
216
240
|
else if (headerLower === 'accept') {
|
|
217
|
-
// If the `Accept` header here is
|
|
218
|
-
//
|
|
219
|
-
|
|
220
|
-
if (headers_1[header] === operation.getContentType()) {
|
|
241
|
+
// If the `Accept` header here is JSON-like header then we can remove it from the code
|
|
242
|
+
// snippet because `api` natively supports and prioritizes JSON over any other mime type.
|
|
243
|
+
if (matchesMimeType.json(headers_1[header])) {
|
|
221
244
|
delete headers_1[header];
|
|
222
245
|
return;
|
|
223
246
|
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "httpsnippet-client-api",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.1",
|
|
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",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
|
+
"lint:types": "tsc --noEmit",
|
|
9
10
|
"prebuild": "rm -rf dist/",
|
|
10
11
|
"prepack": "npm run build",
|
|
11
|
-
"test": "
|
|
12
|
+
"test": "vitest --coverage"
|
|
12
13
|
},
|
|
13
14
|
"repository": {
|
|
14
15
|
"type": "git",
|
|
@@ -36,22 +37,13 @@
|
|
|
36
37
|
"@readme/openapi-parser": "^2.4.0",
|
|
37
38
|
"@types/content-type": "^1.1.5",
|
|
38
39
|
"@types/stringify-object": "^4.0.2",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
40
|
+
"@vitest/coverage-v8": "^0.34.1",
|
|
41
|
+
"api": "^6.1.1",
|
|
41
42
|
"fetch-mock": "^9.11.0",
|
|
42
43
|
"isomorphic-fetch": "^3.0.0",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"sinon": "^15.0.1",
|
|
46
|
-
"sinon-chai": "^3.7.0",
|
|
47
|
-
"typescript": "^4.9.5"
|
|
44
|
+
"typescript": "^4.9.5",
|
|
45
|
+
"vitest": "^0.34.1"
|
|
48
46
|
},
|
|
49
47
|
"prettier": "@readme/eslint-config/prettier",
|
|
50
|
-
"
|
|
51
|
-
"exclude": [
|
|
52
|
-
"dist/",
|
|
53
|
-
"test/"
|
|
54
|
-
]
|
|
55
|
-
},
|
|
56
|
-
"gitHead": "5fe262d794d82935f08863341b0d95b9eb8ac39b"
|
|
48
|
+
"gitHead": "e440a28841e753895bfb5315b4d31f679824fa39"
|
|
57
49
|
}
|
package/src/index.ts
CHANGED
|
@@ -5,9 +5,11 @@ import type { HttpMethods, OASDocument } from 'oas/dist/rmoas.types';
|
|
|
5
5
|
|
|
6
6
|
import { CodeBuilder } from '@readme/httpsnippet/dist/helpers/code-builder';
|
|
7
7
|
import contentType from 'content-type';
|
|
8
|
-
import Oas from 'oas';
|
|
8
|
+
import Oas, { utils } from 'oas';
|
|
9
9
|
import stringifyObject from 'stringify-object';
|
|
10
10
|
|
|
11
|
+
const { matchesMimeType } = utils;
|
|
12
|
+
|
|
11
13
|
// This should really be an exported type in `oas`.
|
|
12
14
|
type SecurityType = 'Basic' | 'Bearer' | 'Query' | 'Header' | 'Cookie' | 'OAuth2' | 'http' | 'apiKey';
|
|
13
15
|
|
|
@@ -35,7 +37,7 @@ function buildAuthSnippet(authKey: string | string[]) {
|
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
function getAuthSources(operation: Operation) {
|
|
38
|
-
const matchers: { header: Record<string, string>; query: string[]
|
|
40
|
+
const matchers: { cookie: string[]; header: Record<string, string>; query: string[] } = {
|
|
39
41
|
header: {},
|
|
40
42
|
query: [],
|
|
41
43
|
cookie: [],
|
|
@@ -79,8 +81,8 @@ function getAuthSources(operation: Operation) {
|
|
|
79
81
|
export interface APIOptions {
|
|
80
82
|
apiDefinition: OASDocument;
|
|
81
83
|
apiDefinitionUri: string;
|
|
82
|
-
indent?: string | false;
|
|
83
84
|
escapeBrackets?: boolean;
|
|
85
|
+
indent?: string | false;
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
const client: Client<APIOptions> = {
|
|
@@ -107,7 +109,7 @@ const client: Client<APIOptions> = {
|
|
|
107
109
|
const foundOperation = oas.findOperation(url, method);
|
|
108
110
|
if (!foundOperation) {
|
|
109
111
|
throw new Error(
|
|
110
|
-
`Unable to locate a matching operation in the supplied \`apiDefinition\` for: ${source.method} ${url}
|
|
112
|
+
`Unable to locate a matching operation in the supplied \`apiDefinition\` for: ${source.method} ${url}`,
|
|
111
113
|
);
|
|
112
114
|
}
|
|
113
115
|
|
|
@@ -224,10 +226,9 @@ const client: Client<APIOptions> = {
|
|
|
224
226
|
return;
|
|
225
227
|
}
|
|
226
228
|
} else if (headerLower === 'accept') {
|
|
227
|
-
// If the `Accept` header here is
|
|
228
|
-
//
|
|
229
|
-
|
|
230
|
-
if (headers[header] === operation.getContentType()) {
|
|
229
|
+
// If the `Accept` header here is JSON-like header then we can remove it from the code
|
|
230
|
+
// snippet because `api` natively supports and prioritizes JSON over any other mime type.
|
|
231
|
+
if (matchesMimeType.json(headers[header] as string)) {
|
|
231
232
|
delete headers[header];
|
|
232
233
|
return;
|
|
233
234
|
}
|