@scalar/oas-utils 0.6.2 → 0.6.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/CHANGELOG.md +31 -0
- package/dist/entities/cookie/cookie.d.ts +1 -1
- package/dist/entities/environment/environment.d.ts.map +1 -1
- package/dist/entities/environment/environment.js.map +2 -2
- package/dist/entities/environment/index.d.ts +2 -1
- package/dist/entities/environment/index.d.ts.map +1 -1
- package/dist/entities/environment/index.js.map +2 -2
- package/dist/entities/spec/collection.d.ts +1 -132
- package/dist/entities/spec/collection.d.ts.map +1 -1
- package/dist/entities/spec/collection.js +4 -7
- package/dist/entities/spec/collection.js.map +2 -2
- package/dist/entities/spec/index.d.ts +9 -8
- package/dist/entities/spec/index.d.ts.map +1 -1
- package/dist/entities/spec/index.js +22 -22
- package/dist/entities/spec/index.js.map +2 -2
- package/dist/entities/spec/operation.d.ts +4 -4
- package/dist/entities/spec/parameters.d.ts +1 -19
- package/dist/entities/spec/parameters.d.ts.map +1 -1
- package/dist/entities/spec/parameters.js +1 -5
- package/dist/entities/spec/parameters.js.map +2 -2
- package/dist/entities/spec/request-examples.d.ts +1 -130
- package/dist/entities/spec/request-examples.d.ts.map +1 -1
- package/dist/entities/spec/request-examples.js +1 -7
- package/dist/entities/spec/request-examples.js.map +2 -2
- package/dist/entities/spec/requests.d.ts +5 -87
- package/dist/entities/spec/requests.d.ts.map +1 -1
- package/dist/entities/spec/requests.js +4 -6
- package/dist/entities/spec/requests.js.map +2 -2
- package/dist/entities/spec/server.d.ts +1 -30
- package/dist/entities/spec/server.d.ts.map +1 -1
- package/dist/entities/spec/server.js +0 -2
- package/dist/entities/spec/server.js.map +2 -2
- package/dist/entities/spec/spec-objects.d.ts +1 -33
- package/dist/entities/spec/spec-objects.d.ts.map +1 -1
- package/dist/entities/spec/spec-objects.js +1 -3
- package/dist/entities/spec/spec-objects.js.map +2 -2
- package/dist/entities/spec/x-scalar-environments.d.ts +2 -6
- package/dist/entities/spec/x-scalar-environments.d.ts.map +1 -1
- package/dist/entities/spec/x-scalar-environments.js +0 -2
- package/dist/entities/spec/x-scalar-environments.js.map +2 -2
- package/dist/entities/spec/x-scalar-secrets.d.ts +0 -5
- package/dist/entities/spec/x-scalar-secrets.d.ts.map +1 -1
- package/dist/entities/spec/x-scalar-secrets.js +0 -1
- package/dist/entities/spec/x-scalar-secrets.js.map +2 -2
- package/dist/entities/workspace/workspace.d.ts +1 -1
- package/dist/helpers/security/get-schemes.d.ts.map +1 -1
- package/package.json +10 -21
|
@@ -58,136 +58,8 @@ export declare const requestExampleParametersSchema: z.ZodPipe<z.ZodObject<{
|
|
|
58
58
|
export declare const parameterArrayToObject: (params: RequestExampleParameter[]) => Record<string, string>;
|
|
59
59
|
/** Request examples - formerly known as instances - are "children" of requests */
|
|
60
60
|
export type RequestExampleParameter = z.infer<typeof requestExampleParametersSchema>;
|
|
61
|
-
export declare const xScalarFileValueSchema: z.ZodNullable<z.ZodObject<{
|
|
62
|
-
url: z.ZodString;
|
|
63
|
-
base64: z.ZodOptional<z.ZodString>;
|
|
64
|
-
}, z.core.$strip>>;
|
|
65
|
-
/**
|
|
66
|
-
* When files are required for an example we provide the options
|
|
67
|
-
* to provide a public URL or a base64 encoded string
|
|
68
|
-
*/
|
|
69
|
-
export type XScalarFileValue = z.infer<typeof xScalarFileValueSchema>;
|
|
70
|
-
/**
|
|
71
|
-
* Schema for the OAS serialization of request example parameters
|
|
72
|
-
*
|
|
73
|
-
* File values can be optionally fetched on import OR inserted as a base64 encoded string
|
|
74
|
-
*/
|
|
75
|
-
export declare const xScalarFormDataValue: z.ZodUnion<readonly [z.ZodObject<{
|
|
76
|
-
type: z.ZodLiteral<"string">;
|
|
77
|
-
value: z.ZodString;
|
|
78
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
79
|
-
type: z.ZodLiteral<"file">;
|
|
80
|
-
file: z.ZodNullable<z.ZodObject<{
|
|
81
|
-
url: z.ZodString;
|
|
82
|
-
base64: z.ZodOptional<z.ZodString>;
|
|
83
|
-
}, z.core.$strip>>;
|
|
84
|
-
}, z.core.$strip>]>;
|
|
85
|
-
export type XScalarFormDataValue = z.infer<typeof xScalarFormDataValue>;
|
|
86
|
-
/**
|
|
87
|
-
* Possible encodings for example request bodies when using text formats
|
|
88
|
-
*
|
|
89
|
-
* TODO: This list may not be comprehensive enough
|
|
90
|
-
*/
|
|
91
|
-
export declare const exampleRequestBodyEncoding: readonly ["json", "text", "html", "javascript", "xml", "yaml", "edn"];
|
|
92
|
-
export type BodyEncoding = (typeof exampleRequestBodyEncoding)[number];
|
|
93
|
-
export declare const exampleBodyMime: readonly ["application/json", "text/plain", "text/html", "application/javascript", "application/xml", "application/yaml", "application/edn", "application/octet-stream", "application/x-www-form-urlencoded", "multipart/form-data", "binary"];
|
|
94
|
-
export type BodyMime = (typeof exampleBodyMime)[number];
|
|
95
|
-
/**
|
|
96
|
-
* TODO: Migrate away from this layout to the format used in the extension
|
|
97
|
-
*
|
|
98
|
-
* If a user changes the encoding of the body we expect the content to change as well
|
|
99
|
-
*/
|
|
100
|
-
export declare const exampleRequestBodySchema: z.ZodObject<{
|
|
101
|
-
raw: z.ZodOptional<z.ZodObject<{
|
|
102
|
-
encoding: z.ZodEnum<{
|
|
103
|
-
xml: "xml";
|
|
104
|
-
json: "json";
|
|
105
|
-
html: "html";
|
|
106
|
-
text: "text";
|
|
107
|
-
javascript: "javascript";
|
|
108
|
-
yaml: "yaml";
|
|
109
|
-
edn: "edn";
|
|
110
|
-
}>;
|
|
111
|
-
value: z.ZodDefault<z.ZodString>;
|
|
112
|
-
mimeType: z.ZodOptional<z.ZodString>;
|
|
113
|
-
}, z.core.$strip>>;
|
|
114
|
-
formData: z.ZodOptional<z.ZodObject<{
|
|
115
|
-
encoding: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<"form-data">, z.ZodLiteral<"urlencoded">]>>;
|
|
116
|
-
value: z.ZodDefault<z.ZodArray<z.ZodPipe<z.ZodObject<{
|
|
117
|
-
key: z.ZodDefault<z.ZodString>;
|
|
118
|
-
value: z.ZodDefault<z.ZodCoercedString<unknown>>;
|
|
119
|
-
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
120
|
-
file: z.ZodOptional<z.ZodAny>;
|
|
121
|
-
description: z.ZodOptional<z.ZodString>;
|
|
122
|
-
required: z.ZodOptional<z.ZodBoolean>;
|
|
123
|
-
enum: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
124
|
-
examples: z.ZodOptional<z.ZodArray<z.ZodAny>>;
|
|
125
|
-
type: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
126
|
-
format: z.ZodOptional<z.ZodString>;
|
|
127
|
-
minimum: z.ZodOptional<z.ZodNumber>;
|
|
128
|
-
maximum: z.ZodOptional<z.ZodNumber>;
|
|
129
|
-
default: z.ZodOptional<z.ZodAny>;
|
|
130
|
-
nullable: z.ZodOptional<z.ZodBoolean>;
|
|
131
|
-
}, z.core.$strip>, z.ZodTransform<{
|
|
132
|
-
key: string;
|
|
133
|
-
value: string;
|
|
134
|
-
enabled: boolean;
|
|
135
|
-
file?: any;
|
|
136
|
-
description?: string | undefined;
|
|
137
|
-
required?: boolean | undefined;
|
|
138
|
-
enum?: string[] | undefined;
|
|
139
|
-
examples?: any[] | undefined;
|
|
140
|
-
type?: string | string[] | undefined;
|
|
141
|
-
format?: string | undefined;
|
|
142
|
-
minimum?: number | undefined;
|
|
143
|
-
maximum?: number | undefined;
|
|
144
|
-
default?: any;
|
|
145
|
-
nullable?: boolean | undefined;
|
|
146
|
-
}, {
|
|
147
|
-
key: string;
|
|
148
|
-
value: string;
|
|
149
|
-
enabled: boolean;
|
|
150
|
-
file?: any;
|
|
151
|
-
description?: string | undefined;
|
|
152
|
-
required?: boolean | undefined;
|
|
153
|
-
enum?: string[] | undefined;
|
|
154
|
-
examples?: any[] | undefined;
|
|
155
|
-
type?: string | string[] | undefined;
|
|
156
|
-
format?: string | undefined;
|
|
157
|
-
minimum?: number | undefined;
|
|
158
|
-
maximum?: number | undefined;
|
|
159
|
-
default?: any;
|
|
160
|
-
nullable?: boolean | undefined;
|
|
161
|
-
}>>>>;
|
|
162
|
-
}, z.core.$strip>>;
|
|
163
|
-
binary: z.ZodOptional<z.ZodCustom<Blob, Blob>>;
|
|
164
|
-
activeBody: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<"raw">, z.ZodLiteral<"formData">, z.ZodLiteral<"binary">]>>;
|
|
165
|
-
}, z.core.$strip>;
|
|
166
|
-
export type ExampleRequestBody = z.infer<typeof exampleRequestBodySchema>;
|
|
167
|
-
/** Schema for the OAS serialization of request example bodies */
|
|
168
|
-
export declare const xScalarExampleBodySchema: z.ZodObject<{
|
|
169
|
-
encoding: z.ZodEnum<{
|
|
170
|
-
binary: "binary";
|
|
171
|
-
"application/json": "application/json";
|
|
172
|
-
"text/plain": "text/plain";
|
|
173
|
-
"text/html": "text/html";
|
|
174
|
-
"application/javascript": "application/javascript";
|
|
175
|
-
"application/xml": "application/xml";
|
|
176
|
-
"application/yaml": "application/yaml";
|
|
177
|
-
"application/edn": "application/edn";
|
|
178
|
-
"application/octet-stream": "application/octet-stream";
|
|
179
|
-
"application/x-www-form-urlencoded": "application/x-www-form-urlencoded";
|
|
180
|
-
"multipart/form-data": "multipart/form-data";
|
|
181
|
-
}>;
|
|
182
|
-
content: z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodString]>;
|
|
183
|
-
file: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
184
|
-
url: z.ZodString;
|
|
185
|
-
base64: z.ZodOptional<z.ZodString>;
|
|
186
|
-
}, z.core.$strip>>>;
|
|
187
|
-
}, z.core.$strip>;
|
|
188
|
-
export type XScalarExampleBody = z.infer<typeof xScalarExampleBodySchema>;
|
|
189
61
|
export declare const requestExampleSchema: z.ZodObject<{
|
|
190
|
-
uid: z.core.$ZodBranded<z.ZodDefault<z.
|
|
62
|
+
uid: z.core.$ZodBranded<z.ZodDefault<z.ZodString>, "example">;
|
|
191
63
|
type: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"requestExample">>>;
|
|
192
64
|
requestUid: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "operation">>;
|
|
193
65
|
name: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
@@ -476,7 +348,6 @@ export declare const xScalarExampleSchema: z.ZodObject<{
|
|
|
476
348
|
cookies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
477
349
|
}, z.core.$strip>;
|
|
478
350
|
}, z.core.$strip>;
|
|
479
|
-
export type XScalarExample = z.infer<typeof xScalarExampleSchema>;
|
|
480
351
|
/**
|
|
481
352
|
* Convert a request example to the xScalar serialized format
|
|
482
353
|
*
|
|
@@ -1 +1 @@
|
|
|
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;AAMvB,OAAO,KAAK,EAAoB,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACtE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAKtC;;;;;GAKG;AACH,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCvC,CAAA;AAEJ,+EAA+E;AAC/E,eAAO,MAAM,sBAAsB,GAAI,QAAQ,uBAAuB,EAAE,2BAIhE,CAAA;AAER,kFAAkF;AAClF,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"request-examples.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/request-examples.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,C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AO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,cAAc,CA2HxG"}
|
|
@@ -351,15 +351,9 @@ export {
|
|
|
351
351
|
convertExampleToXScalar,
|
|
352
352
|
createExampleFromRequest,
|
|
353
353
|
createParamInstance,
|
|
354
|
-
exampleBodyMime,
|
|
355
|
-
exampleRequestBodyEncoding,
|
|
356
|
-
exampleRequestBodySchema,
|
|
357
354
|
parameterArrayToObject,
|
|
358
355
|
requestExampleParametersSchema,
|
|
359
356
|
requestExampleSchema,
|
|
360
|
-
|
|
361
|
-
xScalarExampleSchema,
|
|
362
|
-
xScalarFileValueSchema,
|
|
363
|
-
xScalarFormDataValue
|
|
357
|
+
xScalarExampleSchema
|
|
364
358
|
};
|
|
365
359
|
//# sourceMappingURL=request-examples.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/entities/spec/request-examples.ts"],
|
|
4
|
-
"sourcesContent": ["import { isDefined } from '@scalar/helpers/array/is-defined'\nimport { objectKeys } from '@scalar/helpers/object/object-keys'\nimport { keysOf } from '@scalar/object-utils/arrays'\nimport { type ENTITY_BRANDS, nanoidSchema } from '@scalar/types/utils'\nimport { z } from 'zod'\n\nimport { schemaModel } from '@/helpers/schema-model'\nimport { getRequestBodyFromOperation } from '@/spec-getters/get-request-body-from-operation'\nimport { getServerVariableExamples } from '@/spec-getters/get-server-variable-examples'\n\nimport type { ParameterContent, RequestParameter } from './parameters'\nimport type { Request } from './requests'\nimport type { Server } from './server'\n\n// ---------------------------------------------------------------------------\n// Example Parameters\n\n/**\n * TODO: Deprecate this.\n *\n * The request schema should be stored in the request and any\n * parameters should be validated against that\n */\nexport const requestExampleParametersSchema = z\n .object({\n key: z.string().default(''),\n value: z.coerce.string().default(''),\n enabled: z.boolean().default(true),\n file: z.any().optional(),\n description: z.string().optional(),\n required: z.boolean().optional(),\n enum: z.array(z.string()).optional(),\n examples: z.array(z.any()).optional(),\n type: z\n .union([\n // 'string'\n z.string(),\n // ['string', 'null']\n z.array(z.string()),\n ])\n .optional(),\n format: z.string().optional(),\n minimum: z.number().optional(),\n maximum: z.number().optional(),\n default: z.any().optional(),\n nullable: z.boolean().optional(),\n })\n // set nullable: to true if type is ['string', 'null']\n .transform((_data) => {\n const data = { ..._data }\n\n // type: ['string', 'null'] -> nullable: true\n if (Array.isArray(data.type) && data.type.includes('null')) {\n data.nullable = true\n }\n\n // Hey, if it's just one value and 'null', we can make it a string and ditch the 'null'.\n if (Array.isArray(data.type) && data.type.length === 2 && data.type.includes('null')) {\n data.type = data.type.find((item) => item !== 'null')\n }\n\n return data\n })\n\n/** Convert the array of parameters to an object keyed by the parameter name */\nexport const parameterArrayToObject = (params: RequestExampleParameter[]) =>\n params.reduce<Record<string, string>>((map, param) => {\n map[param.key] = param.value\n return map\n }, {})\n\n/** Request examples - formerly known as instances - are \"children\" of requests */\nexport type RequestExampleParameter = z.infer<typeof requestExampleParametersSchema>\n\nexport const xScalarFileValueSchema = z\n .object({\n url: z.string(),\n base64: z.string().optional(),\n })\n .nullable()\n\n/**\n * When files are required for an example we provide the options\n * to provide a public URL or a base64 encoded string\n */\nexport type XScalarFileValue = z.infer<typeof xScalarFileValueSchema>\n\n/**\n * Schema for the OAS serialization of request example parameters\n *\n * File values can be optionally fetched on import OR inserted as a base64 encoded string\n */\nexport const xScalarFormDataValue = z.union([\n z.object({\n type: z.literal('string'),\n value: z.string(),\n }),\n z.object({\n type: z.literal('file'),\n file: xScalarFileValueSchema,\n }),\n])\n\nexport type XScalarFormDataValue = z.infer<typeof xScalarFormDataValue>\n\n// ---------------------------------------------------------------------------\n// Example Body\n\n/**\n * Possible encodings for example request bodies when using text formats\n *\n * TODO: This list may not be comprehensive enough\n */\nexport const exampleRequestBodyEncoding = ['json', 'text', 'html', 'javascript', 'xml', 'yaml', 'edn'] as const\n\nexport type BodyEncoding = (typeof exampleRequestBodyEncoding)[number]\n\nexport const exampleBodyMime = [\n 'application/json',\n 'text/plain',\n 'text/html',\n 'application/javascript',\n 'application/xml',\n 'application/yaml',\n 'application/edn',\n 'application/octet-stream',\n 'application/x-www-form-urlencoded',\n 'multipart/form-data',\n /** Used for direct files */\n 'binary',\n] as const\n\nexport type BodyMime = (typeof exampleBodyMime)[number]\n\nconst contentMapping: Record<BodyEncoding, BodyMime> = {\n json: 'application/json',\n text: 'text/plain',\n html: 'text/html',\n javascript: 'application/javascript',\n xml: 'application/xml',\n yaml: 'application/yaml',\n edn: 'application/edn',\n} as const\n\n/**\n * TODO: Migrate away from this layout to the format used in the extension\n *\n * If a user changes the encoding of the body we expect the content to change as well\n */\nexport const exampleRequestBodySchema = z.object({\n raw: z\n .object({\n encoding: z.enum(exampleRequestBodyEncoding),\n value: z.string().default(''),\n mimeType: z.string().optional(),\n })\n .optional(),\n formData: z\n .object({\n encoding: z.union([z.literal('form-data'), z.literal('urlencoded')]).default('form-data'),\n value: requestExampleParametersSchema.array().default([]),\n })\n .optional(),\n binary: z.instanceof(Blob).optional(),\n activeBody: z.union([z.literal('raw'), z.literal('formData'), z.literal('binary')]).default('raw'),\n})\n\nexport type ExampleRequestBody = z.infer<typeof exampleRequestBodySchema>\n\n/** Schema for the OAS serialization of request example bodies */\nexport const xScalarExampleBodySchema = z.object({\n encoding: z.enum(exampleBodyMime),\n /**\n * Body content as an object with a separately specified encoding or a simple pre-encoded string value\n *\n * Ideally we would convert any objects into the proper encoding on import\n */\n content: z.union([z.record(z.string(), z.any()), z.string()]),\n /** When the encoding is `binary` this will be used to link to the file */\n file: xScalarFileValueSchema.optional(),\n})\n\nexport type XScalarExampleBody = z.infer<typeof xScalarExampleBodySchema>\n\n// ---------------------------------------------------------------------------\n// Example Schema\n\nexport const requestExampleSchema = z.object({\n uid: nanoidSchema.brand<ENTITY_BRANDS['EXAMPLE']>(),\n type: z.literal('requestExample').optional().default('requestExample'),\n requestUid: z.string().brand<ENTITY_BRANDS['OPERATION']>().optional(),\n name: z.string().optional().default('Name'),\n body: exampleRequestBodySchema.optional().default({ activeBody: 'raw' }),\n parameters: z\n .object({\n path: requestExampleParametersSchema.array().default([]),\n query: requestExampleParametersSchema.array().default([]),\n headers: requestExampleParametersSchema.array().default([{ key: 'Accept', value: '*/*', enabled: true }]),\n cookies: requestExampleParametersSchema.array().default([]),\n })\n .optional()\n .default({\n path: [],\n query: [],\n headers: [{ key: 'Accept', value: '*/*', enabled: true }],\n cookies: [],\n }),\n /** TODO: Should this be deprecated? */\n serverVariables: z.record(z.string(), z.array(z.string())).optional(),\n})\n\nexport type RequestExample = z.infer<typeof requestExampleSchema>\n\n/** For OAS serialization we just store the simple key/value pairs */\nconst xScalarExampleParameterSchema = z.record(z.string(), z.string()).optional()\n\n/** Schema for the OAS serialization of request examples */\nexport const xScalarExampleSchema = z.object({\n /** TODO: Should this be required? */\n name: z.string().optional(),\n body: xScalarExampleBodySchema.optional(),\n parameters: z.object({\n path: xScalarExampleParameterSchema,\n query: xScalarExampleParameterSchema,\n headers: xScalarExampleParameterSchema,\n cookies: xScalarExampleParameterSchema,\n }),\n})\n\nexport type XScalarExample = z.infer<typeof xScalarExampleSchema>\n\n/**\n * Convert a request example to the xScalar serialized format\n *\n * TODO: The base format should be migrated to align MUCH closer to the serialized format\n */\nexport function convertExampleToXScalar(example: RequestExample) {\n const active = example.body?.activeBody\n\n const xScalarBody: XScalarExampleBody = {\n encoding: 'text/plain',\n content: '',\n }\n\n if (example.body?.activeBody === 'binary') {\n xScalarBody.encoding = 'binary'\n // TODO: Need to allow users to set these properties\n xScalarBody.file = null\n }\n\n if (active === 'formData' && example.body?.[active]) {\n const body = example.body[active]\n xScalarBody.encoding = body.encoding === 'form-data' ? 'multipart/form-data' : 'application/x-www-form-urlencoded'\n\n // TODO: Need to allow users to set these properties\n xScalarBody.content = body.value.reduce<Record<string, XScalarFormDataValue>>((map, param) => {\n /** TODO: We need to ensure only file or value is set */\n map[param.key] = param.file\n ? {\n type: 'file',\n file: null,\n }\n : {\n type: 'string',\n value: param.value,\n }\n return map\n }, {})\n }\n\n if (example.body?.activeBody === 'raw') {\n xScalarBody.encoding = contentMapping[example.body.raw?.encoding ?? 'text'] ?? 'text/plain'\n\n xScalarBody.content = example.body.raw?.value ?? ''\n }\n\n const parameters: XScalarExample['parameters'] = {}\n\n keysOf(example.parameters ?? {}).forEach((key) => {\n if (example.parameters?.[key].length) {\n parameters[key] = parameterArrayToObject(example.parameters[key])\n }\n })\n\n return xScalarExampleSchema.parse({\n /** Only add the body if we have content or the body should be a file */\n body: xScalarBody.content || xScalarBody.encoding === 'binary' ? xScalarBody : undefined,\n parameters,\n })\n}\n\n// ---------------------------------------------------------------------------\n// Example Helpers\n\n/** Create new instance parameter from a request parameter */\nexport function createParamInstance(param: RequestParameter): RequestExampleParameter {\n const schema = param.schema as any\n\n const firstExample = (() => {\n if (param.examples && !Array.isArray(param.examples) && objectKeys(param.examples).length > 0) {\n const exampleValues = Object.entries(param.examples).map(([_, example]) => {\n // returns the external value if it exists\n if (example.externalValue) {\n return example.externalValue\n }\n\n // returns the value if it exists and is defined\n // e.g. { examples: { foo: { value: 'bar' } } } would return ['bar']\n return example.value\n })\n\n // returns the first example as selected value along other examples\n return { value: exampleValues[0], examples: exampleValues }\n }\n\n // param example e.g. { example: 'foo' }\n if (isDefined(param.example)) {\n return { value: param.example }\n }\n\n // param examples e.g. { examples: ['foo', 'bar'] }\n if (Array.isArray(param.examples) && param.examples.length > 0) {\n return { value: param.examples[0] }\n }\n\n // schema example e.g. { example: 'foo' } while being discouraged\n // see https://spec.openapis.org/oas/v3.1.1.html#fixed-fields-20\n if (isDefined(schema?.example)) {\n return { value: schema.example }\n }\n\n // schema examples e.g. { examples: ['foo', 'bar'] }\n if (Array.isArray(schema?.examples) && schema.examples.length > 0) {\n // For boolean type, default to false when using schema examples\n if (schema?.type === 'boolean') {\n return { value: schema.default ?? false }\n }\n return { value: schema.examples[0] }\n }\n\n // content examples e.g. { content: { 'application/json': { examples: { foo: { value: 'bar' } } } } }\n if (param.content) {\n const firstContentType = objectKeys(param.content)[0]\n if (firstContentType) {\n const content = (param.content as ParameterContent)[firstContentType]\n if (content?.examples) {\n const firstExampleKey = Object.keys(content.examples)[0]\n if (firstExampleKey) {\n const example = content.examples[firstExampleKey]\n if (isDefined(example?.value)) {\n return { value: example.value }\n }\n }\n }\n // content example e.g. { example: 'foo' }\n if (isDefined(content?.example)) {\n return { value: content.example }\n }\n }\n }\n\n return null\n })() as null | { value: any; examples?: string[] }\n\n /**\n * TODO:\n * - Need better value defaulting here\n * - Need to handle non-string parameters much better\n * - Need to handle unions/array values for schema\n */\n const value = String(firstExample?.value ?? schema?.default ?? '')\n\n // Handle non-string enums and enums within items for array types\n const parseEnum = (() => {\n if (schema?.enum && schema?.type !== 'string') {\n return schema.enum?.map(String)\n }\n\n if (schema?.items?.enum && schema?.type === 'array') {\n return schema.items.enum.map(String)\n }\n\n return schema?.enum\n })()\n\n // Handle parameter examples\n const examples =\n firstExample?.examples ||\n (schema?.examples && schema?.type !== 'string' ? schema.examples?.map(String) : schema?.examples)\n\n // safe parse the example\n const example = schemaModel(\n {\n ...schema,\n key: param.name,\n value,\n description: param.description,\n required: param.required,\n /** Initialized all required properties to enabled */\n enabled: !!param.required,\n enum: parseEnum,\n examples,\n },\n requestExampleParametersSchema,\n false,\n )\n\n if (!example) {\n console.warn(`Example at ${param.name} is invalid.`)\n return requestExampleParametersSchema.parse({})\n }\n\n return example\n}\n\n/**\n * Create new request example from a request\n * Iterates the name of the example if provided\n */\nexport function createExampleFromRequest(request: Request, name: string, server?: Server): RequestExample {\n // ---------------------------------------------------------------------------\n // Populate all parameters with an example value\n const parameters: Record<'path' | 'cookie' | 'header' | 'query' | 'headers', RequestExampleParameter[]> = {\n path: [],\n query: [],\n cookie: [],\n // deprecated TODO: add zod transform to remove\n header: [],\n headers: [{ key: 'Accept', value: '*/*', enabled: true }],\n }\n\n // Populated the separated params\n request.parameters?.forEach((p) => parameters[p.in].push(createParamInstance(p)))\n\n // TODO: add zod transform to remove header and only support headers\n if (parameters.header.length > 0) {\n parameters.headers = parameters.header\n parameters.header = []\n }\n\n // Get content type header\n const contentTypeHeader = parameters.headers.find((h) => h.key.toLowerCase() === 'content-type')\n\n // ---------------------------------------------------------------------------\n // Handle request body defaulting for various content type encodings\n const body: ExampleRequestBody = {\n activeBody: 'raw',\n }\n\n // If we have a request body or a content type header\n // TODO: we don't even handle path parameters here\n if (request.requestBody || contentTypeHeader?.value) {\n const requestBody = getRequestBodyFromOperation(request)\n const contentType = request.requestBody ? requestBody?.mimeType : contentTypeHeader?.value\n\n // Handle JSON and JSON-like mimetypes\n if (contentType?.includes('/json') || contentType?.endsWith('+json')) {\n body.activeBody = 'raw'\n body.raw = {\n encoding: 'json',\n mimeType: contentType,\n value: requestBody?.text ?? JSON.stringify({}),\n }\n }\n\n if (contentType === 'application/xml') {\n body.activeBody = 'raw'\n body.raw = {\n encoding: 'xml',\n value: requestBody?.text ?? '',\n }\n }\n\n /**\n * TODO: Are we loading example files from somewhere based on the spec?\n * How are we handling the body values\n */\n if (contentType === 'application/octet-stream') {\n body.activeBody = 'binary'\n body.binary = undefined\n }\n\n if (contentType === 'application/x-www-form-urlencoded' || contentType === 'multipart/form-data') {\n body.activeBody = 'formData'\n body.formData = {\n encoding: contentType === 'application/x-www-form-urlencoded' ? 'urlencoded' : 'form-data',\n value: (requestBody?.params || []).map((param) => {\n if (param.value instanceof File) {\n return {\n key: param.name,\n value: 'BINARY',\n file: param.value,\n enabled: true,\n }\n }\n return {\n key: param.name,\n value: param.value || '',\n enabled: true,\n }\n }),\n }\n }\n\n if (contentType?.startsWith('text/')) {\n body.activeBody = 'raw'\n body.raw = {\n encoding: 'text',\n value: requestBody?.text ?? '',\n }\n }\n\n // Add the content-type header if it doesn't exist and if it's not multipart request\n if (requestBody?.mimeType && !contentTypeHeader && !requestBody.mimeType.startsWith('multipart/')) {\n parameters.headers.push({\n key: 'Content-Type',\n value: requestBody.mimeType,\n enabled: true,\n })\n }\n }\n\n const serverVariables = server ? getServerVariableExamples(server) : {}\n\n // safe parse the example\n const example = schemaModel(\n {\n requestUid: request.uid,\n parameters,\n name,\n body,\n serverVariables,\n },\n requestExampleSchema,\n false,\n )\n\n if (!example) {\n console.warn(`Example at ${request.uid} is invalid.`)\n return requestExampleSchema.parse({})\n }\n return example\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AACvB,SAA6B,oBAAoB;AACjD,SAAS,SAAS;AAElB,SAAS,mBAAmB;AAC5B,SAAS,mCAAmC;AAC5C,SAAS,iCAAiC;AAenC,MAAM,iCAAiC,EAC3C,OAAO;AAAA,EACN,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE;AAAA,EAC1B,OAAO,EAAE,OAAO,OAAO,EAAE,QAAQ,EAAE;AAAA,EACnC,SAAS,EAAE,QAAQ,EAAE,QAAQ,IAAI;AAAA,EACjC,MAAM,EAAE,IAAI,EAAE,SAAS;AAAA,EACvB,aAAa,EAAE,OAAO,EAAE,SAAS;AAAA,EACjC,UAAU,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC/B,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS;AAAA,EACnC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,SAAS;AAAA,EACpC,MAAM,EACH,MAAM;AAAA;AAAA,IAEL,EAAE,OAAO;AAAA;AAAA,IAET,EAAE,MAAM,EAAE,OAAO,CAAC;AAAA,EACpB,CAAC,EACA,SAAS;AAAA,EACZ,QAAQ,EAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,SAAS,EAAE,IAAI,EAAE,SAAS;AAAA,EAC1B,UAAU,EAAE,QAAQ,EAAE,SAAS;AACjC,CAAC,EAEA,UAAU,CAAC,UAAU;AACpB,QAAM,OAAO,EAAE,GAAG,MAAM;AAGxB,MAAI,MAAM,QAAQ,KAAK,IAAI,KAAK,KAAK,KAAK,SAAS,MAAM,GAAG;AAC1D,SAAK,WAAW;AAAA,EAClB;AAGA,MAAI,MAAM,QAAQ,KAAK,IAAI,KAAK,KAAK,KAAK,WAAW,KAAK,KAAK,KAAK,SAAS,MAAM,GAAG;AACpF,SAAK,OAAO,KAAK,KAAK,KAAK,CAAC,SAAS,SAAS,MAAM;AAAA,EACtD;AAEA,SAAO;AACT,CAAC;AAGI,MAAM,yBAAyB,CAAC,WACrC,OAAO,OAA+B,CAAC,KAAK,UAAU;AACpD,MAAI,MAAM,GAAG,IAAI,MAAM;AACvB,SAAO;AACT,GAAG,CAAC,CAAC;
|
|
4
|
+
"sourcesContent": ["import { isDefined } from '@scalar/helpers/array/is-defined'\nimport { objectKeys } from '@scalar/helpers/object/object-keys'\nimport { keysOf } from '@scalar/object-utils/arrays'\nimport { type ENTITY_BRANDS, nanoidSchema } from '@scalar/types/utils'\nimport { z } from 'zod'\n\nimport { schemaModel } from '@/helpers/schema-model'\nimport { getRequestBodyFromOperation } from '@/spec-getters/get-request-body-from-operation'\nimport { getServerVariableExamples } from '@/spec-getters/get-server-variable-examples'\n\nimport type { ParameterContent, RequestParameter } from './parameters'\nimport type { Request } from './requests'\nimport type { Server } from './server'\n\n// ---------------------------------------------------------------------------\n// Example Parameters\n\n/**\n * TODO: Deprecate this.\n *\n * The request schema should be stored in the request and any\n * parameters should be validated against that\n */\nexport const requestExampleParametersSchema = z\n .object({\n key: z.string().default(''),\n value: z.coerce.string().default(''),\n enabled: z.boolean().default(true),\n file: z.any().optional(),\n description: z.string().optional(),\n required: z.boolean().optional(),\n enum: z.array(z.string()).optional(),\n examples: z.array(z.any()).optional(),\n type: z\n .union([\n // 'string'\n z.string(),\n // ['string', 'null']\n z.array(z.string()),\n ])\n .optional(),\n format: z.string().optional(),\n minimum: z.number().optional(),\n maximum: z.number().optional(),\n default: z.any().optional(),\n nullable: z.boolean().optional(),\n })\n // set nullable: to true if type is ['string', 'null']\n .transform((_data) => {\n const data = { ..._data }\n\n // type: ['string', 'null'] -> nullable: true\n if (Array.isArray(data.type) && data.type.includes('null')) {\n data.nullable = true\n }\n\n // Hey, if it's just one value and 'null', we can make it a string and ditch the 'null'.\n if (Array.isArray(data.type) && data.type.length === 2 && data.type.includes('null')) {\n data.type = data.type.find((item) => item !== 'null')\n }\n\n return data\n })\n\n/** Convert the array of parameters to an object keyed by the parameter name */\nexport const parameterArrayToObject = (params: RequestExampleParameter[]) =>\n params.reduce<Record<string, string>>((map, param) => {\n map[param.key] = param.value\n return map\n }, {})\n\n/** Request examples - formerly known as instances - are \"children\" of requests */\nexport type RequestExampleParameter = z.infer<typeof requestExampleParametersSchema>\n\nconst xScalarFileValueSchema = z\n .object({\n url: z.string(),\n base64: z.string().optional(),\n })\n .nullable()\n\n/**\n * When files are required for an example we provide the options\n * to provide a public URL or a base64 encoded string\n */\n// not used but kept for consistency\n// export type XScalarFileValue = z.infer<typeof xScalarFileValueSchema>\n\n/**\n * Schema for the OAS serialization of request example parameters\n *\n * File values can be optionally fetched on import OR inserted as a base64 encoded string\n */\nconst xScalarFormDataValue = z.union([\n z.object({\n type: z.literal('string'),\n value: z.string(),\n }),\n z.object({\n type: z.literal('file'),\n file: xScalarFileValueSchema,\n }),\n])\n\ntype XScalarFormDataValue = z.infer<typeof xScalarFormDataValue>\n\n// ---------------------------------------------------------------------------\n// Example Body\n\n/**\n * Possible encodings for example request bodies when using text formats\n *\n * TODO: This list may not be comprehensive enough\n */\nconst exampleRequestBodyEncoding = ['json', 'text', 'html', 'javascript', 'xml', 'yaml', 'edn'] as const\n\ntype BodyEncoding = (typeof exampleRequestBodyEncoding)[number]\n\nconst exampleBodyMime = [\n 'application/json',\n 'text/plain',\n 'text/html',\n 'application/javascript',\n 'application/xml',\n 'application/yaml',\n 'application/edn',\n 'application/octet-stream',\n 'application/x-www-form-urlencoded',\n 'multipart/form-data',\n /** Used for direct files */\n 'binary',\n] as const\n\ntype BodyMime = (typeof exampleBodyMime)[number]\n\nconst contentMapping: Record<BodyEncoding, BodyMime> = {\n json: 'application/json',\n text: 'text/plain',\n html: 'text/html',\n javascript: 'application/javascript',\n xml: 'application/xml',\n yaml: 'application/yaml',\n edn: 'application/edn',\n} as const\n\n/**\n * TODO: Migrate away from this layout to the format used in the extension\n *\n * If a user changes the encoding of the body we expect the content to change as well\n */\nconst exampleRequestBodySchema = z.object({\n raw: z\n .object({\n encoding: z.enum(exampleRequestBodyEncoding),\n value: z.string().default(''),\n mimeType: z.string().optional(),\n })\n .optional(),\n formData: z\n .object({\n encoding: z.union([z.literal('form-data'), z.literal('urlencoded')]).default('form-data'),\n value: requestExampleParametersSchema.array().default([]),\n })\n .optional(),\n binary: z.instanceof(Blob).optional(),\n activeBody: z.union([z.literal('raw'), z.literal('formData'), z.literal('binary')]).default('raw'),\n})\n\ntype ExampleRequestBody = z.infer<typeof exampleRequestBodySchema>\n\n/** Schema for the OAS serialization of request example bodies */\nconst xScalarExampleBodySchema = z.object({\n encoding: z.enum(exampleBodyMime),\n /**\n * Body content as an object with a separately specified encoding or a simple pre-encoded string value\n *\n * Ideally we would convert any objects into the proper encoding on import\n */\n content: z.union([z.record(z.string(), z.any()), z.string()]),\n /** When the encoding is `binary` this will be used to link to the file */\n file: xScalarFileValueSchema.optional(),\n})\n\ntype XScalarExampleBody = z.infer<typeof xScalarExampleBodySchema>\n\n// ---------------------------------------------------------------------------\n// Example Schema\n\nexport const requestExampleSchema = z.object({\n uid: nanoidSchema.brand<ENTITY_BRANDS['EXAMPLE']>(),\n type: z.literal('requestExample').optional().default('requestExample'),\n requestUid: z.string().brand<ENTITY_BRANDS['OPERATION']>().optional(),\n name: z.string().optional().default('Name'),\n body: exampleRequestBodySchema.optional().default({ activeBody: 'raw' }),\n parameters: z\n .object({\n path: requestExampleParametersSchema.array().default([]),\n query: requestExampleParametersSchema.array().default([]),\n headers: requestExampleParametersSchema.array().default([{ key: 'Accept', value: '*/*', enabled: true }]),\n cookies: requestExampleParametersSchema.array().default([]),\n })\n .optional()\n .default({\n path: [],\n query: [],\n headers: [{ key: 'Accept', value: '*/*', enabled: true }],\n cookies: [],\n }),\n /** TODO: Should this be deprecated? */\n serverVariables: z.record(z.string(), z.array(z.string())).optional(),\n})\n\nexport type RequestExample = z.infer<typeof requestExampleSchema>\n\n/** For OAS serialization we just store the simple key/value pairs */\nconst xScalarExampleParameterSchema = z.record(z.string(), z.string()).optional()\n\n/** Schema for the OAS serialization of request examples */\nexport const xScalarExampleSchema = z.object({\n /** TODO: Should this be required? */\n name: z.string().optional(),\n body: xScalarExampleBodySchema.optional(),\n parameters: z.object({\n path: xScalarExampleParameterSchema,\n query: xScalarExampleParameterSchema,\n headers: xScalarExampleParameterSchema,\n cookies: xScalarExampleParameterSchema,\n }),\n})\n\ntype XScalarExample = z.infer<typeof xScalarExampleSchema>\n\n/**\n * Convert a request example to the xScalar serialized format\n *\n * TODO: The base format should be migrated to align MUCH closer to the serialized format\n */\nexport function convertExampleToXScalar(example: RequestExample) {\n const active = example.body?.activeBody\n\n const xScalarBody: XScalarExampleBody = {\n encoding: 'text/plain',\n content: '',\n }\n\n if (example.body?.activeBody === 'binary') {\n xScalarBody.encoding = 'binary'\n // TODO: Need to allow users to set these properties\n xScalarBody.file = null\n }\n\n if (active === 'formData' && example.body?.[active]) {\n const body = example.body[active]\n xScalarBody.encoding = body.encoding === 'form-data' ? 'multipart/form-data' : 'application/x-www-form-urlencoded'\n\n // TODO: Need to allow users to set these properties\n xScalarBody.content = body.value.reduce<Record<string, XScalarFormDataValue>>((map, param) => {\n /** TODO: We need to ensure only file or value is set */\n map[param.key] = param.file\n ? {\n type: 'file',\n file: null,\n }\n : {\n type: 'string',\n value: param.value,\n }\n return map\n }, {})\n }\n\n if (example.body?.activeBody === 'raw') {\n xScalarBody.encoding = contentMapping[example.body.raw?.encoding ?? 'text'] ?? 'text/plain'\n\n xScalarBody.content = example.body.raw?.value ?? ''\n }\n\n const parameters: XScalarExample['parameters'] = {}\n\n keysOf(example.parameters ?? {}).forEach((key) => {\n if (example.parameters?.[key].length) {\n parameters[key] = parameterArrayToObject(example.parameters[key])\n }\n })\n\n return xScalarExampleSchema.parse({\n /** Only add the body if we have content or the body should be a file */\n body: xScalarBody.content || xScalarBody.encoding === 'binary' ? xScalarBody : undefined,\n parameters,\n })\n}\n\n// ---------------------------------------------------------------------------\n// Example Helpers\n\n/** Create new instance parameter from a request parameter */\nexport function createParamInstance(param: RequestParameter): RequestExampleParameter {\n const schema = param.schema as any\n\n const firstExample = (() => {\n if (param.examples && !Array.isArray(param.examples) && objectKeys(param.examples).length > 0) {\n const exampleValues = Object.entries(param.examples).map(([_, example]) => {\n // returns the external value if it exists\n if (example.externalValue) {\n return example.externalValue\n }\n\n // returns the value if it exists and is defined\n // e.g. { examples: { foo: { value: 'bar' } } } would return ['bar']\n return example.value\n })\n\n // returns the first example as selected value along other examples\n return { value: exampleValues[0], examples: exampleValues }\n }\n\n // param example e.g. { example: 'foo' }\n if (isDefined(param.example)) {\n return { value: param.example }\n }\n\n // param examples e.g. { examples: ['foo', 'bar'] }\n if (Array.isArray(param.examples) && param.examples.length > 0) {\n return { value: param.examples[0] }\n }\n\n // schema example e.g. { example: 'foo' } while being discouraged\n // see https://spec.openapis.org/oas/v3.1.1.html#fixed-fields-20\n if (isDefined(schema?.example)) {\n return { value: schema.example }\n }\n\n // schema examples e.g. { examples: ['foo', 'bar'] }\n if (Array.isArray(schema?.examples) && schema.examples.length > 0) {\n // For boolean type, default to false when using schema examples\n if (schema?.type === 'boolean') {\n return { value: schema.default ?? false }\n }\n return { value: schema.examples[0] }\n }\n\n // content examples e.g. { content: { 'application/json': { examples: { foo: { value: 'bar' } } } } }\n if (param.content) {\n const firstContentType = objectKeys(param.content)[0]\n if (firstContentType) {\n const content = (param.content as ParameterContent)[firstContentType]\n if (content?.examples) {\n const firstExampleKey = Object.keys(content.examples)[0]\n if (firstExampleKey) {\n const example = content.examples[firstExampleKey]\n if (isDefined(example?.value)) {\n return { value: example.value }\n }\n }\n }\n // content example e.g. { example: 'foo' }\n if (isDefined(content?.example)) {\n return { value: content.example }\n }\n }\n }\n\n return null\n })() as null | { value: any; examples?: string[] }\n\n /**\n * TODO:\n * - Need better value defaulting here\n * - Need to handle non-string parameters much better\n * - Need to handle unions/array values for schema\n */\n const value = String(firstExample?.value ?? schema?.default ?? '')\n\n // Handle non-string enums and enums within items for array types\n const parseEnum = (() => {\n if (schema?.enum && schema?.type !== 'string') {\n return schema.enum?.map(String)\n }\n\n if (schema?.items?.enum && schema?.type === 'array') {\n return schema.items.enum.map(String)\n }\n\n return schema?.enum\n })()\n\n // Handle parameter examples\n const examples =\n firstExample?.examples ||\n (schema?.examples && schema?.type !== 'string' ? schema.examples?.map(String) : schema?.examples)\n\n // safe parse the example\n const example = schemaModel(\n {\n ...schema,\n key: param.name,\n value,\n description: param.description,\n required: param.required,\n /** Initialized all required properties to enabled */\n enabled: !!param.required,\n enum: parseEnum,\n examples,\n },\n requestExampleParametersSchema,\n false,\n )\n\n if (!example) {\n console.warn(`Example at ${param.name} is invalid.`)\n return requestExampleParametersSchema.parse({})\n }\n\n return example\n}\n\n/**\n * Create new request example from a request\n * Iterates the name of the example if provided\n */\nexport function createExampleFromRequest(request: Request, name: string, server?: Server): RequestExample {\n // ---------------------------------------------------------------------------\n // Populate all parameters with an example value\n const parameters: Record<'path' | 'cookie' | 'header' | 'query' | 'headers', RequestExampleParameter[]> = {\n path: [],\n query: [],\n cookie: [],\n // deprecated TODO: add zod transform to remove\n header: [],\n headers: [{ key: 'Accept', value: '*/*', enabled: true }],\n }\n\n // Populated the separated params\n request.parameters?.forEach((p) => parameters[p.in].push(createParamInstance(p)))\n\n // TODO: add zod transform to remove header and only support headers\n if (parameters.header.length > 0) {\n parameters.headers = parameters.header\n parameters.header = []\n }\n\n // Get content type header\n const contentTypeHeader = parameters.headers.find((h) => h.key.toLowerCase() === 'content-type')\n\n // ---------------------------------------------------------------------------\n // Handle request body defaulting for various content type encodings\n const body: ExampleRequestBody = {\n activeBody: 'raw',\n }\n\n // If we have a request body or a content type header\n // TODO: we don't even handle path parameters here\n if (request.requestBody || contentTypeHeader?.value) {\n const requestBody = getRequestBodyFromOperation(request)\n const contentType = request.requestBody ? requestBody?.mimeType : contentTypeHeader?.value\n\n // Handle JSON and JSON-like mimetypes\n if (contentType?.includes('/json') || contentType?.endsWith('+json')) {\n body.activeBody = 'raw'\n body.raw = {\n encoding: 'json',\n mimeType: contentType,\n value: requestBody?.text ?? JSON.stringify({}),\n }\n }\n\n if (contentType === 'application/xml') {\n body.activeBody = 'raw'\n body.raw = {\n encoding: 'xml',\n value: requestBody?.text ?? '',\n }\n }\n\n /**\n * TODO: Are we loading example files from somewhere based on the spec?\n * How are we handling the body values\n */\n if (contentType === 'application/octet-stream') {\n body.activeBody = 'binary'\n body.binary = undefined\n }\n\n if (contentType === 'application/x-www-form-urlencoded' || contentType === 'multipart/form-data') {\n body.activeBody = 'formData'\n body.formData = {\n encoding: contentType === 'application/x-www-form-urlencoded' ? 'urlencoded' : 'form-data',\n value: (requestBody?.params || []).map((param) => {\n if (param.value instanceof File) {\n return {\n key: param.name,\n value: 'BINARY',\n file: param.value,\n enabled: true,\n }\n }\n return {\n key: param.name,\n value: param.value || '',\n enabled: true,\n }\n }),\n }\n }\n\n if (contentType?.startsWith('text/')) {\n body.activeBody = 'raw'\n body.raw = {\n encoding: 'text',\n value: requestBody?.text ?? '',\n }\n }\n\n // Add the content-type header if it doesn't exist and if it's not multipart request\n if (requestBody?.mimeType && !contentTypeHeader && !requestBody.mimeType.startsWith('multipart/')) {\n parameters.headers.push({\n key: 'Content-Type',\n value: requestBody.mimeType,\n enabled: true,\n })\n }\n }\n\n const serverVariables = server ? getServerVariableExamples(server) : {}\n\n // safe parse the example\n const example = schemaModel(\n {\n requestUid: request.uid,\n parameters,\n name,\n body,\n serverVariables,\n },\n requestExampleSchema,\n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,IAAI,CAAC;AAGtE,QAAM,UAAU;AAAA,IACd;AAAA,MACE,YAAY,QAAQ;AAAA,MACpB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,MAAI,CAAC,SAAS;AACZ,YAAQ,KAAK,cAAc,QAAQ,GAAG,cAAc;AACpD,WAAO,qBAAqB,MAAM,CAAC,CAAC;AAAA,EACtC;AACA,SAAO;AACT;",
|
|
6
6
|
"names": ["example"]
|
|
7
7
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
1
|
import { type PostResponseSchema, XPostResponseSchema } from '@scalar/openapi-types/schemas/extensions';
|
|
3
|
-
import { XScalarStability } from '@scalar/types';
|
|
2
|
+
import { XScalarStability } from '@scalar/types/legacy';
|
|
3
|
+
import { z } from 'zod';
|
|
4
4
|
import { type RequestExample } from './request-examples.js';
|
|
5
|
-
|
|
5
|
+
declare const requestMethods: readonly ["delete", "get", "head", "options", "patch", "post", "put", "trace"];
|
|
6
6
|
export type RequestMethod = (typeof requestMethods)[number];
|
|
7
7
|
/** A single set of populated values for a sent request */
|
|
8
8
|
export type ResponseInstance = Omit<Response, 'headers'> & {
|
|
@@ -35,89 +35,6 @@ export type RequestEvent = {
|
|
|
35
35
|
response: ResponseInstance;
|
|
36
36
|
timestamp: number;
|
|
37
37
|
};
|
|
38
|
-
/** Open API Compliant Request Validator */
|
|
39
|
-
export declare const oasRequestSchema: z.ZodObject<{
|
|
40
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
41
|
-
summary: z.ZodOptional<z.ZodString>;
|
|
42
|
-
description: z.ZodOptional<z.ZodString>;
|
|
43
|
-
operationId: z.ZodOptional<z.ZodString>;
|
|
44
|
-
security: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString>>>>>>;
|
|
45
|
-
requestBody: z.ZodOptional<z.ZodAny>;
|
|
46
|
-
parameters: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
47
|
-
in: z.ZodEnum<{
|
|
48
|
-
cookie: "cookie";
|
|
49
|
-
path: "path";
|
|
50
|
-
query: "query";
|
|
51
|
-
header: "header";
|
|
52
|
-
}>;
|
|
53
|
-
name: z.ZodString;
|
|
54
|
-
description: z.ZodOptional<z.ZodString>;
|
|
55
|
-
required: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
56
|
-
deprecated: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
57
|
-
schema: z.ZodOptional<z.ZodUnknown>;
|
|
58
|
-
content: z.ZodOptional<z.ZodUnknown>;
|
|
59
|
-
style: z.ZodOptional<z.ZodEnum<{
|
|
60
|
-
matrix: "matrix";
|
|
61
|
-
label: "label";
|
|
62
|
-
form: "form";
|
|
63
|
-
simple: "simple";
|
|
64
|
-
spaceDelimited: "spaceDelimited";
|
|
65
|
-
pipeDelimited: "pipeDelimited";
|
|
66
|
-
deepObject: "deepObject";
|
|
67
|
-
}>>;
|
|
68
|
-
explode: z.ZodOptional<z.ZodBoolean>;
|
|
69
|
-
example: z.ZodOptional<z.ZodUnknown>;
|
|
70
|
-
examples: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
71
|
-
value: z.ZodOptional<z.ZodUnknown>;
|
|
72
|
-
summary: z.ZodOptional<z.ZodString>;
|
|
73
|
-
externalValue: z.ZodOptional<z.ZodString>;
|
|
74
|
-
}, z.core.$strip>>, z.ZodArray<z.ZodUnknown>]>>;
|
|
75
|
-
}, z.core.$strip>>>;
|
|
76
|
-
externalDocs: z.ZodOptional<z.ZodPipe<z.ZodObject<{
|
|
77
|
-
description: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
78
|
-
url: z.ZodString;
|
|
79
|
-
}, z.core.$strip>, z.ZodTransform<{
|
|
80
|
-
url: string;
|
|
81
|
-
description?: string | undefined;
|
|
82
|
-
}, {
|
|
83
|
-
url: string;
|
|
84
|
-
description?: string | undefined;
|
|
85
|
-
}>>>;
|
|
86
|
-
deprecated: z.ZodOptional<z.ZodBoolean>;
|
|
87
|
-
responses: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
88
|
-
callbacks: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>>>>;
|
|
89
|
-
'x-scalar-examples': z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
90
|
-
name: z.ZodOptional<z.ZodString>;
|
|
91
|
-
body: z.ZodOptional<z.ZodObject<{
|
|
92
|
-
encoding: z.ZodEnum<{
|
|
93
|
-
binary: "binary";
|
|
94
|
-
"application/json": "application/json";
|
|
95
|
-
"text/plain": "text/plain";
|
|
96
|
-
"text/html": "text/html";
|
|
97
|
-
"application/javascript": "application/javascript";
|
|
98
|
-
"application/xml": "application/xml";
|
|
99
|
-
"application/yaml": "application/yaml";
|
|
100
|
-
"application/edn": "application/edn";
|
|
101
|
-
"application/octet-stream": "application/octet-stream";
|
|
102
|
-
"application/x-www-form-urlencoded": "application/x-www-form-urlencoded";
|
|
103
|
-
"multipart/form-data": "multipart/form-data";
|
|
104
|
-
}>;
|
|
105
|
-
content: z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodString]>;
|
|
106
|
-
file: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
107
|
-
url: z.ZodString;
|
|
108
|
-
base64: z.ZodOptional<z.ZodString>;
|
|
109
|
-
}, z.core.$strip>>>;
|
|
110
|
-
}, z.core.$strip>>;
|
|
111
|
-
parameters: z.ZodObject<{
|
|
112
|
-
path: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
113
|
-
query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
114
|
-
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
115
|
-
cookies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
116
|
-
}, z.core.$strip>;
|
|
117
|
-
}, z.core.$strip>>>;
|
|
118
|
-
'x-internal': z.ZodOptional<z.ZodBoolean>;
|
|
119
|
-
'x-scalar-ignore': z.ZodOptional<z.ZodBoolean>;
|
|
120
|
-
}, z.core.$strip>;
|
|
121
38
|
export type PostResponseScript = z.infer<typeof PostResponseSchema>;
|
|
122
39
|
export type PostResponseScripts = z.infer<typeof XPostResponseSchema>['x-post-response'];
|
|
123
40
|
/** Unified request schema for client usage */
|
|
@@ -194,7 +111,7 @@ export declare const requestSchema: z.ZodObject<{
|
|
|
194
111
|
stable: XScalarStability.Stable;
|
|
195
112
|
}>>>;
|
|
196
113
|
type: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"request">>>;
|
|
197
|
-
uid: z.core.$ZodBranded<z.ZodDefault<z.
|
|
114
|
+
uid: z.core.$ZodBranded<z.ZodDefault<z.ZodString>, "operation">;
|
|
198
115
|
path: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
199
116
|
method: z.ZodDefault<z.ZodEnum<{
|
|
200
117
|
delete: "delete";
|
|
@@ -214,4 +131,5 @@ export declare const requestSchema: z.ZodObject<{
|
|
|
214
131
|
}, z.core.$strip>;
|
|
215
132
|
export type Request = z.infer<typeof requestSchema>;
|
|
216
133
|
export type RequestPayload = z.input<typeof requestSchema>;
|
|
134
|
+
export {};
|
|
217
135
|
//# sourceMappingURL=requests.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requests.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/requests.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"requests.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/requests.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAEvB,mBAAmB,EACpB,MAAM,0CAA0C,CAAA;AAEjD,OAAO,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AAC,CAAC,iBAAiB,CAAC,CAAA;AAExF,8CAA8C;AAC9C,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAKG,CAAA;AAE7B,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAA;AACnD,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAA"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { selectedSecuritySchemeUidSchema } from "../../entities/shared/utility.js";
|
|
2
|
-
import { nanoidSchema } from "@scalar/types/utils";
|
|
3
|
-
import { z } from "zod";
|
|
4
1
|
import {
|
|
5
2
|
XCodeSamplesSchema,
|
|
6
3
|
XPostResponseSchema
|
|
7
4
|
} from "@scalar/openapi-types/schemas/extensions";
|
|
8
|
-
import { XScalarStability } from "@scalar/types";
|
|
9
5
|
import { oasSecurityRequirementSchema } from "@scalar/types/entities";
|
|
6
|
+
import { XScalarStability } from "@scalar/types/legacy";
|
|
7
|
+
import { nanoidSchema } from "@scalar/types/utils";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { selectedSecuritySchemeUidSchema } from "../../entities/shared/utility.js";
|
|
10
10
|
import { oasParameterSchema } from "./parameters.js";
|
|
11
11
|
import { xScalarExampleSchema } from "./request-examples.js";
|
|
12
12
|
import { oasExternalDocumentationSchema } from "./spec-objects.js";
|
|
@@ -86,8 +86,6 @@ const extendedRequestSchema = z.object({
|
|
|
86
86
|
});
|
|
87
87
|
const requestSchema = oasRequestSchema.omit({ "x-scalar-examples": true }).merge(XCodeSamplesSchema).merge(ScalarStabilitySchema).merge(extendedRequestSchema).merge(XPostResponseSchema);
|
|
88
88
|
export {
|
|
89
|
-
oasRequestSchema,
|
|
90
|
-
requestMethods,
|
|
91
89
|
requestSchema
|
|
92
90
|
};
|
|
93
91
|
//# sourceMappingURL=requests.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/entities/spec/requests.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": "AAAA
|
|
4
|
+
"sourcesContent": ["import {\n type PostResponseSchema,\n XCodeSamplesSchema,\n XPostResponseSchema,\n} from '@scalar/openapi-types/schemas/extensions'\nimport { oasSecurityRequirementSchema } from '@scalar/types/entities'\nimport { XScalarStability } from '@scalar/types/legacy'\nimport { type ENTITY_BRANDS, nanoidSchema } from '@scalar/types/utils'\nimport { type ZodSchema, z } from 'zod'\n\nimport { selectedSecuritySchemeUidSchema } from '@/entities/shared/utility'\n\nimport { oasParameterSchema } from './parameters'\nimport { type RequestExample, xScalarExampleSchema } from './request-examples'\nimport { oasExternalDocumentationSchema } from './spec-objects'\n\nconst requestMethods = ['delete', 'get', 'head', 'options', 'patch', 'post', 'put', 'trace'] as const\n\nexport type RequestMethod = (typeof requestMethods)[number]\n\n/** A single set of populated values for a sent request */\nexport type ResponseInstance = Omit<Response, 'headers'> & {\n /** Store headers as an object to match what we had with axios */\n headers: Record<string, string>\n /** Keys of headers which set cookies */\n cookieHeaderKeys: string[]\n /** Time in ms the request took */\n duration: number\n /** The response status */\n status: number\n /** The response status text */\n statusText: string\n /** The response method */\n method: RequestMethod\n /** The request path */\n path: string\n} & (\n | {\n /** The response data */\n data: string | Blob\n /** The response size in bytes */\n size: number\n }\n | {\n /** A stream reader for a streamable response body */\n reader: ReadableStreamDefaultReader<Uint8Array>\n }\n )\n\n/** A single request/response set to save to the history stack */\nexport type RequestEvent = {\n request: RequestExample\n response: ResponseInstance\n timestamp: number\n}\n\n// TODO: Type body definitions\ntype RequestBody = object\nconst requestBodySchema = z.any() satisfies ZodSchema<RequestBody>\n\n/** Open API Compliant Request Validator */\nconst oasRequestSchema = z.object({\n /**\n * A list of tags for API documentation control. Tags can be used for logical\n * grouping of operations by resources or any other qualifier.\n *\n * These tags are the openapi spec tag names, not uids\n */\n 'tags': z.string().array().optional(),\n /** A short summary of what the operation does. */\n 'summary': z.string().optional(),\n /** A verbose explanation of the operation behavior. CommonMark syntax MAY be used for rich text representation. */\n 'description': z.string().optional(),\n /**\n * Unique string used to identify the operation. The id MUST be unique among all operations described in the API.\n * The operationId value is case-sensitive. Tools and libraries MAY use the operationId to uniquely identify an\n * operation, therefore, it is RECOMMENDED to follow bin common programming naming conventions./\n */\n 'operationId': z.string().optional(),\n /**\n * A declaration of which security mechanisms can be used across the API. The list of\n * values includes alternative security requirement objects that can be used. Only\n * one of the security requirement objects need to be satisfied to authorize a request.\n * Individual operations can override this definition. To make security optional, an empty\n * security requirement ({}) can be included in the array.\n */\n 'security': z.array(oasSecurityRequirementSchema).optional(),\n /**\n * The request body applicable for this operation. The requestBody is fully supported in HTTP methods where the\n * HTTP 1.1 specification [RFC7231] has explicitly defined semantics for request bodies. In other cases where the\n * HTTP spec is vague (such as GET, HEAD and DELETE), requestBody is permitted but does not have well-defined\n * semantics and SHOULD be avoided if possible.\n */\n 'requestBody': requestBodySchema.optional(),\n /**\n * Request parameters\n */\n 'parameters': oasParameterSchema.array().optional(),\n /**\n * External documentation object\n */\n 'externalDocs': oasExternalDocumentationSchema.optional(),\n 'deprecated': z.boolean().optional(),\n /** Response formats */\n 'responses': z.record(z.string(), z.any()).optional(),\n /** Callbacks */\n 'callbacks': z.record(z.string(), z.record(z.string(), z.record(z.string(), z.any()))).optional(),\n /** xScalar examples */\n 'x-scalar-examples': z.record(z.string(), xScalarExampleSchema).optional(),\n /** Hide operations */\n 'x-internal': z.boolean().optional(),\n /** Ignore operations */\n 'x-scalar-ignore': z.boolean().optional(),\n})\n\n/**\n * An OpenAPI extension to indicate the stability of the operation\n *\n * @example\n * ```yaml\n * x-scalar-stability: deprecated\n * ```\n */\nconst ScalarStabilitySchema = z.object({\n 'x-scalar-stability': z\n .enum([XScalarStability.Deprecated, XScalarStability.Experimental, XScalarStability.Stable])\n .optional()\n .catch(undefined),\n})\n\n/**\n * Extended properties added to the spec definition for client usage\n *\n * WARNING: DO NOT ADD PROPERTIES THAT SHARE A NAME WITH OAS OPERATION ENTITIES\n *\n * This object is directly converted to a spec operation during saving\n */\nconst extendedRequestSchema = z.object({\n type: z.literal('request').optional().default('request'),\n uid: nanoidSchema.brand<ENTITY_BRANDS['OPERATION']>(),\n /** Path Key */\n path: z.string().optional().default(''),\n /** Request Method */\n method: z.enum(requestMethods).default('get'),\n /** List of server UIDs specific to the request */\n servers: z.string().brand<ENTITY_BRANDS['SERVER']>().array().default([]),\n /** The currently selected server */\n selectedServerUid: z.string().brand<ENTITY_BRANDS['SERVER']>().optional().nullable().default(null),\n /** List of example UIDs associated with the request */\n examples: z.string().brand<ENTITY_BRANDS['EXAMPLE']>().array().default([]),\n /** List of security scheme UIDs associated with the request */\n selectedSecuritySchemeUids: selectedSecuritySchemeUidSchema,\n})\n\nexport type PostResponseScript = z.infer<typeof PostResponseSchema>\nexport type PostResponseScripts = z.infer<typeof XPostResponseSchema>['x-post-response']\n\n/** Unified request schema for client usage */\nexport const requestSchema = oasRequestSchema\n .omit({ 'x-scalar-examples': true })\n .merge(XCodeSamplesSchema)\n .merge(ScalarStabilitySchema)\n .merge(extendedRequestSchema)\n .merge(XPostResponseSchema)\n\nexport type Request = z.infer<typeof requestSchema>\nexport type RequestPayload = z.input<typeof requestSchema>\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EAEE;AAAA,EACA;AAAA,OACK;AACP,SAAS,oCAAoC;AAC7C,SAAS,wBAAwB;AACjC,SAA6B,oBAAoB;AACjD,SAAyB,SAAS;AAElC,SAAS,uCAAuC;AAEhD,SAAS,0BAA0B;AACnC,SAA8B,4BAA4B;AAC1D,SAAS,sCAAsC;AAE/C,MAAM,iBAAiB,CAAC,UAAU,OAAO,QAAQ,WAAW,SAAS,QAAQ,OAAO,OAAO;AA0C3F,MAAM,oBAAoB,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AC;AASD,MAAM,wBAAwB,EAAE,OAAO;AAAA,EACrC,MAAM,EAAE,QAAQ,SAAS,EAAE,SAAS,EAAE,QAAQ,SAAS;AAAA,EACvD,KAAK,aAAa,MAAkC;AAAA;AAAA,EAEpD,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE;AAAA;AAAA,EAEtC,QAAQ,EAAE,KAAK,cAAc,EAAE,QAAQ,KAAK;AAAA;AAAA,EAE5C,SAAS,EAAE,OAAO,EAAE,MAA+B,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;AAAA;AAAA,EAEvE,mBAAmB,EAAE,OAAO,EAAE,MAA+B,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,IAAI;AAAA;AAAA,EAEjG,UAAU,EAAE,OAAO,EAAE,MAAgC,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;AAAA;AAAA,EAEzE,4BAA4B;AAC9B,CAAC;AAMM,MAAM,gBAAgB,iBAC1B,KAAK,EAAE,qBAAqB,KAAK,CAAC,EAClC,MAAM,kBAAkB,EACxB,MAAM,qBAAqB,EAC3B,MAAM,qBAAqB,EAC3B,MAAM,mBAAmB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,33 +1,4 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
/**
|
|
3
|
-
* Server Variable Object
|
|
4
|
-
*
|
|
5
|
-
* An object representing a Server Variable for server URL template substitution.
|
|
6
|
-
*
|
|
7
|
-
* @see https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.1.md#server-variable-object
|
|
8
|
-
*/
|
|
9
|
-
export declare const oasServerVariableSchema: z.ZodObject<{
|
|
10
|
-
enum: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
11
|
-
default: z.ZodOptional<z.ZodString>;
|
|
12
|
-
description: z.ZodOptional<z.ZodString>;
|
|
13
|
-
}, z.core.$strip>;
|
|
14
|
-
/**
|
|
15
|
-
* Server Object
|
|
16
|
-
*
|
|
17
|
-
* An object representing a Server.
|
|
18
|
-
*
|
|
19
|
-
* @see https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.1.md#server-object
|
|
20
|
-
*/
|
|
21
|
-
export declare const oasServerSchema: z.ZodObject<{
|
|
22
|
-
url: z.ZodString;
|
|
23
|
-
description: z.ZodOptional<z.ZodString>;
|
|
24
|
-
variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
25
|
-
enum: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
26
|
-
default: z.ZodOptional<z.ZodString>;
|
|
27
|
-
description: z.ZodOptional<z.ZodString>;
|
|
28
|
-
value: z.ZodOptional<z.ZodString>;
|
|
29
|
-
}, z.core.$strip>>>;
|
|
30
|
-
}, z.core.$strip>;
|
|
31
2
|
export declare const serverSchema: z.ZodObject<{
|
|
32
3
|
url: z.ZodString;
|
|
33
4
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -37,7 +8,7 @@ export declare const serverSchema: z.ZodObject<{
|
|
|
37
8
|
description: z.ZodOptional<z.ZodString>;
|
|
38
9
|
value: z.ZodOptional<z.ZodString>;
|
|
39
10
|
}, z.core.$strip>>>;
|
|
40
|
-
uid: z.core.$ZodBranded<z.ZodDefault<z.
|
|
11
|
+
uid: z.core.$ZodBranded<z.ZodDefault<z.ZodString>, "server">;
|
|
41
12
|
}, z.core.$strip>;
|
|
42
13
|
export type Server = z.infer<typeof serverSchema>;
|
|
43
14
|
export type ServerPayload = z.input<typeof serverSchema>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAqEvB,eAAO,MAAM,YAAY;;;;;;;;;;iBAEvB,CAAA;AAEF,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAA;AACjD,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/entities/spec/server.ts"],
|
|
4
|
-
"sourcesContent": ["import { type ENTITY_BRANDS, nanoidSchema } from '@scalar/types/utils'\nimport { z } from 'zod'\n\n/**\n * Server Variable Object\n *\n * An object representing a Server Variable for server URL template substitution.\n *\n * @see https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.1.md#server-variable-object\n */\
|
|
5
|
-
"mappings": "AAAA,SAA6B,oBAAoB;AACjD,SAAS,SAAS;
|
|
4
|
+
"sourcesContent": ["import { type ENTITY_BRANDS, nanoidSchema } from '@scalar/types/utils'\nimport { z } from 'zod'\n\n/**\n * Server Variable Object\n *\n * An object representing a Server Variable for server URL template substitution.\n *\n * @see https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.1.md#server-variable-object\n */\nconst oasServerVariableSchema = z.object({\n /**\n * An enumeration of string values to be used if the substitution options are from a limited set. The array MUST NOT be empty.\n */\n enum: z.array(z.string()).optional(),\n /**\n * REQUIRED. The default value to use for substitution, which SHALL be sent if an alternate value is not supplied.\n * Note this behavior is different than the Schema Object's treatment of default values, because in those cases\n * parameter values are optional. If the enum is defined, the value MUST exist in the enum's values.\n */\n default: z.string().optional(),\n /**\n * An optional description for the server variable. CommonMark syntax MAY be used for rich text representation.\n */\n description: z.string().optional(),\n})\n\n/** Extended schema for server variables */\nconst extendedServerVariableSchema = oasServerVariableSchema\n .extend({\n /** The value of the variable */\n value: z.string().optional(),\n })\n .refine((data) => {\n // Set default to the first enum value if invalid\n if (Array.isArray(data.enum) && !data.enum.includes(data.default ?? '') && data.enum.length > 0) {\n data.default = data.enum[0]\n }\n\n if (Array.isArray(data.enum) && data.enum.length === 0) {\n delete data.enum\n }\n\n // Always return true since we've modified the data to be valid\n return true\n })\n\n/**\n * Server Object\n *\n * An object representing a Server.\n *\n * @see https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.1.md#server-object\n */\nconst oasServerSchema = z.object({\n /**\n * REQUIRED. A URL to the target host. This URL supports Server Variables and MAY be relative, to indicate that\n * the host location is relative to the location where the OpenAPI document is being served. Variable substitutions\n * will be made when a variable is named in {brackets}.\n */\n url: z.string(),\n /**\n * An optional string describing the host designated by the URL. CommonMark syntax MAY be used for rich text\n * representation.\n */\n description: z.string().optional(),\n /** A map between a variable name and its value. The value is used for substitution in the server's URL template. */\n variables: z.record(z.string(), extendedServerVariableSchema).optional(),\n})\n\nexport const serverSchema = oasServerSchema.extend({\n uid: nanoidSchema.brand<ENTITY_BRANDS['SERVER']>(),\n})\n\nexport type Server = z.infer<typeof serverSchema>\nexport type ServerPayload = z.input<typeof serverSchema>\n"],
|
|
5
|
+
"mappings": "AAAA,SAA6B,oBAAoB;AACjD,SAAS,SAAS;AASlB,MAAM,0BAA0B,EAAE,OAAO;AAAA;AAAA;AAAA;AAAA,EAIvC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMnC,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA,EAI7B,aAAa,EAAE,OAAO,EAAE,SAAS;AACnC,CAAC;AAGD,MAAM,+BAA+B,wBAClC,OAAO;AAAA;AAAA,EAEN,OAAO,EAAE,OAAO,EAAE,SAAS;AAC7B,CAAC,EACA,OAAO,CAAC,SAAS;AAEhB,MAAI,MAAM,QAAQ,KAAK,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,KAAK,WAAW,EAAE,KAAK,KAAK,KAAK,SAAS,GAAG;AAC/F,SAAK,UAAU,KAAK,KAAK,CAAC;AAAA,EAC5B;AAEA,MAAI,MAAM,QAAQ,KAAK,IAAI,KAAK,KAAK,KAAK,WAAW,GAAG;AACtD,WAAO,KAAK;AAAA,EACd;AAGA,SAAO;AACT,CAAC;AASH,MAAM,kBAAkB,EAAE,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM/B,KAAK,EAAE,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA,EAKd,aAAa,EAAE,OAAO,EAAE,SAAS;AAAA;AAAA,EAEjC,WAAW,EAAE,OAAO,EAAE,OAAO,GAAG,4BAA4B,EAAE,SAAS;AACzE,CAAC;AAEM,MAAM,eAAe,gBAAgB,OAAO;AAAA,EACjD,KAAK,aAAa,MAA+B;AACnD,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|