@scalar/oas-utils 0.2.140 → 0.2.142
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/CHANGELOG.md +18 -0
- package/dist/entities/cookie/cookie.js +14 -13
- package/dist/entities/cookie/cookie.js.map +7 -0
- package/dist/entities/cookie/index.d.ts +1 -1
- package/dist/entities/cookie/index.d.ts.map +1 -1
- package/dist/entities/cookie/index.js +5 -1
- package/dist/entities/cookie/index.js.map +7 -0
- package/dist/entities/environment/environment.js +10 -9
- package/dist/entities/environment/environment.js.map +7 -0
- package/dist/entities/environment/index.d.ts +1 -1
- package/dist/entities/environment/index.d.ts.map +1 -1
- package/dist/entities/environment/index.js +5 -1
- package/dist/entities/environment/index.js.map +7 -0
- package/dist/entities/hotkeys/hotkeys.js +109 -116
- package/dist/entities/hotkeys/hotkeys.js.map +7 -0
- package/dist/entities/hotkeys/index.d.ts +1 -1
- package/dist/entities/hotkeys/index.d.ts.map +1 -1
- package/dist/entities/hotkeys/index.js +6 -1
- package/dist/entities/hotkeys/index.js.map +7 -0
- package/dist/entities/shared/index.d.ts +1 -1
- package/dist/entities/shared/index.d.ts.map +1 -1
- package/dist/entities/shared/index.js +7 -1
- package/dist/entities/shared/index.js.map +7 -0
- package/dist/entities/shared/utility.js +9 -12
- package/dist/entities/shared/utility.js.map +7 -0
- package/dist/entities/spec/collection.d.ts.map +1 -1
- package/dist/entities/spec/collection.js +91 -94
- package/dist/entities/spec/collection.js.map +7 -0
- package/dist/entities/spec/index.d.ts +8 -8
- package/dist/entities/spec/index.d.ts.map +1 -1
- package/dist/entities/spec/index.js +59 -9
- package/dist/entities/spec/index.js.map +7 -0
- package/dist/entities/spec/operation.d.ts +1 -1
- package/dist/entities/spec/operation.d.ts.map +1 -1
- package/dist/entities/spec/operation.js +5 -8
- package/dist/entities/spec/operation.js.map +7 -0
- package/dist/entities/spec/operation.test.js +43 -0
- package/dist/entities/spec/operation.test.js.map +7 -0
- package/dist/entities/spec/parameters.d.ts +1 -1
- package/dist/entities/spec/parameters.d.ts.map +1 -1
- package/dist/entities/spec/parameters.js +40 -38
- package/dist/entities/spec/parameters.js.map +7 -0
- package/dist/entities/spec/parameters.test.js +71 -0
- package/dist/entities/spec/parameters.test.js.map +7 -0
- package/dist/entities/spec/request-example.test.js +637 -0
- package/dist/entities/spec/request-example.test.js.map +7 -0
- package/dist/entities/spec/request-examples.d.ts +3 -3
- package/dist/entities/spec/request-examples.d.ts.map +1 -1
- package/dist/entities/spec/request-examples.js +323 -338
- package/dist/entities/spec/request-examples.js.map +7 -0
- package/dist/entities/spec/requests.d.ts +6 -8
- package/dist/entities/spec/requests.d.ts.map +1 -1
- package/dist/entities/spec/requests.js +80 -101
- package/dist/entities/spec/requests.js.map +7 -0
- package/dist/entities/spec/server.js +47 -63
- package/dist/entities/spec/server.js.map +7 -0
- package/dist/entities/spec/server.test.js +120 -0
- package/dist/entities/spec/server.test.js.map +7 -0
- package/dist/entities/spec/spec-objects.d.ts.map +1 -1
- package/dist/entities/spec/spec-objects.js +77 -121
- package/dist/entities/spec/spec-objects.js.map +7 -0
- package/dist/entities/spec/spec-objects.test.js +205 -0
- package/dist/entities/spec/spec-objects.test.js.map +7 -0
- package/dist/entities/spec/x-scalar-environments.js +21 -18
- package/dist/entities/spec/x-scalar-environments.js.map +7 -0
- package/dist/entities/spec/x-scalar-environments.test.js +11 -0
- package/dist/entities/spec/x-scalar-environments.test.js.map +7 -0
- package/dist/entities/spec/x-scalar-secrets.js +8 -6
- package/dist/entities/spec/x-scalar-secrets.js.map +7 -0
- package/dist/entities/spec/x-scalar-secrets.test.js +11 -0
- package/dist/entities/spec/x-scalar-secrets.test.js.map +7 -0
- package/dist/entities/workspace/index.d.ts +1 -1
- package/dist/entities/workspace/index.d.ts.map +1 -1
- package/dist/entities/workspace/index.js +7 -1
- package/dist/entities/workspace/index.js.map +7 -0
- package/dist/entities/workspace/workspace.js +46 -50
- package/dist/entities/workspace/workspace.js.map +7 -0
- package/dist/helpers/create-hash.js +15 -18
- package/dist/helpers/create-hash.js.map +7 -0
- package/dist/helpers/ensure-protocol.js +9 -10
- package/dist/helpers/ensure-protocol.js.map +7 -0
- package/dist/helpers/ensure-protocol.test.js +70 -0
- package/dist/helpers/ensure-protocol.test.js.map +7 -0
- package/dist/helpers/fetch-document.js +24 -32
- package/dist/helpers/fetch-document.js.map +7 -0
- package/dist/helpers/fetch-document.test.js +63 -0
- package/dist/helpers/fetch-document.test.js.map +7 -0
- package/dist/helpers/fetch-with-proxy-fallback.js +20 -28
- package/dist/helpers/fetch-with-proxy-fallback.js.map +7 -0
- package/dist/helpers/find-variables.d.ts +1 -1
- package/dist/helpers/find-variables.d.ts.map +1 -1
- package/dist/helpers/find-variables.js +6 -8
- package/dist/helpers/find-variables.js.map +7 -0
- package/dist/helpers/find-variables.test.js +20 -0
- package/dist/helpers/find-variables.test.js.map +7 -0
- package/dist/helpers/http-methods.d.ts +1 -1
- package/dist/helpers/http-methods.d.ts.map +1 -1
- package/dist/helpers/http-methods.js +60 -66
- package/dist/helpers/http-methods.js.map +7 -0
- package/dist/helpers/http-status-codes.js +319 -317
- package/dist/helpers/http-status-codes.js.map +7 -0
- package/dist/helpers/index.d.ts +27 -27
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +73 -27
- package/dist/helpers/index.js.map +7 -0
- package/dist/helpers/is-defined.js +5 -14
- package/dist/helpers/is-defined.js.map +7 -0
- package/dist/helpers/is-defined.test.js +37 -0
- package/dist/helpers/is-defined.test.js.map +7 -0
- package/dist/helpers/is-local-url.js +11 -16
- package/dist/helpers/is-local-url.js.map +7 -0
- package/dist/helpers/is-local-url.test.js +40 -0
- package/dist/helpers/is-local-url.test.js.map +7 -0
- package/dist/helpers/is-valid-url.js +9 -18
- package/dist/helpers/is-valid-url.js.map +7 -0
- package/dist/helpers/is-valid-url.test.js +17 -0
- package/dist/helpers/is-valid-url.test.js.map +7 -0
- package/dist/helpers/iterate-title.js +11 -15
- package/dist/helpers/iterate-title.js.map +7 -0
- package/dist/helpers/json2xml.js +40 -47
- package/dist/helpers/json2xml.js.map +7 -0
- package/dist/helpers/json2xml.test.js +19 -0
- package/dist/helpers/json2xml.test.js.map +7 -0
- package/dist/helpers/local-storage.js +13 -15
- package/dist/helpers/local-storage.js.map +7 -0
- package/dist/helpers/make-url-absolute.js +11 -17
- package/dist/helpers/make-url-absolute.js.map +7 -0
- package/dist/helpers/make-url-absolute.test.js +61 -0
- package/dist/helpers/make-url-absolute.test.js.map +7 -0
- package/dist/helpers/merge-urls.js +50 -75
- package/dist/helpers/merge-urls.js.map +7 -0
- package/dist/helpers/merge-urls.test.js +339 -0
- package/dist/helpers/merge-urls.test.js.map +7 -0
- package/dist/helpers/normalize-mime-type-object.js +21 -31
- package/dist/helpers/normalize-mime-type-object.js.map +7 -0
- package/dist/helpers/normalize-mime-type-object.test.js +53 -0
- package/dist/helpers/normalize-mime-type-object.test.js.map +7 -0
- package/dist/helpers/normalize-mime-type.js +8 -18
- package/dist/helpers/normalize-mime-type.js.map +7 -0
- package/dist/helpers/normalize-mime-type.test.js +33 -0
- package/dist/helpers/normalize-mime-type.test.js.map +7 -0
- package/dist/helpers/object.js +12 -18
- package/dist/helpers/object.js.map +7 -0
- package/dist/helpers/omit-undefined-values.js +17 -19
- package/dist/helpers/omit-undefined-values.js.map +7 -0
- package/dist/helpers/omit-undefined-values.test.js +89 -0
- package/dist/helpers/omit-undefined-values.test.js.map +7 -0
- package/dist/helpers/parse.js +71 -83
- package/dist/helpers/parse.js.map +7 -0
- package/dist/helpers/parse.test.js +45 -0
- package/dist/helpers/parse.test.js.map +7 -0
- package/dist/helpers/pretty-print-json.js +31 -35
- package/dist/helpers/pretty-print-json.js.map +7 -0
- package/dist/helpers/pretty-print-json.test.js +28 -0
- package/dist/helpers/pretty-print-json.test.js.map +7 -0
- package/dist/helpers/redirect-to-proxy.js +46 -83
- package/dist/helpers/redirect-to-proxy.js.map +7 -0
- package/dist/helpers/redirect-to-proxy.test.js +54 -0
- package/dist/helpers/redirect-to-proxy.test.js.map +7 -0
- package/dist/helpers/regex-helpers.js +11 -9
- package/dist/helpers/regex-helpers.js.map +7 -0
- package/dist/helpers/regex-helpers.test.js +154 -0
- package/dist/helpers/regex-helpers.test.js.map +7 -0
- package/dist/helpers/replace-variables.js +13 -16
- package/dist/helpers/replace-variables.js.map +7 -0
- package/dist/helpers/replace-variables.test.js +30 -0
- package/dist/helpers/replace-variables.test.js.map +7 -0
- package/dist/helpers/schema-model.js +15 -14
- package/dist/helpers/schema-model.js.map +7 -0
- package/dist/helpers/security/get-schemes.d.ts +1 -1
- package/dist/helpers/security/get-schemes.d.ts.map +1 -1
- package/dist/helpers/security/get-schemes.js +7 -9
- package/dist/helpers/security/get-schemes.js.map +7 -0
- package/dist/helpers/security/get-schemes.test.js +71 -0
- package/dist/helpers/security/get-schemes.test.js.map +7 -0
- package/dist/helpers/security/has-token.js +18 -19
- package/dist/helpers/security/has-token.js.map +7 -0
- package/dist/helpers/security/has-token.test.js +157 -0
- package/dist/helpers/security/has-token.test.js.map +7 -0
- package/dist/helpers/security/index.d.ts +2 -2
- package/dist/helpers/security/index.d.ts.map +1 -1
- package/dist/helpers/security/index.js +7 -2
- package/dist/helpers/security/index.js.map +7 -0
- package/dist/helpers/should-ignore-entity.d.ts +2 -2
- package/dist/helpers/should-ignore-entity.d.ts.map +1 -1
- package/dist/helpers/should-ignore-entity.js +5 -6
- package/dist/helpers/should-ignore-entity.js.map +7 -0
- package/dist/helpers/ssr-state.js +6 -6
- package/dist/helpers/ssr-state.js.map +7 -0
- package/dist/helpers/string.js +6 -18
- package/dist/helpers/string.js.map +7 -0
- package/dist/migrations/data-version.js +7 -17
- package/dist/migrations/data-version.js.map +7 -0
- package/dist/migrations/generate-types.js +56 -0
- package/dist/migrations/generate-types.js.map +7 -0
- package/dist/migrations/index.d.ts +3 -3
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +10 -3
- package/dist/migrations/index.js.map +7 -0
- package/dist/migrations/local-storage.d.ts +1 -1
- package/dist/migrations/local-storage.d.ts.map +1 -1
- package/dist/migrations/local-storage.js +27 -32
- package/dist/migrations/local-storage.js.map +7 -0
- package/dist/migrations/migrator.d.ts +1 -1
- package/dist/migrations/migrator.d.ts.map +1 -1
- package/dist/migrations/migrator.js +51 -58
- package/dist/migrations/migrator.js.map +7 -0
- package/dist/migrations/semver.js +23 -25
- package/dist/migrations/semver.js.map +7 -0
- package/dist/migrations/semver.test.js +21 -0
- package/dist/migrations/semver.test.js.map +7 -0
- package/dist/migrations/v-0.0.0/types.generated.js +1 -0
- package/dist/migrations/v-0.0.0/types.generated.js.map +7 -0
- package/dist/migrations/v-2.1.0/migration.d.ts +2 -2
- package/dist/migrations/v-2.1.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.1.0/migration.js +256 -273
- package/dist/migrations/v-2.1.0/migration.js.map +7 -0
- package/dist/migrations/v-2.1.0/types.generated.js +1 -0
- package/dist/migrations/v-2.1.0/types.generated.js.map +7 -0
- package/dist/migrations/v-2.2.0/migration.d.ts +2 -2
- package/dist/migrations/v-2.2.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.2.0/migration.js +95 -100
- package/dist/migrations/v-2.2.0/migration.js.map +7 -0
- package/dist/migrations/v-2.2.0/types.generated.js +1 -0
- package/dist/migrations/v-2.2.0/types.generated.js.map +7 -0
- package/dist/migrations/v-2.3.0/migration.d.ts +2 -2
- package/dist/migrations/v-2.3.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.3.0/migration.js +47 -46
- package/dist/migrations/v-2.3.0/migration.js.map +7 -0
- package/dist/migrations/v-2.3.0/types.generated.js +1 -0
- package/dist/migrations/v-2.3.0/types.generated.js.map +7 -0
- package/dist/migrations/v-2.4.0/migration.d.ts +2 -2
- package/dist/migrations/v-2.4.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.4.0/migration.js +24 -26
- package/dist/migrations/v-2.4.0/migration.js.map +7 -0
- package/dist/migrations/v-2.4.0/migration.test.js +90 -0
- package/dist/migrations/v-2.4.0/migration.test.js.map +7 -0
- package/dist/migrations/v-2.4.0/types.generated.js +1 -0
- package/dist/migrations/v-2.4.0/types.generated.js.map +7 -0
- package/dist/migrations/v-2.5.0/migration.d.ts +2 -2
- package/dist/migrations/v-2.5.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.5.0/migration.js +135 -119
- package/dist/migrations/v-2.5.0/migration.js.map +7 -0
- package/dist/migrations/v-2.5.0/migration.test.js +108 -0
- package/dist/migrations/v-2.5.0/migration.test.js.map +7 -0
- package/dist/migrations/v-2.5.0/types.generated.d.ts +8 -8
- package/dist/migrations/v-2.5.0/types.generated.d.ts.map +1 -1
- package/dist/migrations/v-2.5.0/types.generated.js +1 -0
- package/dist/migrations/v-2.5.0/types.generated.js.map +7 -0
- package/dist/spec-getters/get-example-from-schema.js +206 -268
- package/dist/spec-getters/get-example-from-schema.js.map +7 -0
- package/dist/spec-getters/get-example-from-schema.test.js +1092 -0
- package/dist/spec-getters/get-example-from-schema.test.js.map +7 -0
- package/dist/spec-getters/get-parameters-from-operation.js +22 -42
- package/dist/spec-getters/get-parameters-from-operation.js.map +7 -0
- package/dist/spec-getters/get-parameters-from-operation.test.js +178 -0
- package/dist/spec-getters/get-parameters-from-operation.test.js.map +7 -0
- package/dist/spec-getters/get-request-body-from-operation.js +110 -162
- package/dist/spec-getters/get-request-body-from-operation.js.map +7 -0
- package/dist/spec-getters/get-request-body-from-operation.test.js +289 -0
- package/dist/spec-getters/get-request-body-from-operation.test.js.map +7 -0
- package/dist/spec-getters/get-server-variable-examples.d.ts +1 -1
- package/dist/spec-getters/get-server-variable-examples.d.ts.map +1 -1
- package/dist/spec-getters/get-server-variable-examples.js +12 -11
- package/dist/spec-getters/get-server-variable-examples.js.map +7 -0
- package/dist/spec-getters/index.d.ts +4 -4
- package/dist/spec-getters/index.d.ts.map +1 -1
- package/dist/spec-getters/index.js +11 -4
- package/dist/spec-getters/index.js.map +7 -0
- package/dist/transforms/import-spec.d.ts +6 -6
- package/dist/transforms/import-spec.d.ts.map +1 -1
- package/dist/transforms/import-spec.js +313 -425
- package/dist/transforms/import-spec.js.map +7 -0
- package/dist/transforms/import-spec.test.js +1124 -0
- package/dist/transforms/import-spec.test.js.map +7 -0
- package/dist/transforms/index.d.ts +1 -1
- package/dist/transforms/index.d.ts.map +1 -1
- package/dist/transforms/index.js +13 -1
- package/dist/transforms/index.js.map +7 -0
- package/package.json +10 -11
|
@@ -1,363 +1,348 @@
|
|
|
1
|
-
import { schemaModel } from
|
|
2
|
-
import { getServerVariableExamples } from
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
default: z.any().optional(),
|
|
39
|
-
nullable: z.boolean().optional(),
|
|
40
|
-
})
|
|
41
|
-
// set nullable: to true if type is ['string', 'null']
|
|
42
|
-
.transform((_data) => {
|
|
43
|
-
const data = { ..._data };
|
|
44
|
-
// type: ['string', 'null'] -> nullable: true
|
|
45
|
-
if (Array.isArray(data.type) && data.type.includes('null')) {
|
|
46
|
-
data.nullable = true;
|
|
47
|
-
}
|
|
48
|
-
// Hey, if it's just one value and 'null', we can make it a string and ditch the 'null'.
|
|
49
|
-
if (Array.isArray(data.type) && data.type.length === 2 && data.type.includes('null')) {
|
|
50
|
-
data.type = data.type.find((item) => item !== 'null');
|
|
51
|
-
}
|
|
52
|
-
return data;
|
|
1
|
+
import { schemaModel } from "../../helpers/schema-model.js";
|
|
2
|
+
import { getServerVariableExamples } from "../../spec-getters/get-server-variable-examples.js";
|
|
3
|
+
import { keysOf } from "@scalar/object-utils/arrays";
|
|
4
|
+
import { nanoidSchema } from "@scalar/types/utils";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { isDefined } from "../../helpers/is-defined.js";
|
|
7
|
+
import { getObjectKeys } from "../../helpers/object.js";
|
|
8
|
+
import { getRequestBodyFromOperation } from "../../spec-getters/get-request-body-from-operation.js";
|
|
9
|
+
const requestExampleParametersSchema = z.object({
|
|
10
|
+
key: z.string().default(""),
|
|
11
|
+
value: z.coerce.string().default(""),
|
|
12
|
+
enabled: z.boolean().default(true),
|
|
13
|
+
file: z.any().optional(),
|
|
14
|
+
description: z.string().optional(),
|
|
15
|
+
required: z.boolean().optional(),
|
|
16
|
+
enum: z.array(z.string()).optional(),
|
|
17
|
+
examples: z.array(z.any()).optional(),
|
|
18
|
+
type: z.union([
|
|
19
|
+
// 'string'
|
|
20
|
+
z.string(),
|
|
21
|
+
// ['string', 'null']
|
|
22
|
+
z.array(z.string())
|
|
23
|
+
]).optional(),
|
|
24
|
+
format: z.string().optional(),
|
|
25
|
+
minimum: z.number().optional(),
|
|
26
|
+
maximum: z.number().optional(),
|
|
27
|
+
default: z.any().optional(),
|
|
28
|
+
nullable: z.boolean().optional()
|
|
29
|
+
}).transform((_data) => {
|
|
30
|
+
const data = { ..._data };
|
|
31
|
+
if (Array.isArray(data.type) && data.type.includes("null")) {
|
|
32
|
+
data.nullable = true;
|
|
33
|
+
}
|
|
34
|
+
if (Array.isArray(data.type) && data.type.length === 2 && data.type.includes("null")) {
|
|
35
|
+
data.type = data.type.find((item) => item !== "null");
|
|
36
|
+
}
|
|
37
|
+
return data;
|
|
53
38
|
});
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
z.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
type: z.literal('file'),
|
|
72
|
-
file: xScalarFileValueSchema,
|
|
73
|
-
}),
|
|
39
|
+
const parameterArrayToObject = (params) => params.reduce((map, param) => {
|
|
40
|
+
map[param.key] = param.value;
|
|
41
|
+
return map;
|
|
42
|
+
}, {});
|
|
43
|
+
const xScalarFileValueSchema = z.object({
|
|
44
|
+
url: z.string(),
|
|
45
|
+
base64: z.string().optional()
|
|
46
|
+
}).nullable();
|
|
47
|
+
const xScalarFormDataValue = z.union([
|
|
48
|
+
z.object({
|
|
49
|
+
type: z.literal("string"),
|
|
50
|
+
value: z.string()
|
|
51
|
+
}),
|
|
52
|
+
z.object({
|
|
53
|
+
type: z.literal("file"),
|
|
54
|
+
file: xScalarFileValueSchema
|
|
55
|
+
})
|
|
74
56
|
]);
|
|
75
|
-
|
|
76
|
-
// Example Body
|
|
77
|
-
/**
|
|
78
|
-
* Possible encodings for example request bodies when using text formats
|
|
79
|
-
*
|
|
80
|
-
* TODO: This list may not be comprehensive enough
|
|
81
|
-
*/
|
|
82
|
-
const exampleRequestBodyEncoding = ['json', 'text', 'html', 'javascript', 'xml', 'yaml', 'edn'];
|
|
57
|
+
const exampleRequestBodyEncoding = ["json", "text", "html", "javascript", "xml", "yaml", "edn"];
|
|
83
58
|
const exampleBodyMime = [
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
59
|
+
"application/json",
|
|
60
|
+
"text/plain",
|
|
61
|
+
"text/html",
|
|
62
|
+
"application/javascript",
|
|
63
|
+
"application/xml",
|
|
64
|
+
"application/yaml",
|
|
65
|
+
"application/edn",
|
|
66
|
+
"application/octet-stream",
|
|
67
|
+
"application/x-www-form-urlencoded",
|
|
68
|
+
"multipart/form-data",
|
|
69
|
+
/** Used for direct files */
|
|
70
|
+
"binary"
|
|
96
71
|
];
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
72
|
+
const contentMapping = {
|
|
73
|
+
json: "application/json",
|
|
74
|
+
text: "text/plain",
|
|
75
|
+
html: "text/html",
|
|
76
|
+
javascript: "application/javascript",
|
|
77
|
+
xml: "application/xml",
|
|
78
|
+
yaml: "application/yaml",
|
|
79
|
+
edn: "application/edn"
|
|
80
|
+
};
|
|
102
81
|
const exampleRequestBodySchema = z.object({
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
})
|
|
115
|
-
.optional(),
|
|
116
|
-
binary: z.instanceof(Blob).optional(),
|
|
117
|
-
activeBody: z.union([z.literal('raw'), z.literal('formData'), z.literal('binary')]).default('raw'),
|
|
82
|
+
raw: z.object({
|
|
83
|
+
encoding: z.enum(exampleRequestBodyEncoding),
|
|
84
|
+
value: z.string().default(""),
|
|
85
|
+
mimeType: z.string().optional()
|
|
86
|
+
}).optional(),
|
|
87
|
+
formData: z.object({
|
|
88
|
+
encoding: z.union([z.literal("form-data"), z.literal("urlencoded")]).default("form-data"),
|
|
89
|
+
value: requestExampleParametersSchema.array().default([])
|
|
90
|
+
}).optional(),
|
|
91
|
+
binary: z.instanceof(Blob).optional(),
|
|
92
|
+
activeBody: z.union([z.literal("raw"), z.literal("formData"), z.literal("binary")]).default("raw")
|
|
118
93
|
});
|
|
119
|
-
/** Schema for the OAS serialization of request example bodies */
|
|
120
94
|
const xScalarExampleBodySchema = z.object({
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
95
|
+
encoding: z.enum(exampleBodyMime),
|
|
96
|
+
/**
|
|
97
|
+
* Body content as an object with a separately specified encoding or a simple pre-encoded string value
|
|
98
|
+
*
|
|
99
|
+
* Ideally we would convert any objects into the proper encoding on import
|
|
100
|
+
*/
|
|
101
|
+
content: z.union([z.record(z.string(), z.any()), z.string()]),
|
|
102
|
+
/** When the encoding is `binary` this will be used to link to the file */
|
|
103
|
+
file: xScalarFileValueSchema.optional()
|
|
130
104
|
});
|
|
131
|
-
// ---------------------------------------------------------------------------
|
|
132
|
-
// Example Schema
|
|
133
105
|
const requestExampleSchema = z.object({
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
.default({}),
|
|
148
|
-
/** TODO: Should this be deprecated? */
|
|
149
|
-
serverVariables: z.record(z.string(), z.array(z.string())).optional(),
|
|
106
|
+
uid: nanoidSchema.brand(),
|
|
107
|
+
type: z.literal("requestExample").optional().default("requestExample"),
|
|
108
|
+
requestUid: z.string().brand().optional(),
|
|
109
|
+
name: z.string().optional().default("Name"),
|
|
110
|
+
body: exampleRequestBodySchema.optional().default({}),
|
|
111
|
+
parameters: z.object({
|
|
112
|
+
path: requestExampleParametersSchema.array().default([]),
|
|
113
|
+
query: requestExampleParametersSchema.array().default([]),
|
|
114
|
+
headers: requestExampleParametersSchema.array().default([{ key: "Accept", value: "*/*", enabled: true }]),
|
|
115
|
+
cookies: requestExampleParametersSchema.array().default([])
|
|
116
|
+
}).optional().default({}),
|
|
117
|
+
/** TODO: Should this be deprecated? */
|
|
118
|
+
serverVariables: z.record(z.string(), z.array(z.string())).optional()
|
|
150
119
|
});
|
|
151
|
-
/** For OAS serialization we just store the simple key/value pairs */
|
|
152
120
|
const xScalarExampleParameterSchema = z.record(z.string(), z.string()).optional();
|
|
153
|
-
/** Schema for the OAS serialization of request examples */
|
|
154
121
|
const xScalarExampleSchema = z.object({
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
122
|
+
/** TODO: Should this be required? */
|
|
123
|
+
name: z.string().optional(),
|
|
124
|
+
body: xScalarExampleBodySchema.optional(),
|
|
125
|
+
parameters: z.object({
|
|
126
|
+
path: xScalarExampleParameterSchema,
|
|
127
|
+
query: xScalarExampleParameterSchema,
|
|
128
|
+
headers: xScalarExampleParameterSchema,
|
|
129
|
+
cookies: xScalarExampleParameterSchema
|
|
130
|
+
})
|
|
164
131
|
});
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
132
|
+
function convertExampleToXScalar(example) {
|
|
133
|
+
const active = example.body?.activeBody;
|
|
134
|
+
const xScalarBody = {
|
|
135
|
+
encoding: "text/plain",
|
|
136
|
+
content: ""
|
|
137
|
+
};
|
|
138
|
+
if (example.body?.activeBody === "binary") {
|
|
139
|
+
xScalarBody.encoding = "binary";
|
|
140
|
+
xScalarBody.file = null;
|
|
141
|
+
}
|
|
142
|
+
if (active === "formData" && example.body?.[active]) {
|
|
143
|
+
const body = example.body[active];
|
|
144
|
+
xScalarBody.encoding = body.encoding === "form-data" ? "multipart/form-data" : "application/x-www-form-urlencoded";
|
|
145
|
+
xScalarBody.content = body.value.reduce((map, param) => {
|
|
146
|
+
map[param.key] = param.file ? {
|
|
147
|
+
type: "file",
|
|
148
|
+
file: null
|
|
149
|
+
} : {
|
|
150
|
+
type: "string",
|
|
151
|
+
value: param.value
|
|
152
|
+
};
|
|
153
|
+
return map;
|
|
154
|
+
}, {});
|
|
155
|
+
}
|
|
156
|
+
if (example.body?.activeBody === "raw") {
|
|
157
|
+
xScalarBody.encoding = contentMapping[example.body.raw?.encoding ?? "text"] ?? "text/plain";
|
|
158
|
+
xScalarBody.content = example.body.raw?.value ?? "";
|
|
159
|
+
}
|
|
160
|
+
const parameters = {};
|
|
161
|
+
keysOf(example.parameters ?? {}).forEach((key) => {
|
|
162
|
+
if (example.parameters?.[key].length) {
|
|
163
|
+
parameters[key] = parameterArrayToObject(example.parameters[key]);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
return xScalarExampleSchema.parse({
|
|
167
|
+
/** Only add the body if we have content or the body should be a file */
|
|
168
|
+
body: xScalarBody.content || xScalarBody.encoding === "binary" ? xScalarBody : void 0,
|
|
169
|
+
parameters
|
|
170
|
+
});
|
|
171
|
+
}
|
|
168
172
|
function createParamInstance(param) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return example.externalValue;
|
|
176
|
-
}
|
|
177
|
-
// returns the value if it exists and is defined
|
|
178
|
-
// e.g. { examples: { foo: { value: 'bar' } } } would return ['bar']
|
|
179
|
-
return example.value;
|
|
180
|
-
});
|
|
181
|
-
// returns the first example as selected value along other examples
|
|
182
|
-
return { value: exampleValues[0], examples: exampleValues };
|
|
183
|
-
}
|
|
184
|
-
// param example e.g. { example: 'foo' }
|
|
185
|
-
if (isDefined(param.example)) {
|
|
186
|
-
return { value: param.example };
|
|
187
|
-
}
|
|
188
|
-
// param examples e.g. { examples: ['foo', 'bar'] }
|
|
189
|
-
if (Array.isArray(param.examples) && param.examples.length > 0) {
|
|
190
|
-
return { value: param.examples[0] };
|
|
173
|
+
const schema = param.schema;
|
|
174
|
+
const firstExample = (() => {
|
|
175
|
+
if (param.examples && !Array.isArray(param.examples) && getObjectKeys(param.examples).length > 0) {
|
|
176
|
+
const exampleValues = Object.entries(param.examples).map(([_, example2]) => {
|
|
177
|
+
if (example2.externalValue) {
|
|
178
|
+
return example2.externalValue;
|
|
191
179
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
return { value: content.example };
|
|
222
|
-
}
|
|
180
|
+
return example2.value;
|
|
181
|
+
});
|
|
182
|
+
return { value: exampleValues[0], examples: exampleValues };
|
|
183
|
+
}
|
|
184
|
+
if (isDefined(param.example)) {
|
|
185
|
+
return { value: param.example };
|
|
186
|
+
}
|
|
187
|
+
if (Array.isArray(param.examples) && param.examples.length > 0) {
|
|
188
|
+
return { value: param.examples[0] };
|
|
189
|
+
}
|
|
190
|
+
if (isDefined(schema?.example)) {
|
|
191
|
+
return { value: schema.example };
|
|
192
|
+
}
|
|
193
|
+
if (Array.isArray(schema?.examples) && schema.examples.length > 0) {
|
|
194
|
+
if (schema?.type === "boolean") {
|
|
195
|
+
return { value: schema.default ?? false };
|
|
196
|
+
}
|
|
197
|
+
return { value: schema.examples[0] };
|
|
198
|
+
}
|
|
199
|
+
if (param.content) {
|
|
200
|
+
const firstContentType = getObjectKeys(param.content)[0];
|
|
201
|
+
if (firstContentType) {
|
|
202
|
+
const content = param.content[firstContentType];
|
|
203
|
+
if (content?.examples) {
|
|
204
|
+
const firstExampleKey = Object.keys(content.examples)[0];
|
|
205
|
+
if (firstExampleKey) {
|
|
206
|
+
const example2 = content.examples[firstExampleKey];
|
|
207
|
+
if (isDefined(example2?.value)) {
|
|
208
|
+
return { value: example2.value };
|
|
223
209
|
}
|
|
210
|
+
}
|
|
224
211
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* TODO:
|
|
229
|
-
* - Need better value defaulting here
|
|
230
|
-
* - Need to handle non-string parameters much better
|
|
231
|
-
* - Need to handle unions/array values for schema
|
|
232
|
-
*/
|
|
233
|
-
const value = String(firstExample?.value ?? schema?.default ?? '');
|
|
234
|
-
// Handle non-string enums and enums within items for array types
|
|
235
|
-
const parseEnum = (() => {
|
|
236
|
-
if (schema?.enum && schema?.type !== 'string') {
|
|
237
|
-
return schema.enum?.map(String);
|
|
238
|
-
}
|
|
239
|
-
if (schema?.items?.enum && schema?.type === 'array') {
|
|
240
|
-
return schema.items.enum.map(String);
|
|
212
|
+
if (isDefined(content?.example)) {
|
|
213
|
+
return { value: content.example };
|
|
241
214
|
}
|
|
242
|
-
|
|
243
|
-
})();
|
|
244
|
-
// Handle parameter examples
|
|
245
|
-
const examples = firstExample?.examples ||
|
|
246
|
-
(schema?.examples && schema?.type !== 'string' ? schema.examples?.map(String) : schema?.examples);
|
|
247
|
-
// safe parse the example
|
|
248
|
-
const example = schemaModel({
|
|
249
|
-
...schema,
|
|
250
|
-
key: param.name,
|
|
251
|
-
value,
|
|
252
|
-
description: param.description,
|
|
253
|
-
required: param.required,
|
|
254
|
-
/** Initialized all required properties to enabled */
|
|
255
|
-
enabled: !!param.required,
|
|
256
|
-
enum: parseEnum,
|
|
257
|
-
examples,
|
|
258
|
-
}, requestExampleParametersSchema, false);
|
|
259
|
-
if (!example) {
|
|
260
|
-
console.warn(`Example at ${param.name} is invalid.`);
|
|
261
|
-
return requestExampleParametersSchema.parse({});
|
|
215
|
+
}
|
|
262
216
|
}
|
|
263
|
-
return
|
|
217
|
+
return null;
|
|
218
|
+
})();
|
|
219
|
+
const value = String(firstExample?.value ?? schema?.default ?? "");
|
|
220
|
+
const parseEnum = (() => {
|
|
221
|
+
if (schema?.enum && schema?.type !== "string") {
|
|
222
|
+
return schema.enum?.map(String);
|
|
223
|
+
}
|
|
224
|
+
if (schema?.items?.enum && schema?.type === "array") {
|
|
225
|
+
return schema.items.enum.map(String);
|
|
226
|
+
}
|
|
227
|
+
return schema?.enum;
|
|
228
|
+
})();
|
|
229
|
+
const examples = firstExample?.examples || (schema?.examples && schema?.type !== "string" ? schema.examples?.map(String) : schema?.examples);
|
|
230
|
+
const example = schemaModel(
|
|
231
|
+
{
|
|
232
|
+
...schema,
|
|
233
|
+
key: param.name,
|
|
234
|
+
value,
|
|
235
|
+
description: param.description,
|
|
236
|
+
required: param.required,
|
|
237
|
+
/** Initialized all required properties to enabled */
|
|
238
|
+
enabled: !!param.required,
|
|
239
|
+
enum: parseEnum,
|
|
240
|
+
examples
|
|
241
|
+
},
|
|
242
|
+
requestExampleParametersSchema,
|
|
243
|
+
false
|
|
244
|
+
);
|
|
245
|
+
if (!example) {
|
|
246
|
+
console.warn(`Example at ${param.name} is invalid.`);
|
|
247
|
+
return requestExampleParametersSchema.parse({});
|
|
248
|
+
}
|
|
249
|
+
return example;
|
|
264
250
|
}
|
|
265
|
-
/**
|
|
266
|
-
* Create new request example from a request
|
|
267
|
-
* Iterates the name of the example if provided
|
|
268
|
-
*/
|
|
269
251
|
function createExampleFromRequest(request, name, server) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
252
|
+
const parameters = {
|
|
253
|
+
path: [],
|
|
254
|
+
query: [],
|
|
255
|
+
cookie: [],
|
|
256
|
+
// deprecated TODO: add zod transform to remove
|
|
257
|
+
header: [],
|
|
258
|
+
headers: [{ key: "Accept", value: "*/*", enabled: true }]
|
|
259
|
+
};
|
|
260
|
+
request.parameters?.forEach((p) => parameters[p.in].push(createParamInstance(p)));
|
|
261
|
+
if (parameters.header.length > 0) {
|
|
262
|
+
parameters.headers = parameters.header;
|
|
263
|
+
parameters.header = [];
|
|
264
|
+
}
|
|
265
|
+
const contentTypeHeader = parameters.headers.find((h) => h.key.toLowerCase() === "content-type");
|
|
266
|
+
const body = {
|
|
267
|
+
activeBody: "raw"
|
|
268
|
+
};
|
|
269
|
+
if (request.requestBody || contentTypeHeader?.value) {
|
|
270
|
+
const requestBody = getRequestBodyFromOperation({
|
|
271
|
+
path: request.path,
|
|
272
|
+
information: {
|
|
273
|
+
requestBody: request.requestBody
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
const contentType = request.requestBody ? requestBody?.mimeType : contentTypeHeader?.value;
|
|
277
|
+
if (contentType?.includes("/json") || contentType?.endsWith("+json")) {
|
|
278
|
+
body.activeBody = "raw";
|
|
279
|
+
body.raw = {
|
|
280
|
+
encoding: "json",
|
|
281
|
+
mimeType: contentType,
|
|
282
|
+
value: requestBody?.text ?? JSON.stringify({})
|
|
283
|
+
};
|
|
286
284
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
mimeType: contentType,
|
|
309
|
-
value: requestBody?.text ?? JSON.stringify({}),
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
|
-
if (contentType === 'application/xml') {
|
|
313
|
-
body.activeBody = 'raw';
|
|
314
|
-
body.raw = {
|
|
315
|
-
encoding: 'xml',
|
|
316
|
-
value: requestBody?.text ?? '',
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* TODO: Are we loading example files from somewhere based on the spec?
|
|
321
|
-
* How are we handling the body values
|
|
322
|
-
*/
|
|
323
|
-
if (contentType === 'application/octet-stream') {
|
|
324
|
-
body.activeBody = 'binary';
|
|
325
|
-
body.binary = undefined;
|
|
326
|
-
}
|
|
327
|
-
if (contentType === 'application/x-www-form-urlencoded' || contentType === 'multipart/form-data') {
|
|
328
|
-
body.activeBody = 'formData';
|
|
329
|
-
body.formData = {
|
|
330
|
-
encoding: contentType === 'application/x-www-form-urlencoded' ? 'urlencoded' : 'form-data',
|
|
331
|
-
value: (requestBody?.params || []).map((param) => ({
|
|
332
|
-
key: param.name,
|
|
333
|
-
value: param.value || '',
|
|
334
|
-
enabled: true,
|
|
335
|
-
})),
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
// Add the content-type header if it doesn't exist
|
|
339
|
-
if (requestBody?.mimeType && !contentTypeHeader) {
|
|
340
|
-
parameters.headers.push({
|
|
341
|
-
key: 'Content-Type',
|
|
342
|
-
value: requestBody.mimeType,
|
|
343
|
-
enabled: true,
|
|
344
|
-
});
|
|
345
|
-
}
|
|
285
|
+
if (contentType === "application/xml") {
|
|
286
|
+
body.activeBody = "raw";
|
|
287
|
+
body.raw = {
|
|
288
|
+
encoding: "xml",
|
|
289
|
+
value: requestBody?.text ?? ""
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
if (contentType === "application/octet-stream") {
|
|
293
|
+
body.activeBody = "binary";
|
|
294
|
+
body.binary = void 0;
|
|
295
|
+
}
|
|
296
|
+
if (contentType === "application/x-www-form-urlencoded" || contentType === "multipart/form-data") {
|
|
297
|
+
body.activeBody = "formData";
|
|
298
|
+
body.formData = {
|
|
299
|
+
encoding: contentType === "application/x-www-form-urlencoded" ? "urlencoded" : "form-data",
|
|
300
|
+
value: (requestBody?.params || []).map((param) => ({
|
|
301
|
+
key: param.name,
|
|
302
|
+
value: param.value || "",
|
|
303
|
+
enabled: true
|
|
304
|
+
}))
|
|
305
|
+
};
|
|
346
306
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
body,
|
|
354
|
-
serverVariables,
|
|
355
|
-
}, requestExampleSchema, false);
|
|
356
|
-
if (!example) {
|
|
357
|
-
console.warn(`Example at ${request.uid} is invalid.`);
|
|
358
|
-
return requestExampleSchema.parse({});
|
|
307
|
+
if (requestBody?.mimeType && !contentTypeHeader) {
|
|
308
|
+
parameters.headers.push({
|
|
309
|
+
key: "Content-Type",
|
|
310
|
+
value: requestBody.mimeType,
|
|
311
|
+
enabled: true
|
|
312
|
+
});
|
|
359
313
|
}
|
|
360
|
-
|
|
314
|
+
}
|
|
315
|
+
const serverVariables = server ? getServerVariableExamples(server) : {};
|
|
316
|
+
const example = schemaModel(
|
|
317
|
+
{
|
|
318
|
+
requestUid: request.uid,
|
|
319
|
+
parameters,
|
|
320
|
+
name,
|
|
321
|
+
body,
|
|
322
|
+
serverVariables
|
|
323
|
+
},
|
|
324
|
+
requestExampleSchema,
|
|
325
|
+
false
|
|
326
|
+
);
|
|
327
|
+
if (!example) {
|
|
328
|
+
console.warn(`Example at ${request.uid} is invalid.`);
|
|
329
|
+
return requestExampleSchema.parse({});
|
|
330
|
+
}
|
|
331
|
+
return example;
|
|
361
332
|
}
|
|
362
|
-
|
|
363
|
-
|
|
333
|
+
export {
|
|
334
|
+
convertExampleToXScalar,
|
|
335
|
+
createExampleFromRequest,
|
|
336
|
+
createParamInstance,
|
|
337
|
+
exampleBodyMime,
|
|
338
|
+
exampleRequestBodyEncoding,
|
|
339
|
+
exampleRequestBodySchema,
|
|
340
|
+
parameterArrayToObject,
|
|
341
|
+
requestExampleParametersSchema,
|
|
342
|
+
requestExampleSchema,
|
|
343
|
+
xScalarExampleBodySchema,
|
|
344
|
+
xScalarExampleSchema,
|
|
345
|
+
xScalarFileValueSchema,
|
|
346
|
+
xScalarFormDataValue
|
|
347
|
+
};
|
|
348
|
+
//# sourceMappingURL=request-examples.js.map
|