@readme/oas-to-har 21.0.2 → 21.0.4
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.js +1 -20
- package/dist/lib/style-formatting/index.js +5 -1
- package/dist/lib/utils.d.ts +8 -0
- package/dist/lib/utils.js +20 -3
- package/package.json +10 -10
- package/src/index.ts +1 -20
- package/src/lib/style-formatting/index.ts +5 -1
- package/src/lib/utils.ts +19 -2
package/dist/index.js
CHANGED
|
@@ -125,25 +125,6 @@ function multipartBodyToFormatterParams(payload, oasMediaTypeObject, schema) {
|
|
|
125
125
|
// empty array if we get anything else.
|
|
126
126
|
return [];
|
|
127
127
|
}
|
|
128
|
-
/**
|
|
129
|
-
* Because some request body schema shapes might not always be a top-level `properties`, instead
|
|
130
|
-
* nesting it in an `oneOf` or `anyOf` we need to extract the first usable schema that we have. If
|
|
131
|
-
* we don't do this then these non-conventional request body schema payloads may not be properly
|
|
132
|
-
* represented in the HAR that we generate.
|
|
133
|
-
*
|
|
134
|
-
*/
|
|
135
|
-
function getSafeRequestBody(obj) {
|
|
136
|
-
if ('properties' in obj) {
|
|
137
|
-
return obj;
|
|
138
|
-
}
|
|
139
|
-
else if ('oneOf' in obj) {
|
|
140
|
-
return getSafeRequestBody(obj.oneOf[0]);
|
|
141
|
-
}
|
|
142
|
-
else if ('anyOf' in obj) {
|
|
143
|
-
return getSafeRequestBody(obj.anyOf[0]);
|
|
144
|
-
}
|
|
145
|
-
return {};
|
|
146
|
-
}
|
|
147
128
|
var defaultFormDataTypes = Object.keys(jsonSchemaTypes).reduce(function (prev, curr) {
|
|
148
129
|
var _a;
|
|
149
130
|
return Object.assign(prev, (_a = {}, _a[curr] = {}, _a));
|
|
@@ -400,7 +381,7 @@ function oasToHar(oas, operationSchema, values, auth, opts) {
|
|
|
400
381
|
// Because some request body schema shapes might not always be a top-level `properties`,
|
|
401
382
|
// instead nesting it in an `oneOf` or `anyOf` we need to extract the first usable
|
|
402
383
|
// schema that we have in order to process this multipart payload.
|
|
403
|
-
var safeBodySchema_1 = getSafeRequestBody(requestBodySchema);
|
|
384
|
+
var safeBodySchema_1 = (0, utils_1.getSafeRequestBody)(requestBodySchema);
|
|
404
385
|
/**
|
|
405
386
|
* Discover all `{ type: string, format: binary }` properties, or arrays containing the
|
|
406
387
|
* same, within the request body. If there are any, then that means that we're dealing
|
|
@@ -198,7 +198,11 @@ function handleExplode(value, parameter) {
|
|
|
198
198
|
return stylizeValue(value, parameter);
|
|
199
199
|
}
|
|
200
200
|
function shouldExplode(parameter) {
|
|
201
|
-
return ((parameter.explode ||
|
|
201
|
+
return ((parameter.explode ||
|
|
202
|
+
(parameter.explode !== false && parameter.style === 'form') ||
|
|
203
|
+
// style: deepObject && explode: false doesn't exist so explode it always
|
|
204
|
+
// https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#style-examples
|
|
205
|
+
parameter.style === 'deepObject') &&
|
|
202
206
|
// header and path doesn't explode into separate parameters like query and cookie do
|
|
203
207
|
parameter.in !== 'header' &&
|
|
204
208
|
parameter.in !== 'path');
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -4,6 +4,14 @@ import type { SchemaObject } from 'oas/dist/rmoas.types';
|
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
6
|
export declare function hasSchemaType(schema: SchemaObject, discriminator: 'array' | 'object' | 'string' | 'number' | 'boolean' | 'integer' | 'null'): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Because some request body schema shapes might not always be a top-level `properties`, instead
|
|
9
|
+
* nesting it in an `oneOf` or `anyOf` we need to extract the first usable schema that we have. If
|
|
10
|
+
* we don't do this then these non-conventional request body schema payloads may not be properly
|
|
11
|
+
* represented in the HAR that we generate.
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
export declare function getSafeRequestBody(obj: any): any;
|
|
7
15
|
interface Options {
|
|
8
16
|
parentIsArray?: boolean;
|
|
9
17
|
parentKey?: string;
|
package/dist/lib/utils.js
CHANGED
|
@@ -16,7 +16,7 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
16
16
|
return ar;
|
|
17
17
|
};
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.getTypedFormatsInSchema = exports.hasSchemaType = void 0;
|
|
19
|
+
exports.getTypedFormatsInSchema = exports.getSafeRequestBody = exports.hasSchemaType = void 0;
|
|
20
20
|
var lodash_1 = require("lodash"); // eslint-disable-line no-restricted-imports
|
|
21
21
|
/**
|
|
22
22
|
* Determine if a schema `type` is, or contains, a specific discriminator.
|
|
@@ -29,6 +29,23 @@ function hasSchemaType(schema, discriminator) {
|
|
|
29
29
|
return schema.type === discriminator;
|
|
30
30
|
}
|
|
31
31
|
exports.hasSchemaType = hasSchemaType;
|
|
32
|
+
/**
|
|
33
|
+
* Because some request body schema shapes might not always be a top-level `properties`, instead
|
|
34
|
+
* nesting it in an `oneOf` or `anyOf` we need to extract the first usable schema that we have. If
|
|
35
|
+
* we don't do this then these non-conventional request body schema payloads may not be properly
|
|
36
|
+
* represented in the HAR that we generate.
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
function getSafeRequestBody(obj) {
|
|
40
|
+
if ('oneOf' in obj) {
|
|
41
|
+
return getSafeRequestBody(obj.oneOf[0]);
|
|
42
|
+
}
|
|
43
|
+
else if ('anyOf' in obj) {
|
|
44
|
+
return getSafeRequestBody(obj.anyOf[0]);
|
|
45
|
+
}
|
|
46
|
+
return obj;
|
|
47
|
+
}
|
|
48
|
+
exports.getSafeRequestBody = getSafeRequestBody;
|
|
32
49
|
function getSubschemas(schema, opts) {
|
|
33
50
|
var subSchemaDataSize = 0;
|
|
34
51
|
if (opts.parentIsArray) {
|
|
@@ -48,7 +65,7 @@ function getSubschemas(schema, opts) {
|
|
|
48
65
|
var _b = __read(_a, 2), key = _b[0], subschema = _b[1];
|
|
49
66
|
return ({
|
|
50
67
|
key: opts.parentKey ? [opts.parentKey, idx, key].join('.') : key,
|
|
51
|
-
schema: subschema,
|
|
68
|
+
schema: getSafeRequestBody(subschema),
|
|
52
69
|
});
|
|
53
70
|
}));
|
|
54
71
|
};
|
|
@@ -61,7 +78,7 @@ function getSubschemas(schema, opts) {
|
|
|
61
78
|
var _b = __read(_a, 2), key = _b[0], subschema = _b[1];
|
|
62
79
|
return ({
|
|
63
80
|
key: opts.parentKey ? [opts.parentKey, key].join('.') : key,
|
|
64
|
-
schema: subschema,
|
|
81
|
+
schema: getSafeRequestBody(subschema),
|
|
65
82
|
});
|
|
66
83
|
});
|
|
67
84
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@readme/oas-to-har",
|
|
3
3
|
"description": "Utility to transform an OAS operation into a HAR representation",
|
|
4
|
-
"version": "21.0.
|
|
4
|
+
"version": "21.0.4",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"author": "Jon Ursenbach <jon@ursenba.ch>",
|
|
@@ -27,27 +27,27 @@
|
|
|
27
27
|
"@readme/data-urls": "^1.0.1",
|
|
28
28
|
"@readme/oas-extensions": "^17.0.1",
|
|
29
29
|
"lodash": "^4.17.21",
|
|
30
|
-
"oas": "^20.
|
|
30
|
+
"oas": "^20.10.1",
|
|
31
31
|
"qs": "^6.11.2",
|
|
32
32
|
"remove-undefined-objects": "^3.0.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@commitlint/cli": "^17.6.
|
|
36
|
-
"@commitlint/config-conventional": "^17.6.
|
|
35
|
+
"@commitlint/cli": "^17.6.7",
|
|
36
|
+
"@commitlint/config-conventional": "^17.6.7",
|
|
37
37
|
"@readme/eslint-config": "^10.6.2",
|
|
38
|
-
"@readme/oas-examples": "^5.
|
|
38
|
+
"@readme/oas-examples": "^5.12.0",
|
|
39
39
|
"@types/har-format": "^1.2.11",
|
|
40
|
-
"@types/jest": "^29.5.
|
|
41
|
-
"@types/lodash": "^4.14.
|
|
40
|
+
"@types/jest": "^29.5.3",
|
|
41
|
+
"@types/lodash": "^4.14.196",
|
|
42
42
|
"@types/qs": "^6.9.7",
|
|
43
|
-
"eslint": "^8.
|
|
43
|
+
"eslint": "^8.45.0",
|
|
44
44
|
"har-validator": "^5.1.5",
|
|
45
45
|
"husky": "^8.0.3",
|
|
46
|
-
"jest": "^29.6.
|
|
46
|
+
"jest": "^29.6.2",
|
|
47
47
|
"jest-expect-har": "^6.0.0",
|
|
48
48
|
"prettier": "^2.8.8",
|
|
49
49
|
"ts-jest": "^29.1.1",
|
|
50
|
-
"type-fest": "^
|
|
50
|
+
"type-fest": "^4.0.0",
|
|
51
51
|
"typescript": "^5.1.6"
|
|
52
52
|
},
|
|
53
53
|
"browserslist": [
|
package/src/index.ts
CHANGED
|
@@ -24,7 +24,7 @@ import removeUndefinedObjects from 'remove-undefined-objects';
|
|
|
24
24
|
|
|
25
25
|
import configureSecurity from './lib/configure-security';
|
|
26
26
|
import formatStyle from './lib/style-formatting';
|
|
27
|
-
import { getTypedFormatsInSchema, hasSchemaType } from './lib/utils';
|
|
27
|
+
import { getSafeRequestBody, getTypedFormatsInSchema, hasSchemaType } from './lib/utils';
|
|
28
28
|
|
|
29
29
|
const { jsonSchemaTypes, matchesMimeType } = utils;
|
|
30
30
|
|
|
@@ -137,25 +137,6 @@ function multipartBodyToFormatterParams(payload: unknown, oasMediaTypeObject: Me
|
|
|
137
137
|
return [];
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
/**
|
|
141
|
-
* Because some request body schema shapes might not always be a top-level `properties`, instead
|
|
142
|
-
* nesting it in an `oneOf` or `anyOf` we need to extract the first usable schema that we have. If
|
|
143
|
-
* we don't do this then these non-conventional request body schema payloads may not be properly
|
|
144
|
-
* represented in the HAR that we generate.
|
|
145
|
-
*
|
|
146
|
-
*/
|
|
147
|
-
function getSafeRequestBody(obj: any) {
|
|
148
|
-
if ('properties' in obj) {
|
|
149
|
-
return obj;
|
|
150
|
-
} else if ('oneOf' in obj) {
|
|
151
|
-
return getSafeRequestBody(obj.oneOf[0]);
|
|
152
|
-
} else if ('anyOf' in obj) {
|
|
153
|
-
return getSafeRequestBody(obj.anyOf[0]);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return {};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
140
|
const defaultFormDataTypes = Object.keys(jsonSchemaTypes).reduce((prev, curr) => {
|
|
160
141
|
return Object.assign(prev, { [curr]: {} });
|
|
161
142
|
}, {});
|
|
@@ -215,7 +215,11 @@ function handleExplode(value: any, parameter: ParameterObject) {
|
|
|
215
215
|
|
|
216
216
|
function shouldExplode(parameter: ParameterObject) {
|
|
217
217
|
return (
|
|
218
|
-
(parameter.explode ||
|
|
218
|
+
(parameter.explode ||
|
|
219
|
+
(parameter.explode !== false && parameter.style === 'form') ||
|
|
220
|
+
// style: deepObject && explode: false doesn't exist so explode it always
|
|
221
|
+
// https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#style-examples
|
|
222
|
+
parameter.style === 'deepObject') &&
|
|
219
223
|
// header and path doesn't explode into separate parameters like query and cookie do
|
|
220
224
|
parameter.in !== 'header' &&
|
|
221
225
|
parameter.in !== 'path'
|
package/src/lib/utils.ts
CHANGED
|
@@ -17,6 +17,23 @@ export function hasSchemaType(
|
|
|
17
17
|
return schema.type === discriminator;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Because some request body schema shapes might not always be a top-level `properties`, instead
|
|
22
|
+
* nesting it in an `oneOf` or `anyOf` we need to extract the first usable schema that we have. If
|
|
23
|
+
* we don't do this then these non-conventional request body schema payloads may not be properly
|
|
24
|
+
* represented in the HAR that we generate.
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
export function getSafeRequestBody(obj: any) {
|
|
28
|
+
if ('oneOf' in obj) {
|
|
29
|
+
return getSafeRequestBody(obj.oneOf[0]);
|
|
30
|
+
} else if ('anyOf' in obj) {
|
|
31
|
+
return getSafeRequestBody(obj.anyOf[0]);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return obj;
|
|
35
|
+
}
|
|
36
|
+
|
|
20
37
|
interface Options {
|
|
21
38
|
parentIsArray?: boolean;
|
|
22
39
|
parentKey?: string;
|
|
@@ -43,14 +60,14 @@ function getSubschemas(schema: any, opts: Options) {
|
|
|
43
60
|
subschemas = subschemas.concat(
|
|
44
61
|
Object.entries(schema).map(([key, subschema]: [string, JSONSchema]) => ({
|
|
45
62
|
key: opts.parentKey ? [opts.parentKey, idx, key].join('.') : key,
|
|
46
|
-
schema: subschema,
|
|
63
|
+
schema: getSafeRequestBody(subschema),
|
|
47
64
|
}))
|
|
48
65
|
);
|
|
49
66
|
}
|
|
50
67
|
} else {
|
|
51
68
|
subschemas = Object.entries(schema).map(([key, subschema]: [string, JSONSchema]) => ({
|
|
52
69
|
key: opts.parentKey ? [opts.parentKey, key].join('.') : key,
|
|
53
|
-
schema: subschema,
|
|
70
|
+
schema: getSafeRequestBody(subschema),
|
|
54
71
|
}));
|
|
55
72
|
}
|
|
56
73
|
|