@scalar/oas-utils 0.2.106 → 0.2.108
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 +30 -0
- package/dist/entities/cookie/cookie.d.ts +2 -2
- package/dist/entities/cookie/cookie.js +1 -1
- package/dist/entities/environment/environment.d.ts +2 -2
- package/dist/entities/environment/environment.js +1 -1
- package/dist/entities/shared/utility.d.ts +13 -1
- package/dist/entities/shared/utility.d.ts.map +1 -1
- package/dist/entities/shared/utility.js +4 -1
- package/dist/entities/spec/collection.d.ts +199 -155
- package/dist/entities/spec/collection.d.ts.map +1 -1
- package/dist/entities/spec/collection.js +15 -17
- package/dist/entities/spec/index.js +1 -1
- package/dist/entities/spec/operation.d.ts +34 -28
- package/dist/entities/spec/operation.d.ts.map +1 -1
- package/dist/entities/spec/parameters.d.ts +4 -4
- package/dist/entities/spec/request-examples.d.ts +5 -5
- package/dist/entities/spec/request-examples.d.ts.map +1 -1
- package/dist/entities/spec/request-examples.js +37 -71
- package/dist/entities/spec/requests.d.ts +54 -42
- package/dist/entities/spec/requests.d.ts.map +1 -1
- package/dist/entities/spec/requests.js +6 -18
- package/dist/entities/spec/security.d.ts +22 -22
- package/dist/entities/spec/security.d.ts.map +1 -1
- package/dist/entities/spec/security.js +7 -22
- package/dist/entities/spec/server.d.ts +2 -2
- package/dist/entities/spec/server.d.ts.map +1 -1
- package/dist/entities/spec/server.js +3 -5
- package/dist/entities/spec/spec-objects.d.ts +150 -78
- package/dist/entities/spec/spec-objects.d.ts.map +1 -1
- package/dist/entities/spec/spec-objects.js +68 -45
- package/dist/entities/spec/x-scalar-secrets.d.ts +4 -4
- package/dist/entities/spec/x-scalar-secrets.d.ts.map +1 -1
- package/dist/entities/workspace/workspace.d.ts +7 -7
- package/dist/entities/workspace/workspace.d.ts.map +1 -1
- package/dist/entities/workspace/workspace.js +5 -5
- package/dist/helpers/fetchSpecFromUrl.d.ts.map +1 -1
- package/dist/helpers/fetchSpecFromUrl.js +1 -1
- package/dist/helpers/fetchWithProxyFallback.d.ts.map +1 -1
- package/dist/helpers/findVariables.d.ts.map +1 -1
- package/dist/helpers/findVariables.js +1 -1
- package/dist/helpers/httpMethods.d.ts.map +1 -1
- package/dist/helpers/is-defined.d.ts.map +1 -1
- package/dist/helpers/iterateTitle.d.ts.map +1 -1
- package/dist/helpers/json2xml.d.ts.map +1 -1
- package/dist/helpers/json2xml.js +3 -7
- package/dist/helpers/makeUrlAbsolute.d.ts.map +1 -1
- package/dist/helpers/makeUrlAbsolute.js +1 -4
- package/dist/helpers/merge-urls.d.ts.map +1 -1
- package/dist/helpers/normalizeMimeTypeObject.d.ts +1 -0
- package/dist/helpers/normalizeMimeTypeObject.d.ts.map +1 -1
- package/dist/helpers/object.d.ts.map +1 -1
- package/dist/helpers/parse.d.ts.map +1 -1
- package/dist/helpers/prettyPrintJson.d.ts.map +1 -1
- package/dist/helpers/replaceVariables.d.ts.map +1 -1
- package/dist/helpers/replaceVariables.js +1 -3
- package/dist/helpers/ssrState.d.ts.map +1 -1
- package/dist/helpers/ssrState.js +1 -3
- package/dist/migrations/local-storage.d.ts.map +1 -1
- package/dist/migrations/migrator.d.ts +1 -1
- package/dist/migrations/migrator.d.ts.map +1 -1
- package/dist/migrations/semver.d.ts.map +1 -1
- package/dist/migrations/semver.js +1 -3
- package/dist/migrations/v-0.0.0/types.generated.d.ts.map +1 -1
- package/dist/migrations/v-2.1.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.1.0/migration.js +1 -4
- package/dist/migrations/v-2.1.0/types.generated.d.ts.map +1 -1
- package/dist/migrations/v-2.2.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.2.0/migration.js +2 -4
- package/dist/migrations/v-2.2.0/types.generated.d.ts.map +1 -1
- package/dist/migrations/v-2.3.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.3.0/migration.js +3 -8
- package/dist/migrations/v-2.3.0/types.generated.d.ts.map +1 -1
- package/dist/migrations/v-2.4.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.4.0/types.generated.d.ts.map +1 -1
- package/dist/migrations/v-2.5.0/migration.d.ts +1 -1
- package/dist/migrations/v-2.5.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.5.0/migration.js +70 -3
- package/dist/migrations/v-2.5.0/types.generated.d.ts +17 -17
- package/dist/migrations/v-2.5.0/types.generated.d.ts.map +1 -1
- package/dist/spec-getters/getExampleFromSchema.d.ts.map +1 -1
- package/dist/spec-getters/getExampleFromSchema.js +8 -22
- package/dist/spec-getters/getParametersFromOperation.d.ts.map +1 -1
- package/dist/spec-getters/getParametersFromOperation.js +1 -4
- package/dist/spec-getters/getRequestBodyFromOperation.d.ts.map +1 -1
- package/dist/spec-getters/getRequestBodyFromOperation.js +4 -9
- package/dist/spec-getters/getServerVariableExamples.js +3 -1
- package/dist/transforms/import-spec.d.ts +2 -1
- package/dist/transforms/import-spec.d.ts.map +1 -1
- package/dist/transforms/import-spec.js +13 -35
- package/dist/transforms/index.d.ts +0 -1
- package/dist/transforms/index.d.ts.map +1 -1
- package/dist/transforms/index.js +0 -1
- package/package.json +7 -7
- package/dist/transforms/export-spec.d.ts +0 -17
- package/dist/transforms/export-spec.d.ts.map +0 -1
- package/dist/transforms/export-spec.js +0 -73
|
@@ -13,16 +13,14 @@ const oasCollectionSchema = z.object({
|
|
|
13
13
|
*/
|
|
14
14
|
'type': z.literal('collection').optional().default('collection'),
|
|
15
15
|
'openapi': z
|
|
16
|
-
.union([
|
|
17
|
-
z.string(),
|
|
18
|
-
z.literal('3.0.0'),
|
|
19
|
-
z.literal('3.1.0'),
|
|
20
|
-
z.literal('4.0.0'),
|
|
21
|
-
])
|
|
16
|
+
.union([z.string(), z.literal('3.0.0'), z.literal('3.1.0'), z.literal('4.0.0')])
|
|
22
17
|
.optional()
|
|
23
18
|
.default('3.1.0'),
|
|
24
19
|
'jsonSchemaDialect': z.string().optional(),
|
|
25
|
-
'info': oasInfoSchema.
|
|
20
|
+
'info': oasInfoSchema.catch({
|
|
21
|
+
title: 'API',
|
|
22
|
+
version: '1.0',
|
|
23
|
+
}),
|
|
26
24
|
/**
|
|
27
25
|
* A declaration of which security mechanisms can be used across the API. The list of
|
|
28
26
|
* values includes alternative security requirement objects that can be used. Only
|
|
@@ -49,21 +47,24 @@ const oasCollectionSchema = z.object({
|
|
|
49
47
|
// security
|
|
50
48
|
});
|
|
51
49
|
const extendedCollectionSchema = z.object({
|
|
52
|
-
uid: nanoidSchema,
|
|
50
|
+
uid: nanoidSchema.brand(),
|
|
53
51
|
/** A list of security schemes UIDs associated with the collection */
|
|
54
52
|
securitySchemes: z.string().array().default([]),
|
|
55
53
|
/** List of currently selected security scheme UIDs, these can be overridden per request */
|
|
56
54
|
selectedSecuritySchemeUids: selectedSecuritySchemeUidSchema,
|
|
57
55
|
/** The currently selected server */
|
|
58
|
-
selectedServerUid: z.string().
|
|
56
|
+
selectedServerUid: z.string().brand().optional(),
|
|
59
57
|
/** UIDs which refer to servers on the workspace base */
|
|
60
|
-
servers:
|
|
58
|
+
servers: z.string().brand().array().default([]),
|
|
61
59
|
/** Request UIDs associated with a collection */
|
|
62
|
-
requests:
|
|
60
|
+
requests: z.string().brand().array().default([]),
|
|
63
61
|
/** Tag UIDs associated with the collection */
|
|
64
|
-
tags:
|
|
62
|
+
tags: z.string().brand().array().default([]),
|
|
65
63
|
/** List of requests without tags and top level tag "folders" */
|
|
66
|
-
children:
|
|
64
|
+
children: z
|
|
65
|
+
.union([z.string().brand(), z.string().brand()])
|
|
66
|
+
.array()
|
|
67
|
+
.default([]),
|
|
67
68
|
/**
|
|
68
69
|
* A link to where this document is stored
|
|
69
70
|
*
|
|
@@ -84,10 +85,7 @@ const extendedCollectionSchema = z.object({
|
|
|
84
85
|
*
|
|
85
86
|
* @defaults to idle for all collections, doesn't mean that it can watch for changes
|
|
86
87
|
*/
|
|
87
|
-
watchModeStatus: z
|
|
88
|
-
.enum(['IDLE', 'WATCHING', 'ERROR'])
|
|
89
|
-
.optional()
|
|
90
|
-
.default('IDLE'),
|
|
88
|
+
watchModeStatus: z.enum(['IDLE', 'WATCHING', 'ERROR']).optional().default('IDLE'),
|
|
91
89
|
});
|
|
92
90
|
const collectionSchema = oasCollectionSchema.merge(extendedCollectionSchema);
|
|
93
91
|
|
|
@@ -2,7 +2,7 @@ export { collectionSchema, extendedCollectionSchema, oasCollectionSchema } from
|
|
|
2
2
|
export { oasServerSchema, oasServerVariableSchema, serverSchema } from './server.js';
|
|
3
3
|
export { oasRequestSchema, requestMethods, requestSchema } from './requests.js';
|
|
4
4
|
export { convertExampleToXScalar, createExampleFromRequest, createParamInstance, exampleBodyMime, exampleRequestBodyEncoding, exampleRequestBodySchema, parameterArrayToObject, requestExampleParametersSchema, requestExampleSchema, xScalarExampleBodySchema, xScalarExampleSchema, xScalarFileValueSchema, xScalarFormDataValue } from './request-examples.js';
|
|
5
|
-
export { oasContactSchema, oasExternalDocumentationSchema, oasInfoSchema, oasLicenseSchema, oasTagSchema, tagSchema, xScalarNestedSchema } from './spec-objects.js';
|
|
5
|
+
export { oasContactSchema, oasExternalDocumentationSchema, oasInfoSchema, oasLicenseSchema, oasTagSchema, omitUndefinedValues, tagSchema, xScalarNestedSchema } from './spec-objects.js';
|
|
6
6
|
export { oasParameterSchema, parameterStyleSchema, parameterTypeSchema } from './parameters.js';
|
|
7
7
|
export { oasSecurityRequirementSchema, oasSecuritySchemeSchema, pkceOptions, securityApiKeySchema, securityHttpSchema, securityOauthSchema, securityOpenIdSchema, securitySchemeApiKeyIn, securitySchemeSchema } from './security.js';
|
|
8
8
|
export { xScalarEnvVarSchema, xScalarEnvironmentSchema, xScalarEnvironmentsSchema } from './x-scalar-environments.js';
|
|
@@ -35,10 +35,10 @@ export declare const operationSchema: import("zod").ZodObject<import("zod").obje
|
|
|
35
35
|
}, "strip", import("zod").ZodTypeAny, {
|
|
36
36
|
required: boolean;
|
|
37
37
|
name: string;
|
|
38
|
-
in: "path" | "
|
|
38
|
+
in: "path" | "cookie" | "query" | "header";
|
|
39
39
|
deprecated: boolean;
|
|
40
|
-
description?: string | undefined;
|
|
41
40
|
example?: unknown;
|
|
41
|
+
description?: string | undefined;
|
|
42
42
|
schema?: unknown;
|
|
43
43
|
content?: unknown;
|
|
44
44
|
style?: "matrix" | "simple" | "form" | "label" | "spaceDelimited" | "pipeDelimited" | "deepObject" | undefined;
|
|
@@ -48,10 +48,10 @@ export declare const operationSchema: import("zod").ZodObject<import("zod").obje
|
|
|
48
48
|
}> | undefined;
|
|
49
49
|
}, {
|
|
50
50
|
name: string;
|
|
51
|
-
in: "path" | "
|
|
51
|
+
in: "path" | "cookie" | "query" | "header";
|
|
52
|
+
example?: unknown;
|
|
52
53
|
required?: boolean | undefined;
|
|
53
54
|
description?: string | undefined;
|
|
54
|
-
example?: unknown;
|
|
55
55
|
deprecated?: boolean | undefined;
|
|
56
56
|
schema?: unknown;
|
|
57
57
|
content?: unknown;
|
|
@@ -61,15 +61,21 @@ export declare const operationSchema: import("zod").ZodObject<import("zod").obje
|
|
|
61
61
|
summary?: string | undefined;
|
|
62
62
|
}> | undefined;
|
|
63
63
|
}>, "many">>;
|
|
64
|
-
externalDocs: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
65
|
-
description: import("zod").ZodOptional<import("zod").ZodString
|
|
66
|
-
url: import("zod").
|
|
64
|
+
externalDocs: import("zod").ZodOptional<import("zod").ZodEffects<import("zod").ZodObject<{
|
|
65
|
+
description: import("zod").ZodCatch<import("zod").ZodOptional<import("zod").ZodString>>;
|
|
66
|
+
url: import("zod").ZodString;
|
|
67
67
|
}, "strip", import("zod").ZodTypeAny, {
|
|
68
68
|
url: string;
|
|
69
69
|
description?: string | undefined;
|
|
70
70
|
}, {
|
|
71
|
+
url: string;
|
|
72
|
+
description?: unknown;
|
|
73
|
+
}>, {
|
|
74
|
+
url: string;
|
|
71
75
|
description?: string | undefined;
|
|
72
|
-
|
|
76
|
+
}, {
|
|
77
|
+
url: string;
|
|
78
|
+
description?: unknown;
|
|
73
79
|
}>>;
|
|
74
80
|
deprecated: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
75
81
|
responses: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
|
|
@@ -156,21 +162,21 @@ export declare const operationSchema: import("zod").ZodObject<import("zod").obje
|
|
|
156
162
|
'x-scalar-ignore': import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
157
163
|
}, "x-scalar-examples">, {
|
|
158
164
|
type: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodLiteral<"request">>>;
|
|
159
|
-
uid: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodString
|
|
165
|
+
uid: import("zod").ZodBranded<import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodString>>, "operation">;
|
|
160
166
|
path: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodString>>;
|
|
161
167
|
method: import("zod").ZodDefault<import("zod").ZodEnum<["connect", "delete", "get", "head", "options", "patch", "post", "put", "trace"]>>;
|
|
162
|
-
servers: import("zod").ZodDefault<import("zod").ZodArray<import("zod").
|
|
163
|
-
selectedServerUid: import("zod").ZodDefault<import("zod").ZodString
|
|
164
|
-
examples: import("zod").ZodDefault<import("zod").ZodArray<import("zod").
|
|
165
|
-
selectedSecuritySchemeUids: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodUnion<[import("zod").
|
|
168
|
+
servers: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodBranded<import("zod").ZodString, "server">, "many">>;
|
|
169
|
+
selectedServerUid: import("zod").ZodDefault<import("zod").ZodNullable<import("zod").ZodOptional<import("zod").ZodBranded<import("zod").ZodString, "server">>>>;
|
|
170
|
+
examples: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodBranded<import("zod").ZodString, "example">, "many">>;
|
|
171
|
+
selectedSecuritySchemeUids: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodUnion<[import("zod").ZodBranded<import("zod").ZodString, "securityScheme">, import("zod").ZodArray<import("zod").ZodBranded<import("zod").ZodString, "securityScheme">, "many">]>, "many">>;
|
|
166
172
|
}>, "strip", import("zod").ZodTypeAny, {
|
|
167
173
|
path: string;
|
|
168
174
|
type: "request";
|
|
169
|
-
uid: string
|
|
170
|
-
selectedSecuritySchemeUids: (string | string[])[];
|
|
171
|
-
selectedServerUid: string;
|
|
172
|
-
servers: string[];
|
|
173
|
-
examples: string[];
|
|
175
|
+
uid: string & import("zod").BRAND<"operation">;
|
|
176
|
+
selectedSecuritySchemeUids: ((string & import("zod").BRAND<"securityScheme">) | (string & import("zod").BRAND<"securityScheme">)[])[];
|
|
177
|
+
selectedServerUid: (string & import("zod").BRAND<"server">) | null;
|
|
178
|
+
servers: (string & import("zod").BRAND<"server">)[];
|
|
179
|
+
examples: (string & import("zod").BRAND<"example">)[];
|
|
174
180
|
method: "options" | "connect" | "delete" | "get" | "head" | "patch" | "post" | "put" | "trace";
|
|
175
181
|
description?: string | undefined;
|
|
176
182
|
summary?: string | undefined;
|
|
@@ -187,10 +193,10 @@ export declare const operationSchema: import("zod").ZodObject<import("zod").obje
|
|
|
187
193
|
parameters?: {
|
|
188
194
|
required: boolean;
|
|
189
195
|
name: string;
|
|
190
|
-
in: "path" | "
|
|
196
|
+
in: "path" | "cookie" | "query" | "header";
|
|
191
197
|
deprecated: boolean;
|
|
192
|
-
description?: string | undefined;
|
|
193
198
|
example?: unknown;
|
|
199
|
+
description?: string | undefined;
|
|
194
200
|
schema?: unknown;
|
|
195
201
|
content?: unknown;
|
|
196
202
|
style?: "matrix" | "simple" | "form" | "label" | "spaceDelimited" | "pipeDelimited" | "deepObject" | undefined;
|
|
@@ -208,25 +214,25 @@ export declare const operationSchema: import("zod").ZodObject<import("zod").obje
|
|
|
208
214
|
description?: string | undefined;
|
|
209
215
|
summary?: string | undefined;
|
|
210
216
|
externalDocs?: {
|
|
211
|
-
|
|
212
|
-
|
|
217
|
+
url: string;
|
|
218
|
+
description?: unknown;
|
|
213
219
|
} | undefined;
|
|
214
220
|
'x-internal'?: boolean | undefined;
|
|
215
221
|
'x-scalar-ignore'?: boolean | undefined;
|
|
216
222
|
security?: Record<string, string[] | undefined>[] | undefined;
|
|
217
|
-
selectedSecuritySchemeUids?: (string |
|
|
218
|
-
selectedServerUid?: string | undefined;
|
|
219
|
-
servers?:
|
|
223
|
+
selectedSecuritySchemeUids?: (string | string[])[] | undefined;
|
|
224
|
+
selectedServerUid?: string | null | undefined;
|
|
225
|
+
servers?: string[] | undefined;
|
|
220
226
|
tags?: string[] | undefined;
|
|
221
227
|
deprecated?: boolean | undefined;
|
|
222
|
-
examples?:
|
|
228
|
+
examples?: string[] | undefined;
|
|
223
229
|
operationId?: string | undefined;
|
|
224
230
|
parameters?: {
|
|
225
231
|
name: string;
|
|
226
|
-
in: "path" | "
|
|
232
|
+
in: "path" | "cookie" | "query" | "header";
|
|
233
|
+
example?: unknown;
|
|
227
234
|
required?: boolean | undefined;
|
|
228
235
|
description?: string | undefined;
|
|
229
|
-
example?: unknown;
|
|
230
236
|
deprecated?: boolean | undefined;
|
|
231
237
|
schema?: unknown;
|
|
232
238
|
content?: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/operation.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/operation.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,OAAO,IAAI,WAAW,EAAiB,MAAM,YAAY,CAAA;AAE5F,MAAM,MAAM,SAAS,GAAG,WAAW,CAAA;AACnC,MAAM,MAAM,gBAAgB,GAAG,cAAc,CAAA;AAC7C,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAgB,CAAA"}
|
|
@@ -32,10 +32,10 @@ export declare const oasParameterSchema: z.ZodObject<{
|
|
|
32
32
|
}, "strip", z.ZodTypeAny, {
|
|
33
33
|
required: boolean;
|
|
34
34
|
name: string;
|
|
35
|
-
in: "path" | "
|
|
35
|
+
in: "path" | "cookie" | "query" | "header";
|
|
36
36
|
deprecated: boolean;
|
|
37
|
-
description?: string | undefined;
|
|
38
37
|
example?: unknown;
|
|
38
|
+
description?: string | undefined;
|
|
39
39
|
schema?: unknown;
|
|
40
40
|
content?: unknown;
|
|
41
41
|
style?: "matrix" | "simple" | "form" | "label" | "spaceDelimited" | "pipeDelimited" | "deepObject" | undefined;
|
|
@@ -45,10 +45,10 @@ export declare const oasParameterSchema: z.ZodObject<{
|
|
|
45
45
|
}> | undefined;
|
|
46
46
|
}, {
|
|
47
47
|
name: string;
|
|
48
|
-
in: "path" | "
|
|
48
|
+
in: "path" | "cookie" | "query" | "header";
|
|
49
|
+
example?: unknown;
|
|
49
50
|
required?: boolean | undefined;
|
|
50
51
|
description?: string | undefined;
|
|
51
|
-
example?: unknown;
|
|
52
52
|
deprecated?: boolean | undefined;
|
|
53
53
|
schema?: unknown;
|
|
54
54
|
content?: unknown;
|
|
@@ -85,7 +85,7 @@ export declare const requestExampleParametersSchema: z.ZodEffects<z.ZodObject<{
|
|
|
85
85
|
nullable?: boolean | undefined;
|
|
86
86
|
}>;
|
|
87
87
|
/** Convert the array of parameters to an object keyed by the parameter name */
|
|
88
|
-
export declare
|
|
88
|
+
export declare const parameterArrayToObject: (params: RequestExampleParameter[]) => Record<string, string>;
|
|
89
89
|
/** Request examples - formerly known as instances - are "children" of requests */
|
|
90
90
|
export type RequestExampleParameter = z.infer<typeof requestExampleParametersSchema>;
|
|
91
91
|
export declare const xScalarFileValueSchema: z.ZodNullable<z.ZodObject<{
|
|
@@ -376,9 +376,9 @@ export declare const xScalarExampleBodySchema: z.ZodObject<{
|
|
|
376
376
|
}>;
|
|
377
377
|
export type XScalarExampleBody = z.infer<typeof xScalarExampleBodySchema>;
|
|
378
378
|
export declare const requestExampleSchema: z.ZodObject<{
|
|
379
|
-
uid: z.ZodDefault<z.ZodOptional<z.ZodString
|
|
379
|
+
uid: z.ZodBranded<z.ZodDefault<z.ZodOptional<z.ZodString>>, "example">;
|
|
380
380
|
type: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"requestExample">>>;
|
|
381
|
-
requestUid: z.
|
|
381
|
+
requestUid: z.ZodOptional<z.ZodBranded<z.ZodString, "operation">>;
|
|
382
382
|
name: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
383
383
|
body: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
384
384
|
raw: z.ZodOptional<z.ZodObject<{
|
|
@@ -1001,7 +1001,7 @@ export declare const requestExampleSchema: z.ZodObject<{
|
|
|
1001
1001
|
serverVariables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
|
|
1002
1002
|
}, "strip", z.ZodTypeAny, {
|
|
1003
1003
|
type: "requestExample";
|
|
1004
|
-
uid: string
|
|
1004
|
+
uid: string & z.BRAND<"example">;
|
|
1005
1005
|
name: string;
|
|
1006
1006
|
parameters: {
|
|
1007
1007
|
path: {
|
|
@@ -1096,7 +1096,7 @@ export declare const requestExampleSchema: z.ZodObject<{
|
|
|
1096
1096
|
encoding: "xml" | "text" | "json" | "html" | "javascript" | "yaml" | "edn";
|
|
1097
1097
|
} | undefined;
|
|
1098
1098
|
};
|
|
1099
|
-
requestUid
|
|
1099
|
+
requestUid?: (string & z.BRAND<"operation">) | undefined;
|
|
1100
1100
|
serverVariables?: Record<string, string[]> | undefined;
|
|
1101
1101
|
}, {
|
|
1102
1102
|
type?: "requestExample" | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-examples.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/request-examples.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"request-examples.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/request-examples.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAKtC;;;;;GAKG;AACH,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuCvC,CAAA;AAEJ,+EAA+E;AAC/E,eAAO,MAAM,sBAAsB,WAAY,uBAAuB,EAAE,2BAIhE,CAAA;AAER,kFAAkF;AAClF,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAA;AAEpF,eAAO,MAAM,sBAAsB;;;;;;;;;GAKtB,CAAA;AAEb;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAErE;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAS/B,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAKvE;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,uEAAwE,CAAA;AAE/G,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,0B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= z
|
|
|
38
38
|
nullable: z.boolean().optional(),
|
|
39
39
|
})
|
|
40
40
|
// set nullable: to true if type is ['string', 'null']
|
|
41
|
-
.transform((
|
|
41
|
+
.transform((_data) => {
|
|
42
|
+
const data = { ..._data };
|
|
42
43
|
// type: ['string', 'null'] -> nullable: true
|
|
43
44
|
if (Array.isArray(data.type) && data.type.includes('null')) {
|
|
44
|
-
data =
|
|
45
|
+
data.nullable = true;
|
|
45
46
|
}
|
|
46
47
|
// Hey, if it’s just one value and 'null', we can make it a string and ditch the 'null'.
|
|
47
|
-
if (Array.isArray(data.type) &&
|
|
48
|
-
data.type.
|
|
49
|
-
data.type.includes('null')) {
|
|
50
|
-
data = { ...data, type: data.type.find((item) => item !== 'null') };
|
|
48
|
+
if (Array.isArray(data.type) && data.type.length === 2 && data.type.includes('null')) {
|
|
49
|
+
data.type = data.type.find((item) => item !== 'null');
|
|
51
50
|
}
|
|
52
51
|
return data;
|
|
53
52
|
});
|
|
54
53
|
/** Convert the array of parameters to an object keyed by the parameter name */
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}, {});
|
|
60
|
-
}
|
|
54
|
+
const parameterArrayToObject = (params) => params.reduce((map, param) => {
|
|
55
|
+
map[param.key] = param.value;
|
|
56
|
+
return map;
|
|
57
|
+
}, {});
|
|
61
58
|
const xScalarFileValueSchema = z
|
|
62
59
|
.object({
|
|
63
60
|
url: z.string(),
|
|
@@ -86,15 +83,7 @@ const xScalarFormDataValue = z.union([
|
|
|
86
83
|
*
|
|
87
84
|
* TODO: This list may not be comprehensive enough
|
|
88
85
|
*/
|
|
89
|
-
const exampleRequestBodyEncoding = [
|
|
90
|
-
'json',
|
|
91
|
-
'text',
|
|
92
|
-
'html',
|
|
93
|
-
'javascript',
|
|
94
|
-
'xml',
|
|
95
|
-
'yaml',
|
|
96
|
-
'edn',
|
|
97
|
-
];
|
|
86
|
+
const exampleRequestBodyEncoding = ['json', 'text', 'html', 'javascript', 'xml', 'yaml', 'edn'];
|
|
98
87
|
const exampleBodyMime = [
|
|
99
88
|
'application/json',
|
|
100
89
|
'text/plain',
|
|
@@ -132,16 +121,12 @@ const exampleRequestBodySchema = z.object({
|
|
|
132
121
|
.optional(),
|
|
133
122
|
formData: z
|
|
134
123
|
.object({
|
|
135
|
-
encoding: z
|
|
136
|
-
.union([z.literal('form-data'), z.literal('urlencoded')])
|
|
137
|
-
.default('form-data'),
|
|
124
|
+
encoding: z.union([z.literal('form-data'), z.literal('urlencoded')]).default('form-data'),
|
|
138
125
|
value: requestExampleParametersSchema.array().default([]),
|
|
139
126
|
})
|
|
140
127
|
.optional(),
|
|
141
128
|
binary: z.instanceof(Blob).optional(),
|
|
142
|
-
activeBody: z
|
|
143
|
-
.union([z.literal('raw'), z.literal('formData'), z.literal('binary')])
|
|
144
|
-
.default('raw'),
|
|
129
|
+
activeBody: z.union([z.literal('raw'), z.literal('formData'), z.literal('binary')]).default('raw'),
|
|
145
130
|
});
|
|
146
131
|
/** Schema for the OAS serialization of request example bodies */
|
|
147
132
|
const xScalarExampleBodySchema = z.object({
|
|
@@ -158,18 +143,16 @@ const xScalarExampleBodySchema = z.object({
|
|
|
158
143
|
// ---------------------------------------------------------------------------
|
|
159
144
|
// Example Schema
|
|
160
145
|
const requestExampleSchema = z.object({
|
|
161
|
-
uid: nanoidSchema,
|
|
146
|
+
uid: nanoidSchema.brand(),
|
|
162
147
|
type: z.literal('requestExample').optional().default('requestExample'),
|
|
163
|
-
requestUid:
|
|
148
|
+
requestUid: z.string().brand().optional(),
|
|
164
149
|
name: z.string().optional().default('Name'),
|
|
165
150
|
body: exampleRequestBodySchema.optional().default({}),
|
|
166
151
|
parameters: z
|
|
167
152
|
.object({
|
|
168
153
|
path: requestExampleParametersSchema.array().default([]),
|
|
169
154
|
query: requestExampleParametersSchema.array().default([]),
|
|
170
|
-
headers: requestExampleParametersSchema
|
|
171
|
-
.array()
|
|
172
|
-
.default([{ key: 'Accept', value: '*/*', enabled: true }]),
|
|
155
|
+
headers: requestExampleParametersSchema.array().default([{ key: 'Accept', value: '*/*', enabled: true }]),
|
|
173
156
|
cookies: requestExampleParametersSchema.array().default([]),
|
|
174
157
|
})
|
|
175
158
|
.optional()
|
|
@@ -178,9 +161,7 @@ const requestExampleSchema = z.object({
|
|
|
178
161
|
serverVariables: z.record(z.string(), z.array(z.string())).optional(),
|
|
179
162
|
});
|
|
180
163
|
/** For OAS serialization we just store the simple key/value pairs */
|
|
181
|
-
const xScalarExampleParameterSchema = z
|
|
182
|
-
.record(z.string(), z.string())
|
|
183
|
-
.optional();
|
|
164
|
+
const xScalarExampleParameterSchema = z.record(z.string(), z.string()).optional();
|
|
184
165
|
/** Schema for the OAS serialization of request examples */
|
|
185
166
|
const xScalarExampleSchema = z.object({
|
|
186
167
|
/** TODO: Should this be required? */
|
|
@@ -211,10 +192,7 @@ function convertExampleToXScalar(example) {
|
|
|
211
192
|
}
|
|
212
193
|
if (active === 'formData' && example.body?.[active]) {
|
|
213
194
|
const body = example.body[active];
|
|
214
|
-
xScalarBody.encoding =
|
|
215
|
-
body.encoding === 'form-data'
|
|
216
|
-
? 'multipart/form-data'
|
|
217
|
-
: 'application/x-www-form-urlencoded';
|
|
195
|
+
xScalarBody.encoding = body.encoding === 'form-data' ? 'multipart/form-data' : 'application/x-www-form-urlencoded';
|
|
218
196
|
// TODO: Need to allow users to set these properties
|
|
219
197
|
xScalarBody.content = body.value.reduce((map, param) => {
|
|
220
198
|
/** TODO: We need to ensure only file or value is set */
|
|
@@ -231,8 +209,7 @@ function convertExampleToXScalar(example) {
|
|
|
231
209
|
}, {});
|
|
232
210
|
}
|
|
233
211
|
if (example.body?.activeBody === 'raw') {
|
|
234
|
-
xScalarBody.encoding =
|
|
235
|
-
contentMapping[example.body.raw?.encoding ?? 'text'] ?? 'text/plain';
|
|
212
|
+
xScalarBody.encoding = contentMapping[example.body.raw?.encoding ?? 'text'] ?? 'text/plain';
|
|
236
213
|
xScalarBody.content = example.body.raw?.value ?? '';
|
|
237
214
|
}
|
|
238
215
|
const parameters = {};
|
|
@@ -243,9 +220,7 @@ function convertExampleToXScalar(example) {
|
|
|
243
220
|
});
|
|
244
221
|
return xScalarExampleSchema.parse({
|
|
245
222
|
/** Only add the body if we have content or the body should be a file */
|
|
246
|
-
body: xScalarBody.content || xScalarBody.encoding === 'binary'
|
|
247
|
-
? xScalarBody
|
|
248
|
-
: undefined,
|
|
223
|
+
body: xScalarBody.content || xScalarBody.encoding === 'binary' ? xScalarBody : undefined,
|
|
249
224
|
parameters,
|
|
250
225
|
});
|
|
251
226
|
}
|
|
@@ -262,12 +237,7 @@ function createParamInstance(param) {
|
|
|
262
237
|
* - Need to handle non-string parameters much better
|
|
263
238
|
* - Need to handle unions/array values for schema
|
|
264
239
|
*/
|
|
265
|
-
const value = String(schema?.default ??
|
|
266
|
-
schema?.examples?.[0] ??
|
|
267
|
-
schema?.example ??
|
|
268
|
-
firstExample?.value ??
|
|
269
|
-
param.example ??
|
|
270
|
-
'');
|
|
240
|
+
const value = String(schema?.default ?? schema?.examples?.[0] ?? schema?.example ?? firstExample?.value ?? param.example ?? '');
|
|
271
241
|
// Handle non-string enums and enums within items for array types
|
|
272
242
|
const parseEnum = schema?.enum && schema?.type !== 'string'
|
|
273
243
|
? schema.enum?.map(String)
|
|
@@ -275,9 +245,7 @@ function createParamInstance(param) {
|
|
|
275
245
|
? schema.items.enum.map(String)
|
|
276
246
|
: schema?.enum;
|
|
277
247
|
// Handle non-string examples
|
|
278
|
-
const parseExamples = schema?.examples && schema?.type !== 'string'
|
|
279
|
-
? schema.examples?.map(String)
|
|
280
|
-
: schema?.examples;
|
|
248
|
+
const parseExamples = schema?.examples && schema?.type !== 'string' ? schema.examples?.map(String) : schema?.examples;
|
|
281
249
|
// safe parse the example
|
|
282
250
|
const example = schemaModel({
|
|
283
251
|
...schema,
|
|
@@ -294,8 +262,7 @@ function createParamInstance(param) {
|
|
|
294
262
|
console.warn(`Example at ${param.name} is invalid.`);
|
|
295
263
|
return requestExampleParametersSchema.parse({});
|
|
296
264
|
}
|
|
297
|
-
|
|
298
|
-
return example;
|
|
265
|
+
return example;
|
|
299
266
|
}
|
|
300
267
|
/**
|
|
301
268
|
* Create new request example from a request
|
|
@@ -319,48 +286,49 @@ function createExampleFromRequest(request, name, server) {
|
|
|
319
286
|
parameters.headers = parameters.header;
|
|
320
287
|
parameters.header = [];
|
|
321
288
|
}
|
|
289
|
+
// Get content type header
|
|
290
|
+
const contentTypeHeader = parameters.headers.find((h) => h.key.toLowerCase() === 'content-type');
|
|
322
291
|
// ---------------------------------------------------------------------------
|
|
323
292
|
// Handle request body defaulting for various content type encodings
|
|
324
293
|
const body = {
|
|
325
294
|
activeBody: 'raw',
|
|
326
295
|
};
|
|
327
|
-
|
|
296
|
+
// If we have a request body or a content type header
|
|
297
|
+
if (request.requestBody || contentTypeHeader?.value) {
|
|
328
298
|
const requestBody = getRequestBodyFromOperation({
|
|
329
299
|
path: request.path,
|
|
330
300
|
information: {
|
|
331
301
|
requestBody: request.requestBody,
|
|
332
302
|
},
|
|
333
303
|
});
|
|
334
|
-
|
|
304
|
+
const contentType = request.requestBody ? requestBody?.mimeType : contentTypeHeader?.value;
|
|
305
|
+
if (contentType === 'application/json') {
|
|
335
306
|
body.activeBody = 'raw';
|
|
336
307
|
body.raw = {
|
|
337
308
|
encoding: 'json',
|
|
338
|
-
value: requestBody
|
|
309
|
+
value: requestBody?.text ?? JSON.stringify({}),
|
|
339
310
|
};
|
|
340
311
|
}
|
|
341
|
-
if (
|
|
312
|
+
if (contentType === 'application/xml') {
|
|
342
313
|
body.activeBody = 'raw';
|
|
343
314
|
body.raw = {
|
|
344
315
|
encoding: 'xml',
|
|
345
|
-
value: requestBody
|
|
316
|
+
value: requestBody?.text ?? '',
|
|
346
317
|
};
|
|
347
318
|
}
|
|
348
319
|
/**
|
|
349
320
|
* TODO: Are we loading example files from somewhere based on the spec?
|
|
350
321
|
* How are we handling the body values
|
|
351
322
|
*/
|
|
352
|
-
if (
|
|
323
|
+
if (contentType === 'application/octet-stream') {
|
|
353
324
|
body.activeBody = 'binary';
|
|
354
325
|
body.binary = undefined;
|
|
355
326
|
}
|
|
356
|
-
if (
|
|
357
|
-
requestBody?.mimeType === 'multipart/form-data') {
|
|
327
|
+
if (contentType === 'application/x-www-form-urlencoded' || contentType === 'multipart/form-data') {
|
|
358
328
|
body.activeBody = 'formData';
|
|
359
329
|
body.formData = {
|
|
360
|
-
encoding:
|
|
361
|
-
|
|
362
|
-
: 'form-data',
|
|
363
|
-
value: (requestBody.params || []).map((param) => ({
|
|
330
|
+
encoding: contentType === 'application/x-www-form-urlencoded' ? 'urlencoded' : 'form-data',
|
|
331
|
+
value: (requestBody?.params || []).map((param) => ({
|
|
364
332
|
key: param.name,
|
|
365
333
|
value: param.value || '',
|
|
366
334
|
enabled: true,
|
|
@@ -368,8 +336,7 @@ function createExampleFromRequest(request, name, server) {
|
|
|
368
336
|
};
|
|
369
337
|
}
|
|
370
338
|
// Add the content-type header if it doesn't exist
|
|
371
|
-
if (requestBody?.mimeType &&
|
|
372
|
-
!parameters.headers.find((h) => h.key.toLowerCase() === 'content-type')) {
|
|
339
|
+
if (requestBody?.mimeType && !contentTypeHeader) {
|
|
373
340
|
parameters.headers.push({
|
|
374
341
|
key: 'Content-Type',
|
|
375
342
|
value: requestBody.mimeType,
|
|
@@ -390,8 +357,7 @@ function createExampleFromRequest(request, name, server) {
|
|
|
390
357
|
console.warn(`Example at ${request.uid} is invalid.`);
|
|
391
358
|
return requestExampleSchema.parse({});
|
|
392
359
|
}
|
|
393
|
-
|
|
394
|
-
return example;
|
|
360
|
+
return example;
|
|
395
361
|
}
|
|
396
362
|
|
|
397
363
|
export { convertExampleToXScalar, createExampleFromRequest, createParamInstance, exampleBodyMime, exampleRequestBodyEncoding, exampleRequestBodySchema, parameterArrayToObject, requestExampleParametersSchema, requestExampleSchema, xScalarExampleBodySchema, xScalarExampleSchema, xScalarFileValueSchema, xScalarFormDataValue };
|