@scalar/oas-utils 0.2.142 → 0.2.143
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 +14 -0
- package/dist/entities/spec/operation.d.ts +4 -4
- package/dist/entities/spec/request-example.test.js +5 -6
- package/dist/entities/spec/request-example.test.js.map +2 -2
- package/dist/entities/spec/request-examples.d.ts +19 -19
- package/dist/entities/spec/request-examples.d.ts.map +1 -1
- package/dist/entities/spec/request-examples.js +15 -5
- package/dist/entities/spec/request-examples.js.map +2 -2
- package/dist/entities/spec/requests.d.ts +10 -10
- package/dist/helpers/security/get-schemes.d.ts +4 -0
- package/dist/helpers/security/get-schemes.d.ts.map +1 -1
- package/dist/spec-getters/get-example-from-schema.d.ts.map +1 -1
- package/dist/spec-getters/get-example-from-schema.js +6 -3
- package/dist/spec-getters/get-example-from-schema.js.map +2 -2
- package/dist/spec-getters/get-request-body-from-operation.d.ts +1 -1
- package/dist/spec-getters/get-request-body-from-operation.d.ts.map +1 -1
- package/dist/spec-getters/get-request-body-from-operation.js +8 -5
- package/dist/spec-getters/get-request-body-from-operation.js.map +2 -2
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @scalar/oas-utils
|
|
2
2
|
|
|
3
|
+
## 0.2.143
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 67aa0f4: fix: render correct queries with form data
|
|
8
|
+
- Updated dependencies [f711ab5]
|
|
9
|
+
- Updated dependencies [90b773e]
|
|
10
|
+
- Updated dependencies [0222ad4]
|
|
11
|
+
- Updated dependencies [cb9428c]
|
|
12
|
+
- Updated dependencies [67aa0f4]
|
|
13
|
+
- @scalar/types@0.1.15
|
|
14
|
+
- @scalar/themes@0.11.2
|
|
15
|
+
- @scalar/openapi-types@0.2.3
|
|
16
|
+
|
|
3
17
|
## 0.2.142
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -100,14 +100,14 @@ export declare const operationSchema: import("zod").ZodObject<import("zod").obje
|
|
|
100
100
|
base64?: string | undefined;
|
|
101
101
|
}>>>;
|
|
102
102
|
}, "strip", import("zod").ZodTypeAny, {
|
|
103
|
-
encoding: "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "
|
|
103
|
+
encoding: "binary" | "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "text/html" | "application/javascript" | "application/yaml" | "application/edn";
|
|
104
104
|
content: string | Record<string, any>;
|
|
105
105
|
file?: {
|
|
106
106
|
url: string;
|
|
107
107
|
base64?: string | undefined;
|
|
108
108
|
} | null | undefined;
|
|
109
109
|
}, {
|
|
110
|
-
encoding: "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "
|
|
110
|
+
encoding: "binary" | "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "text/html" | "application/javascript" | "application/yaml" | "application/edn";
|
|
111
111
|
content: string | Record<string, any>;
|
|
112
112
|
file?: {
|
|
113
113
|
url: string;
|
|
@@ -139,7 +139,7 @@ export declare const operationSchema: import("zod").ZodObject<import("zod").obje
|
|
|
139
139
|
};
|
|
140
140
|
name?: string | undefined;
|
|
141
141
|
body?: {
|
|
142
|
-
encoding: "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "
|
|
142
|
+
encoding: "binary" | "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "text/html" | "application/javascript" | "application/yaml" | "application/edn";
|
|
143
143
|
content: string | Record<string, any>;
|
|
144
144
|
file?: {
|
|
145
145
|
url: string;
|
|
@@ -155,7 +155,7 @@ export declare const operationSchema: import("zod").ZodObject<import("zod").obje
|
|
|
155
155
|
};
|
|
156
156
|
name?: string | undefined;
|
|
157
157
|
body?: {
|
|
158
|
-
encoding: "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "
|
|
158
|
+
encoding: "binary" | "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "text/html" | "application/javascript" | "application/yaml" | "application/edn";
|
|
159
159
|
content: string | Record<string, any>;
|
|
160
160
|
file?: {
|
|
161
161
|
url: string;
|
|
@@ -339,8 +339,8 @@ describe("convertExampleToXScalar", () => {
|
|
|
339
339
|
{ key: "field1", value: "value1", enabled: true },
|
|
340
340
|
{
|
|
341
341
|
key: "file1",
|
|
342
|
-
value: "
|
|
343
|
-
file: new
|
|
342
|
+
value: "ignore this",
|
|
343
|
+
file: new File(["test content"], "test.txt", { type: "text/plain" }),
|
|
344
344
|
enabled: true
|
|
345
345
|
}
|
|
346
346
|
]
|
|
@@ -547,10 +547,9 @@ describe("createExampleFromRequest", () => {
|
|
|
547
547
|
formData: {
|
|
548
548
|
encoding: "form-data",
|
|
549
549
|
value: [
|
|
550
|
-
{ key: "image", value: "", enabled: true },
|
|
551
|
-
{ key: "additionalImages
|
|
552
|
-
{ key: "metadata
|
|
553
|
-
{ key: "metadata[tags][0]", value: "", enabled: true }
|
|
550
|
+
{ key: "image", value: "BINARY", file: expect.any(File), enabled: true },
|
|
551
|
+
{ key: "additionalImages", value: "BINARY", file: expect.any(File), enabled: true },
|
|
552
|
+
{ key: "metadata", value: '{"caption":"","tags":[""]}', enabled: true }
|
|
554
553
|
]
|
|
555
554
|
}
|
|
556
555
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/entities/spec/request-example.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { operationSchema } from './operation'\nimport {\n convertExampleToXScalar,\n createExampleFromRequest,\n createParamInstance,\n parameterArrayToObject,\n requestExampleSchema,\n} from './request-examples'\n\ndescribe('createParamInstance', () => {\n it('works with schema enum type number', () => {\n const result = createParamInstance({\n in: 'path',\n name: 'foo',\n required: true,\n deprecated: false,\n schema: {\n default: 1.2,\n type: 'number',\n enum: [1.2, 2.1, 3],\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: '1.2',\n enabled: true,\n description: undefined,\n required: true,\n enum: ['1.2', '2.1', '3'],\n type: 'number',\n default: 1.2,\n })\n })\n\n it('works with schema enum type string', () => {\n const result = createParamInstance({\n in: 'path',\n name: 'foo',\n required: true,\n deprecated: false,\n schema: {\n default: 'foo',\n type: 'string',\n enum: ['foo', 'bar'],\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: 'foo',\n enabled: true,\n description: undefined,\n required: true,\n enum: ['foo', 'bar'],\n type: 'string',\n default: 'foo',\n })\n })\n\n it('works with schema enum type integer', () => {\n const result = createParamInstance({\n in: 'query',\n name: 'foo',\n required: true,\n deprecated: false,\n schema: {\n default: 1,\n type: 'integer',\n enum: [1, 2, 3],\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: '1',\n enabled: true,\n description: undefined,\n required: true,\n enum: ['1', '2', '3'],\n type: 'integer',\n default: 1,\n })\n })\n\n it('works with schema enum type boolean', () => {\n const result = createParamInstance({\n in: 'query',\n name: 'foo',\n required: true,\n deprecated: false,\n schema: {\n default: false,\n type: 'boolean',\n enum: [true, false],\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: 'false',\n enabled: true,\n description: undefined,\n required: true,\n enum: ['true', 'false'],\n type: 'boolean',\n default: false,\n })\n })\n\n it('works with schema examples type number', () => {\n const result = createParamInstance({\n in: 'path',\n name: 'foo',\n required: true,\n deprecated: false,\n schema: {\n default: 1.2,\n type: 'number',\n examples: [1.2, 2.1, 3],\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: '1.2',\n enabled: true,\n description: undefined,\n required: true,\n examples: ['1.2', '2.1', '3'],\n type: 'number',\n default: 1.2,\n })\n })\n\n it('works with schema examples type string', () => {\n const result = createParamInstance({\n in: 'query',\n name: 'foo',\n required: true,\n deprecated: false,\n schema: {\n default: false,\n type: 'boolean',\n examples: ['foo', 'bar'],\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: 'false',\n enabled: true,\n description: undefined,\n required: true,\n type: 'boolean',\n default: false,\n examples: ['foo', 'bar'],\n })\n })\n\n it('works with schema examples type integer', () => {\n const result = createParamInstance({\n in: 'query',\n name: 'foo',\n required: true,\n deprecated: false,\n schema: {\n default: 1,\n type: 'integer',\n examples: [1, 2, 3],\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: '1',\n enabled: true,\n description: undefined,\n required: true,\n examples: ['1', '2', '3'],\n type: 'integer',\n default: 1,\n })\n })\n\n it('works with schema examples type boolean', () => {\n const result = createParamInstance({\n in: 'query',\n name: 'foo',\n required: true,\n deprecated: false,\n schema: {\n default: false,\n type: 'boolean',\n examples: [true, false],\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: 'false',\n enabled: true,\n description: undefined,\n required: true,\n examples: ['true', 'false'],\n type: 'boolean',\n default: false,\n })\n })\n\n it('works with array of types', () => {\n const result = createParamInstance({\n in: 'path',\n name: 'foo',\n required: true,\n deprecated: false,\n schema: {\n type: ['string', 'null'],\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n enabled: true,\n enum: undefined,\n examples: undefined,\n description: undefined,\n required: true,\n type: 'string',\n nullable: true,\n value: '',\n })\n })\n\n it('works with content examples', () => {\n const result = createParamInstance({\n in: 'query',\n name: 'foo',\n required: false,\n deprecated: false,\n content: {\n 'application/json': {\n schema: { type: 'integer', maximum: 50 },\n examples: {\n zero: { value: 0 },\n max: { value: 50 },\n },\n },\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: '0',\n enabled: false,\n description: undefined,\n required: false,\n })\n })\n\n it('works with content example', () => {\n const result = createParamInstance({\n in: 'query',\n name: 'foo',\n required: false,\n deprecated: false,\n content: {\n 'application/json': {\n schema: { type: 'integer' },\n example: 42,\n },\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: '42',\n enabled: false,\n description: undefined,\n required: false,\n })\n })\n\n it('works with parameter example', () => {\n const result = createParamInstance({\n in: 'query',\n name: 'foo',\n required: false,\n deprecated: false,\n example: 42,\n schema: {\n type: 'integer',\n example: 1,\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: '42',\n enabled: false,\n description: undefined,\n required: false,\n type: 'integer',\n })\n })\n})\n\ndescribe('parameterArrayToObject', () => {\n it('converts array of parameters to key-value object', () => {\n const params = [\n { key: 'foo', value: 'bar', enabled: true },\n { key: 'hello', value: 'world', enabled: false },\n ]\n\n const result = parameterArrayToObject(params)\n\n expect(result).toEqual({\n foo: 'bar',\n hello: 'world',\n })\n })\n\n it('handles empty array', () => {\n const result = parameterArrayToObject([])\n expect(result).toEqual({})\n })\n})\n\ndescribe('convertExampleToXScalar', () => {\n it('converts raw JSON body', () => {\n const example = requestExampleSchema.parse({\n uid: 'test-uid',\n requestUid: 'req-uid',\n body: {\n activeBody: 'raw',\n raw: {\n encoding: 'json' as const,\n value: '{\"test\": true}',\n },\n },\n parameters: {\n path: [{ key: 'id', value: '123', enabled: true }],\n headers: [{ key: 'Accept', value: '*/*', enabled: true }],\n },\n })\n\n const result = convertExampleToXScalar(example)\n\n expect(result).toEqual({\n body: {\n encoding: 'application/json',\n content: '{\"test\": true}',\n },\n parameters: {\n path: { id: '123' },\n headers: { Accept: '*/*' },\n },\n })\n })\n\n it('converts form data body', () => {\n const example = requestExampleSchema.parse({\n uid: 'test-uid',\n requestUid: 'req-uid',\n body: {\n activeBody: 'formData',\n formData: {\n encoding: 'form-data' as const,\n value: [\n { key: 'field1', value: 'value1', enabled: true },\n {\n key: 'file1',\n value: 'test.txt',\n file: new Blob(['test content'], { type: 'text/plain' }),\n enabled: true,\n },\n ],\n },\n },\n })\n\n const result = convertExampleToXScalar(example)\n\n expect(result).toEqual({\n body: {\n encoding: 'multipart/form-data',\n content: {\n field1: { type: 'string', value: 'value1' },\n file1: { type: 'file', file: null },\n },\n },\n parameters: {\n headers: {\n Accept: '*/*',\n },\n },\n })\n })\n\n it('converts binary body', () => {\n const example = requestExampleSchema.parse({\n uid: 'test-uid',\n requestUid: 'req-uid',\n body: {\n activeBody: 'binary',\n binary: new Blob(['test']),\n },\n })\n\n const result = convertExampleToXScalar(example)\n\n expect(result).toEqual({\n body: {\n encoding: 'binary',\n content: '',\n file: null,\n },\n parameters: {\n headers: {\n Accept: '*/*',\n },\n },\n })\n })\n})\n\ndescribe('createExampleFromRequest', () => {\n it('creates example with JSON request body', () => {\n const operation = operationSchema.parse({\n uid: 'request-1',\n path: '/test',\n parameters: [\n {\n in: 'path',\n name: 'id',\n required: true,\n deprecated: false,\n schema: { type: 'string', default: '123' },\n },\n ],\n requestBody: {\n content: {\n 'application/json': {\n schema: {},\n example: '{\"test\": true}',\n },\n },\n },\n })\n\n const result = createExampleFromRequest(operation, 'Test Example')\n\n expect(result).toMatchObject({\n requestUid: 'request-1',\n name: 'Test Example',\n body: {\n activeBody: 'raw',\n raw: {\n encoding: 'json',\n value: '{\"test\": true}',\n },\n },\n parameters: {\n path: [\n {\n key: 'id',\n value: '123',\n enabled: true,\n required: true,\n },\n ],\n headers: [\n { key: 'Accept', value: '*/*', enabled: true },\n { key: 'Content-Type', value: 'application/json', enabled: true },\n ],\n query: [],\n cookies: [],\n },\n })\n })\n\n it('does not overwrite the content-type header if it exists', () => {\n const operation = operationSchema.parse({\n uid: 'request-1',\n path: '/test',\n parameters: [\n {\n in: 'path',\n name: 'id',\n required: true,\n deprecated: false,\n schema: { type: 'string', default: '123' },\n },\n {\n in: 'header',\n name: 'Content-Type',\n required: true,\n deprecated: false,\n schema: { type: 'string', default: 'application/testing' },\n },\n ],\n requestBody: {\n content: {\n 'application/json': {\n schema: {},\n example: '{\"test\": true}',\n },\n },\n },\n })\n\n const result = createExampleFromRequest(operation, 'Test Example')\n\n expect(result).toMatchObject({\n requestUid: 'request-1',\n name: 'Test Example',\n body: {\n activeBody: 'raw',\n raw: {\n encoding: 'json',\n value: '{\"test\": true}',\n },\n },\n parameters: {\n path: [\n {\n key: 'id',\n value: '123',\n enabled: true,\n required: true,\n },\n ],\n headers: [{ key: 'Content-Type', value: 'application/testing', enabled: true }],\n query: [],\n cookies: [],\n },\n })\n })\n\n it('creates example with form-data request body', () => {\n const operation = operationSchema.parse({\n uid: 'request-1',\n path: '/test',\n parameters: [],\n requestBody: {\n content: {\n 'multipart/form-data': {\n schema: {\n type: 'object',\n properties: {\n image: {\n type: 'string',\n format: 'binary',\n description: \"The pet's image file\",\n },\n additionalImages: {\n type: 'array',\n items: {\n type: 'string',\n format: 'binary',\n },\n description: 'Additional pet images',\n },\n metadata: {\n type: 'object',\n properties: {\n caption: {\n type: 'string',\n },\n tags: {\n type: 'array',\n items: {\n type: 'string',\n },\n },\n },\n },\n },\n },\n },\n },\n },\n })\n\n const result = createExampleFromRequest(operation, 'Form Example')\n\n expect(result).toMatchObject({\n requestUid: 'request-1',\n name: 'Form Example',\n body: {\n activeBody: 'formData',\n formData: {\n encoding: 'form-data',\n value: [\n { key: 'image', value: '', enabled: true },\n { key: 'additionalImages[0]', value: '', enabled: true },\n { key: 'metadata[caption]', value: '', enabled: true },\n { key: 'metadata[tags][0]', value: '', enabled: true },\n ],\n },\n },\n parameters: {\n headers: [\n { key: 'Accept', value: '*/*', enabled: true },\n { key: 'Content-Type', value: 'multipart/form-data', enabled: true },\n ],\n path: [],\n query: [],\n cookies: [],\n },\n })\n })\n})\n\ndescribe('createExampleFromRequest with default body when Content-Type header is exists', () => {\n it.each([\n { contentType: 'application/json', defaultBody: { activeBody: 'raw', raw: { encoding: 'json', value: '{}' } } },\n { contentType: 'application/xml', defaultBody: { activeBody: 'raw', raw: { encoding: 'xml', value: '' } } },\n { contentType: 'application/octet-stream', defaultBody: { activeBody: 'binary', binary: undefined } },\n {\n contentType: 'application/x-www-form-urlencoded',\n defaultBody: { activeBody: 'formData', formData: { encoding: 'urlencoded', value: [] } },\n },\n {\n contentType: 'multipart/form-data',\n defaultBody: { activeBody: 'formData', formData: { encoding: 'form-data', value: [] } },\n },\n ] as const)('when Content-Type header is $contentType', ({ contentType, defaultBody }) => {\n const operation = operationSchema.parse({\n uid: 'request-1',\n path: '/test',\n parameters: [\n {\n in: 'header',\n name: 'Content-Type',\n required: true,\n deprecated: false,\n schema: { type: 'string', default: contentType },\n },\n ],\n })\n\n const result = createExampleFromRequest(operation, 'Test Example')\n\n expect(result).toMatchObject({\n requestUid: 'request-1',\n name: 'Test Example',\n body: defaultBody,\n parameters: {\n headers: [{ key: 'Content-Type', value: contentType, enabled: true }],\n query: [],\n cookies: [],\n },\n })\n })\n\n it('when Content-Type header is not exists', () => {\n const operation = operationSchema.parse({\n uid: 'request-1',\n path: '/test',\n parameters: [\n {\n in: 'header',\n name: 'Content-Type',\n required: true,\n deprecated: false,\n schema: { type: 'string' },\n },\n ],\n })\n\n const result = createExampleFromRequest(operation, 'Test Example')\n\n expect(result).toMatchObject({\n requestUid: 'request-1',\n name: 'Test Example',\n body: {\n activeBody: 'raw',\n },\n parameters: {\n headers: [{ key: 'Content-Type', value: '', enabled: true }],\n query: [],\n cookies: [],\n },\n })\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,uBAAuB,MAAM;AACpC,KAAG,sCAAsC,MAAM;AAC7C,UAAM,SAAS,oBAAoB;AAAA,MACjC,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,UAAU;AAAA,MACV,YAAY;AAAA,MACZ,QAAQ;AAAA,QACN,SAAS;AAAA,QACT,MAAM;AAAA,QACN,MAAM,CAAC,KAAK,KAAK,CAAC;AAAA,MACpB;AAAA,IACF,CA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AC;AAAA,EACH,CAAC;AAED,KAAG,0CAA0C,MAAM;AACjD,UAAM,YAAY,gBAAgB,MAAM;AAAA,MACtC,KAAK;AAAA,MACL,MAAM;AAAA,MACN,YAAY;AAAA,QACV;AAAA,UACE,IAAI;AAAA,UACJ,MAAM;AAAA,UACN,UAAU;AAAA,UACV,YAAY;AAAA,UACZ,QAAQ,EAAE,MAAM,SAAS;AAAA,QAC3B;AAAA,MACF;AAAA,IACF,CAAC;AAED,UAAM,SAAS,yBAAyB,WAAW,cAAc;AAEjE,WAAO,MAAM,EAAE,cAAc;AAAA,MAC3B,YAAY;AAAA,MACZ,MAAM;AAAA,MACN,MAAM;AAAA,QACJ,YAAY;AAAA,MACd;AAAA,MACA,YAAY;AAAA,QACV,SAAS,CAAC,EAAE,KAAK,gBAAgB,OAAO,IAAI,SAAS,KAAK,CAAC;AAAA,QAC3D,OAAO,CAAC;AAAA,QACR,SAAS,CAAC;AAAA,MACZ;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH,CAAC;",
|
|
4
|
+
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { operationSchema } from './operation'\nimport {\n convertExampleToXScalar,\n createExampleFromRequest,\n createParamInstance,\n parameterArrayToObject,\n requestExampleSchema,\n} from './request-examples'\n\ndescribe('createParamInstance', () => {\n it('works with schema enum type number', () => {\n const result = createParamInstance({\n in: 'path',\n name: 'foo',\n required: true,\n deprecated: false,\n schema: {\n default: 1.2,\n type: 'number',\n enum: [1.2, 2.1, 3],\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: '1.2',\n enabled: true,\n description: undefined,\n required: true,\n enum: ['1.2', '2.1', '3'],\n type: 'number',\n default: 1.2,\n })\n })\n\n it('works with schema enum type string', () => {\n const result = createParamInstance({\n in: 'path',\n name: 'foo',\n required: true,\n deprecated: false,\n schema: {\n default: 'foo',\n type: 'string',\n enum: ['foo', 'bar'],\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: 'foo',\n enabled: true,\n description: undefined,\n required: true,\n enum: ['foo', 'bar'],\n type: 'string',\n default: 'foo',\n })\n })\n\n it('works with schema enum type integer', () => {\n const result = createParamInstance({\n in: 'query',\n name: 'foo',\n required: true,\n deprecated: false,\n schema: {\n default: 1,\n type: 'integer',\n enum: [1, 2, 3],\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: '1',\n enabled: true,\n description: undefined,\n required: true,\n enum: ['1', '2', '3'],\n type: 'integer',\n default: 1,\n })\n })\n\n it('works with schema enum type boolean', () => {\n const result = createParamInstance({\n in: 'query',\n name: 'foo',\n required: true,\n deprecated: false,\n schema: {\n default: false,\n type: 'boolean',\n enum: [true, false],\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: 'false',\n enabled: true,\n description: undefined,\n required: true,\n enum: ['true', 'false'],\n type: 'boolean',\n default: false,\n })\n })\n\n it('works with schema examples type number', () => {\n const result = createParamInstance({\n in: 'path',\n name: 'foo',\n required: true,\n deprecated: false,\n schema: {\n default: 1.2,\n type: 'number',\n examples: [1.2, 2.1, 3],\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: '1.2',\n enabled: true,\n description: undefined,\n required: true,\n examples: ['1.2', '2.1', '3'],\n type: 'number',\n default: 1.2,\n })\n })\n\n it('works with schema examples type string', () => {\n const result = createParamInstance({\n in: 'query',\n name: 'foo',\n required: true,\n deprecated: false,\n schema: {\n default: false,\n type: 'boolean',\n examples: ['foo', 'bar'],\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: 'false',\n enabled: true,\n description: undefined,\n required: true,\n type: 'boolean',\n default: false,\n examples: ['foo', 'bar'],\n })\n })\n\n it('works with schema examples type integer', () => {\n const result = createParamInstance({\n in: 'query',\n name: 'foo',\n required: true,\n deprecated: false,\n schema: {\n default: 1,\n type: 'integer',\n examples: [1, 2, 3],\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: '1',\n enabled: true,\n description: undefined,\n required: true,\n examples: ['1', '2', '3'],\n type: 'integer',\n default: 1,\n })\n })\n\n it('works with schema examples type boolean', () => {\n const result = createParamInstance({\n in: 'query',\n name: 'foo',\n required: true,\n deprecated: false,\n schema: {\n default: false,\n type: 'boolean',\n examples: [true, false],\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: 'false',\n enabled: true,\n description: undefined,\n required: true,\n examples: ['true', 'false'],\n type: 'boolean',\n default: false,\n })\n })\n\n it('works with array of types', () => {\n const result = createParamInstance({\n in: 'path',\n name: 'foo',\n required: true,\n deprecated: false,\n schema: {\n type: ['string', 'null'],\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n enabled: true,\n enum: undefined,\n examples: undefined,\n description: undefined,\n required: true,\n type: 'string',\n nullable: true,\n value: '',\n })\n })\n\n it('works with content examples', () => {\n const result = createParamInstance({\n in: 'query',\n name: 'foo',\n required: false,\n deprecated: false,\n content: {\n 'application/json': {\n schema: { type: 'integer', maximum: 50 },\n examples: {\n zero: { value: 0 },\n max: { value: 50 },\n },\n },\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: '0',\n enabled: false,\n description: undefined,\n required: false,\n })\n })\n\n it('works with content example', () => {\n const result = createParamInstance({\n in: 'query',\n name: 'foo',\n required: false,\n deprecated: false,\n content: {\n 'application/json': {\n schema: { type: 'integer' },\n example: 42,\n },\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: '42',\n enabled: false,\n description: undefined,\n required: false,\n })\n })\n\n it('works with parameter example', () => {\n const result = createParamInstance({\n in: 'query',\n name: 'foo',\n required: false,\n deprecated: false,\n example: 42,\n schema: {\n type: 'integer',\n example: 1,\n },\n })\n\n expect(result).toEqual({\n key: 'foo',\n value: '42',\n enabled: false,\n description: undefined,\n required: false,\n type: 'integer',\n })\n })\n})\n\ndescribe('parameterArrayToObject', () => {\n it('converts array of parameters to key-value object', () => {\n const params = [\n { key: 'foo', value: 'bar', enabled: true },\n { key: 'hello', value: 'world', enabled: false },\n ]\n\n const result = parameterArrayToObject(params)\n\n expect(result).toEqual({\n foo: 'bar',\n hello: 'world',\n })\n })\n\n it('handles empty array', () => {\n const result = parameterArrayToObject([])\n expect(result).toEqual({})\n })\n})\n\ndescribe('convertExampleToXScalar', () => {\n it('converts raw JSON body', () => {\n const example = requestExampleSchema.parse({\n uid: 'test-uid',\n requestUid: 'req-uid',\n body: {\n activeBody: 'raw',\n raw: {\n encoding: 'json' as const,\n value: '{\"test\": true}',\n },\n },\n parameters: {\n path: [{ key: 'id', value: '123', enabled: true }],\n headers: [{ key: 'Accept', value: '*/*', enabled: true }],\n },\n })\n\n const result = convertExampleToXScalar(example)\n\n expect(result).toEqual({\n body: {\n encoding: 'application/json',\n content: '{\"test\": true}',\n },\n parameters: {\n path: { id: '123' },\n headers: { Accept: '*/*' },\n },\n })\n })\n\n it('converts form data body', () => {\n const example = requestExampleSchema.parse({\n uid: 'test-uid',\n requestUid: 'req-uid',\n body: {\n activeBody: 'formData',\n formData: {\n encoding: 'form-data' as const,\n value: [\n { key: 'field1', value: 'value1', enabled: true },\n {\n key: 'file1',\n value: 'ignore this',\n file: new File(['test content'], 'test.txt', { type: 'text/plain' }),\n enabled: true,\n },\n ],\n },\n },\n })\n\n const result = convertExampleToXScalar(example)\n\n expect(result).toEqual({\n body: {\n encoding: 'multipart/form-data',\n content: {\n field1: { type: 'string', value: 'value1' },\n file1: { type: 'file', file: null },\n },\n },\n parameters: {\n headers: {\n Accept: '*/*',\n },\n },\n })\n })\n\n it('converts binary body', () => {\n const example = requestExampleSchema.parse({\n uid: 'test-uid',\n requestUid: 'req-uid',\n body: {\n activeBody: 'binary',\n binary: new Blob(['test']),\n },\n })\n\n const result = convertExampleToXScalar(example)\n\n expect(result).toEqual({\n body: {\n encoding: 'binary',\n content: '',\n file: null,\n },\n parameters: {\n headers: {\n Accept: '*/*',\n },\n },\n })\n })\n})\n\ndescribe('createExampleFromRequest', () => {\n it('creates example with JSON request body', () => {\n const operation = operationSchema.parse({\n uid: 'request-1',\n path: '/test',\n parameters: [\n {\n in: 'path',\n name: 'id',\n required: true,\n deprecated: false,\n schema: { type: 'string', default: '123' },\n },\n ],\n requestBody: {\n content: {\n 'application/json': {\n schema: {},\n example: '{\"test\": true}',\n },\n },\n },\n })\n\n const result = createExampleFromRequest(operation, 'Test Example')\n\n expect(result).toMatchObject({\n requestUid: 'request-1',\n name: 'Test Example',\n body: {\n activeBody: 'raw',\n raw: {\n encoding: 'json',\n value: '{\"test\": true}',\n },\n },\n parameters: {\n path: [\n {\n key: 'id',\n value: '123',\n enabled: true,\n required: true,\n },\n ],\n headers: [\n { key: 'Accept', value: '*/*', enabled: true },\n { key: 'Content-Type', value: 'application/json', enabled: true },\n ],\n query: [],\n cookies: [],\n },\n })\n })\n\n it('does not overwrite the content-type header if it exists', () => {\n const operation = operationSchema.parse({\n uid: 'request-1',\n path: '/test',\n parameters: [\n {\n in: 'path',\n name: 'id',\n required: true,\n deprecated: false,\n schema: { type: 'string', default: '123' },\n },\n {\n in: 'header',\n name: 'Content-Type',\n required: true,\n deprecated: false,\n schema: { type: 'string', default: 'application/testing' },\n },\n ],\n requestBody: {\n content: {\n 'application/json': {\n schema: {},\n example: '{\"test\": true}',\n },\n },\n },\n })\n\n const result = createExampleFromRequest(operation, 'Test Example')\n\n expect(result).toMatchObject({\n requestUid: 'request-1',\n name: 'Test Example',\n body: {\n activeBody: 'raw',\n raw: {\n encoding: 'json',\n value: '{\"test\": true}',\n },\n },\n parameters: {\n path: [\n {\n key: 'id',\n value: '123',\n enabled: true,\n required: true,\n },\n ],\n headers: [{ key: 'Content-Type', value: 'application/testing', enabled: true }],\n query: [],\n cookies: [],\n },\n })\n })\n\n it('creates example with form-data request body', () => {\n const operation = operationSchema.parse({\n uid: 'request-1',\n path: '/test',\n parameters: [],\n requestBody: {\n content: {\n 'multipart/form-data': {\n schema: {\n type: 'object',\n properties: {\n image: {\n type: 'string',\n format: 'binary',\n description: \"The pet's image file\",\n },\n additionalImages: {\n type: 'array',\n items: {\n type: 'string',\n format: 'binary',\n },\n description: 'Additional pet images',\n },\n metadata: {\n type: 'object',\n properties: {\n caption: {\n type: 'string',\n },\n tags: {\n type: 'array',\n items: {\n type: 'string',\n },\n },\n },\n },\n },\n },\n },\n },\n },\n })\n\n const result = createExampleFromRequest(operation, 'Form Example')\n\n expect(result).toMatchObject({\n requestUid: 'request-1',\n name: 'Form Example',\n body: {\n activeBody: 'formData',\n formData: {\n encoding: 'form-data',\n value: [\n { key: 'image', value: 'BINARY', file: expect.any(File), enabled: true },\n { key: 'additionalImages', value: 'BINARY', file: expect.any(File), enabled: true },\n { key: 'metadata', value: '{\"caption\":\"\",\"tags\":[\"\"]}', enabled: true },\n ],\n },\n },\n parameters: {\n headers: [\n { key: 'Accept', value: '*/*', enabled: true },\n { key: 'Content-Type', value: 'multipart/form-data', enabled: true },\n ],\n path: [],\n query: [],\n cookies: [],\n },\n })\n })\n})\n\ndescribe('createExampleFromRequest with default body when Content-Type header is exists', () => {\n it.each([\n { contentType: 'application/json', defaultBody: { activeBody: 'raw', raw: { encoding: 'json', value: '{}' } } },\n { contentType: 'application/xml', defaultBody: { activeBody: 'raw', raw: { encoding: 'xml', value: '' } } },\n { contentType: 'application/octet-stream', defaultBody: { activeBody: 'binary', binary: undefined } },\n {\n contentType: 'application/x-www-form-urlencoded',\n defaultBody: { activeBody: 'formData', formData: { encoding: 'urlencoded', value: [] } },\n },\n {\n contentType: 'multipart/form-data',\n defaultBody: { activeBody: 'formData', formData: { encoding: 'form-data', value: [] } },\n },\n ] as const)('when Content-Type header is $contentType', ({ contentType, defaultBody }) => {\n const operation = operationSchema.parse({\n uid: 'request-1',\n path: '/test',\n parameters: [\n {\n in: 'header',\n name: 'Content-Type',\n required: true,\n deprecated: false,\n schema: { type: 'string', default: contentType },\n },\n ],\n })\n\n const result = createExampleFromRequest(operation, 'Test Example')\n\n expect(result).toMatchObject({\n requestUid: 'request-1',\n name: 'Test Example',\n body: defaultBody,\n parameters: {\n headers: [{ key: 'Content-Type', value: contentType, enabled: true }],\n query: [],\n cookies: [],\n },\n })\n })\n\n it('when Content-Type header is not exists', () => {\n const operation = operationSchema.parse({\n uid: 'request-1',\n path: '/test',\n parameters: [\n {\n in: 'header',\n name: 'Content-Type',\n required: true,\n deprecated: false,\n schema: { type: 'string' },\n },\n ],\n })\n\n const result = createExampleFromRequest(operation, 'Test Example')\n\n expect(result).toMatchObject({\n requestUid: 'request-1',\n name: 'Test Example',\n body: {\n activeBody: 'raw',\n },\n parameters: {\n headers: [{ key: 'Content-Type', value: '', enabled: true }],\n query: [],\n cookies: [],\n },\n })\n })\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,uBAAuB,MAAM;AACpC,KAAG,sCAAsC,MAAM;AAC7C,UAAM,SAAS,oBAAoB;AAAA,MACjC,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,UAAU;AAAA,MACV,YAAY;AAAA,MACZ,QAAQ;AAAA,QACN,SAAS;AAAA,QACT,MAAM;AAAA,QACN,MAAM,CAAC,KAAK,KAAK,CAAC;AAAA,MACpB;AAAA,IACF,CAAC;AAED,WAAO,MAAM,EAAE,QAAQ;AAAA,MACrB,KAAK;AAAA,MACL,OAAO;AAAA,MACP,SAAS;AAAA,MACT,aAAa;AAAA,MACb,UAAU;AAAA,MACV,MAAM,CAAC,OAAO,OAAO,GAAG;AAAA,MACxB,MAAM;AAAA,MACN,SAAS;AAAA,IACX,CAAC;AAAA,EACH,CAAC;AAED,KAAG,sCAAsC,MAAM;AAC7C,UAAM,SAAS,oBAAoB;AAAA,MACjC,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,UAAU;AAAA,MACV,YAAY;AAAA,MACZ,QAAQ;AAAA,QACN,SAAS;AAAA,QACT,MAAM;AAAA,QACN,MAAM,CAAC,OAAO,KAAK;AAAA,MACrB;AAAA,IACF,CAAC;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AA,QACV,SAAS,CAAC,EAAE,KAAK,gBAAgB,OAAO,IAAI,SAAS,KAAK,CAAC;AAAA,QAC3D,OAAO,CAAC;AAAA,QACR,SAAS,CAAC;AAAA,MACZ;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -289,7 +289,8 @@ export declare const exampleRequestBodySchema: z.ZodObject<{
|
|
|
289
289
|
binary: z.ZodOptional<z.ZodType<Blob, z.ZodTypeDef, Blob>>;
|
|
290
290
|
activeBody: z.ZodDefault<z.ZodUnion<[z.ZodLiteral<"raw">, z.ZodLiteral<"formData">, z.ZodLiteral<"binary">]>>;
|
|
291
291
|
}, "strip", z.ZodTypeAny, {
|
|
292
|
-
activeBody: "
|
|
292
|
+
activeBody: "binary" | "formData" | "raw";
|
|
293
|
+
binary?: Blob | undefined;
|
|
293
294
|
formData?: {
|
|
294
295
|
value: {
|
|
295
296
|
value: string;
|
|
@@ -314,8 +315,8 @@ export declare const exampleRequestBodySchema: z.ZodObject<{
|
|
|
314
315
|
encoding: "xml" | "json" | "text" | "html" | "javascript" | "yaml" | "edn";
|
|
315
316
|
mimeType?: string | undefined;
|
|
316
317
|
} | undefined;
|
|
317
|
-
binary?: Blob | undefined;
|
|
318
318
|
}, {
|
|
319
|
+
binary?: Blob | undefined;
|
|
319
320
|
formData?: {
|
|
320
321
|
value?: {
|
|
321
322
|
value?: string | undefined;
|
|
@@ -340,8 +341,7 @@ export declare const exampleRequestBodySchema: z.ZodObject<{
|
|
|
340
341
|
value?: string | undefined;
|
|
341
342
|
mimeType?: string | undefined;
|
|
342
343
|
} | undefined;
|
|
343
|
-
|
|
344
|
-
activeBody?: "formData" | "raw" | "binary" | undefined;
|
|
344
|
+
activeBody?: "binary" | "formData" | "raw" | undefined;
|
|
345
345
|
}>;
|
|
346
346
|
export type ExampleRequestBody = z.infer<typeof exampleRequestBodySchema>;
|
|
347
347
|
/** Schema for the OAS serialization of request example bodies */
|
|
@@ -365,14 +365,14 @@ export declare const xScalarExampleBodySchema: z.ZodObject<{
|
|
|
365
365
|
base64?: string | undefined;
|
|
366
366
|
}>>>;
|
|
367
367
|
}, "strip", z.ZodTypeAny, {
|
|
368
|
-
encoding: "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "
|
|
368
|
+
encoding: "binary" | "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "text/html" | "application/javascript" | "application/yaml" | "application/edn";
|
|
369
369
|
content: string | Record<string, any>;
|
|
370
370
|
file?: {
|
|
371
371
|
url: string;
|
|
372
372
|
base64?: string | undefined;
|
|
373
373
|
} | null | undefined;
|
|
374
374
|
}, {
|
|
375
|
-
encoding: "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "
|
|
375
|
+
encoding: "binary" | "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "text/html" | "application/javascript" | "application/yaml" | "application/edn";
|
|
376
376
|
content: string | Record<string, any>;
|
|
377
377
|
file?: {
|
|
378
378
|
url: string;
|
|
@@ -517,7 +517,8 @@ export declare const requestExampleSchema: z.ZodObject<{
|
|
|
517
517
|
binary: z.ZodOptional<z.ZodType<Blob, z.ZodTypeDef, Blob>>;
|
|
518
518
|
activeBody: z.ZodDefault<z.ZodUnion<[z.ZodLiteral<"raw">, z.ZodLiteral<"formData">, z.ZodLiteral<"binary">]>>;
|
|
519
519
|
}, "strip", z.ZodTypeAny, {
|
|
520
|
-
activeBody: "
|
|
520
|
+
activeBody: "binary" | "formData" | "raw";
|
|
521
|
+
binary?: Blob | undefined;
|
|
521
522
|
formData?: {
|
|
522
523
|
value: {
|
|
523
524
|
value: string;
|
|
@@ -542,8 +543,8 @@ export declare const requestExampleSchema: z.ZodObject<{
|
|
|
542
543
|
encoding: "xml" | "json" | "text" | "html" | "javascript" | "yaml" | "edn";
|
|
543
544
|
mimeType?: string | undefined;
|
|
544
545
|
} | undefined;
|
|
545
|
-
binary?: Blob | undefined;
|
|
546
546
|
}, {
|
|
547
|
+
binary?: Blob | undefined;
|
|
547
548
|
formData?: {
|
|
548
549
|
value?: {
|
|
549
550
|
value?: string | undefined;
|
|
@@ -568,8 +569,7 @@ export declare const requestExampleSchema: z.ZodObject<{
|
|
|
568
569
|
value?: string | undefined;
|
|
569
570
|
mimeType?: string | undefined;
|
|
570
571
|
} | undefined;
|
|
571
|
-
|
|
572
|
-
activeBody?: "formData" | "raw" | "binary" | undefined;
|
|
572
|
+
activeBody?: "binary" | "formData" | "raw" | undefined;
|
|
573
573
|
}>>>;
|
|
574
574
|
parameters: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
575
575
|
path: z.ZodDefault<z.ZodArray<z.ZodEffects<z.ZodObject<{
|
|
@@ -1014,7 +1014,8 @@ export declare const requestExampleSchema: z.ZodObject<{
|
|
|
1014
1014
|
name: string;
|
|
1015
1015
|
type: "requestExample";
|
|
1016
1016
|
body: {
|
|
1017
|
-
activeBody: "
|
|
1017
|
+
activeBody: "binary" | "formData" | "raw";
|
|
1018
|
+
binary?: Blob | undefined;
|
|
1018
1019
|
formData?: {
|
|
1019
1020
|
value: {
|
|
1020
1021
|
value: string;
|
|
@@ -1039,7 +1040,6 @@ export declare const requestExampleSchema: z.ZodObject<{
|
|
|
1039
1040
|
encoding: "xml" | "json" | "text" | "html" | "javascript" | "yaml" | "edn";
|
|
1040
1041
|
mimeType?: string | undefined;
|
|
1041
1042
|
} | undefined;
|
|
1042
|
-
binary?: Blob | undefined;
|
|
1043
1043
|
};
|
|
1044
1044
|
parameters: {
|
|
1045
1045
|
path: {
|
|
@@ -1114,6 +1114,7 @@ export declare const requestExampleSchema: z.ZodObject<{
|
|
|
1114
1114
|
name?: string | undefined;
|
|
1115
1115
|
type?: "requestExample" | undefined;
|
|
1116
1116
|
body?: {
|
|
1117
|
+
binary?: Blob | undefined;
|
|
1117
1118
|
formData?: {
|
|
1118
1119
|
value?: {
|
|
1119
1120
|
value?: string | undefined;
|
|
@@ -1138,8 +1139,7 @@ export declare const requestExampleSchema: z.ZodObject<{
|
|
|
1138
1139
|
value?: string | undefined;
|
|
1139
1140
|
mimeType?: string | undefined;
|
|
1140
1141
|
} | undefined;
|
|
1141
|
-
|
|
1142
|
-
activeBody?: "formData" | "raw" | "binary" | undefined;
|
|
1142
|
+
activeBody?: "binary" | "formData" | "raw" | undefined;
|
|
1143
1143
|
} | undefined;
|
|
1144
1144
|
requestUid?: string | undefined;
|
|
1145
1145
|
parameters?: {
|
|
@@ -1235,14 +1235,14 @@ export declare const xScalarExampleSchema: z.ZodObject<{
|
|
|
1235
1235
|
base64?: string | undefined;
|
|
1236
1236
|
}>>>;
|
|
1237
1237
|
}, "strip", z.ZodTypeAny, {
|
|
1238
|
-
encoding: "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "
|
|
1238
|
+
encoding: "binary" | "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "text/html" | "application/javascript" | "application/yaml" | "application/edn";
|
|
1239
1239
|
content: string | Record<string, any>;
|
|
1240
1240
|
file?: {
|
|
1241
1241
|
url: string;
|
|
1242
1242
|
base64?: string | undefined;
|
|
1243
1243
|
} | null | undefined;
|
|
1244
1244
|
}, {
|
|
1245
|
-
encoding: "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "
|
|
1245
|
+
encoding: "binary" | "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "text/html" | "application/javascript" | "application/yaml" | "application/edn";
|
|
1246
1246
|
content: string | Record<string, any>;
|
|
1247
1247
|
file?: {
|
|
1248
1248
|
url: string;
|
|
@@ -1274,7 +1274,7 @@ export declare const xScalarExampleSchema: z.ZodObject<{
|
|
|
1274
1274
|
};
|
|
1275
1275
|
name?: string | undefined;
|
|
1276
1276
|
body?: {
|
|
1277
|
-
encoding: "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "
|
|
1277
|
+
encoding: "binary" | "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "text/html" | "application/javascript" | "application/yaml" | "application/edn";
|
|
1278
1278
|
content: string | Record<string, any>;
|
|
1279
1279
|
file?: {
|
|
1280
1280
|
url: string;
|
|
@@ -1290,7 +1290,7 @@ export declare const xScalarExampleSchema: z.ZodObject<{
|
|
|
1290
1290
|
};
|
|
1291
1291
|
name?: string | undefined;
|
|
1292
1292
|
body?: {
|
|
1293
|
-
encoding: "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "
|
|
1293
|
+
encoding: "binary" | "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "text/html" | "application/javascript" | "application/yaml" | "application/edn";
|
|
1294
1294
|
content: string | Record<string, any>;
|
|
1295
1295
|
file?: {
|
|
1296
1296
|
url: string;
|
|
@@ -1313,7 +1313,7 @@ export declare function convertExampleToXScalar(example: RequestExample): {
|
|
|
1313
1313
|
};
|
|
1314
1314
|
name?: string | undefined;
|
|
1315
1315
|
body?: {
|
|
1316
|
-
encoding: "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "
|
|
1316
|
+
encoding: "binary" | "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "text/html" | "application/javascript" | "application/yaml" | "application/edn";
|
|
1317
1317
|
content: string | Record<string, any>;
|
|
1318
1318
|
file?: {
|
|
1319
1319
|
url: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-exam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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEvC,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAKjE,2DAA2D;AAC3D,eAAO,MAAM,oBAAoB;IAC/B,qCAAqC;;;;QAzCrC;;;;WAIG;;QAEH,0EAA0E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4C1E,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAEjE;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,cAAc;;;;;;;;;;;;;;;;EAqD9D;AAKD,6DAA6D;AAC7D,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,gBAAgB;;;;;;;;;;;;;;;EAsH1D;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,cAAc,CAwHxG"}
|
|
@@ -297,11 +297,21 @@ function createExampleFromRequest(request, name, server) {
|
|
|
297
297
|
body.activeBody = "formData";
|
|
298
298
|
body.formData = {
|
|
299
299
|
encoding: contentType === "application/x-www-form-urlencoded" ? "urlencoded" : "form-data",
|
|
300
|
-
value: (requestBody?.params || []).map((param) =>
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
300
|
+
value: (requestBody?.params || []).map((param) => {
|
|
301
|
+
if (param.value instanceof File) {
|
|
302
|
+
return {
|
|
303
|
+
key: param.name,
|
|
304
|
+
value: "BINARY",
|
|
305
|
+
file: param.value,
|
|
306
|
+
enabled: true
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
key: param.name,
|
|
311
|
+
value: param.value || "",
|
|
312
|
+
enabled: true
|
|
313
|
+
};
|
|
314
|
+
})
|
|
305
315
|
};
|
|
306
316
|
}
|
|
307
317
|
if (requestBody?.mimeType && !contentTypeHeader) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/entities/spec/request-examples.ts"],
|
|
4
|
-
"sourcesContent": ["import { schemaModel } from '@/helpers/schema-model'\nimport { getServerVariableExamples } from '@/spec-getters/get-server-variable-examples'\nimport { keysOf } from '@scalar/object-utils/arrays'\nimport { type ENTITY_BRANDS, nanoidSchema } from '@scalar/types/utils'\nimport { z } from 'zod'\n\nimport { isDefined } from '@/helpers/is-defined'\nimport { getObjectKeys } from '@/helpers/object'\n\nimport { getRequestBodyFromOperation } from '@/spec-getters/get-request-body-from-operation'\nimport type { RequestParameter, ParameterContent } 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({}),\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 /** 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) {\n const schema = param.schema as any\n\n const firstExample = (() => {\n if (param.examples && !Array.isArray(param.examples) && getObjectKeys(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 = getObjectKeys(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 if (request.requestBody || contentTypeHeader?.value) {\n const requestBody = getRequestBodyFromOperation({\n path: request.path,\n information: {\n requestBody: request.requestBody,\n },\n })\n\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 key: param.name,\n value: param.value || '',\n enabled: true,\n })),\n }\n }\n\n // Add the content-type header if it doesn't exist\n if (requestBody?.mimeType && !contentTypeHeader) {\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,mBAAmB;AAC5B,SAAS,iCAAiC;AAC1C,SAAS,cAAc;AACvB,SAA6B,oBAAoB;AACjD,SAAS,SAAS;AAElB,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAE9B,SAAS,mCAAmC;AAcrC,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,EAA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AAC,
|
|
4
|
+
"sourcesContent": ["import { schemaModel } from '@/helpers/schema-model'\nimport { getServerVariableExamples } from '@/spec-getters/get-server-variable-examples'\nimport { keysOf } from '@scalar/object-utils/arrays'\nimport { type ENTITY_BRANDS, nanoidSchema } from '@scalar/types/utils'\nimport { z } from 'zod'\n\nimport { isDefined } from '@/helpers/is-defined'\nimport { getObjectKeys } from '@/helpers/object'\n\nimport { getRequestBodyFromOperation } from '@/spec-getters/get-request-body-from-operation'\nimport type { RequestParameter, ParameterContent } 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({}),\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 /** 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) {\n const schema = param.schema as any\n\n const firstExample = (() => {\n if (param.examples && !Array.isArray(param.examples) && getObjectKeys(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 = getObjectKeys(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 if (request.requestBody || contentTypeHeader?.value) {\n const requestBody = getRequestBodyFromOperation({\n path: request.path,\n information: {\n requestBody: request.requestBody,\n },\n })\n\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 // Add the content-type header if it doesn't exist\n if (requestBody?.mimeType && !contentTypeHeader) {\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,mBAAmB;AAC5B,SAAS,iCAAiC;AAC1C,SAAS,cAAc;AACvB,SAA6B,oBAAoB;AACjD,SAAS,SAAS;AAElB,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAE9B,SAAS,mCAAmC;AAcrC,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,E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K,MAAM;AAAA,YACX,OAAO,MAAM,SAAS;AAAA,YACtB,SAAS;AAAA,UACX;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAGA,QAAI,aAAa,YAAY,CAAC,mBAAmB;AAC/C,iBAAW,QAAQ,KAAK;AAAA,QACtB,KAAK;AAAA,QACL,OAAO,YAAY;AAAA,QACnB,SAAS;AAAA,MACX,CAAC;AAAA,IACH;AAAA,EACF;AAEA,QAAM,kBAAkB,SAAS,0BAA0B,MAAM,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
|
}
|
|
@@ -162,14 +162,14 @@ export declare const oasRequestSchema: z.ZodObject<{
|
|
|
162
162
|
base64?: string | undefined;
|
|
163
163
|
}>>>;
|
|
164
164
|
}, "strip", z.ZodTypeAny, {
|
|
165
|
-
encoding: "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "
|
|
165
|
+
encoding: "binary" | "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "text/html" | "application/javascript" | "application/yaml" | "application/edn";
|
|
166
166
|
content: string | Record<string, any>;
|
|
167
167
|
file?: {
|
|
168
168
|
url: string;
|
|
169
169
|
base64?: string | undefined;
|
|
170
170
|
} | null | undefined;
|
|
171
171
|
}, {
|
|
172
|
-
encoding: "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "
|
|
172
|
+
encoding: "binary" | "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "text/html" | "application/javascript" | "application/yaml" | "application/edn";
|
|
173
173
|
content: string | Record<string, any>;
|
|
174
174
|
file?: {
|
|
175
175
|
url: string;
|
|
@@ -201,7 +201,7 @@ export declare const oasRequestSchema: z.ZodObject<{
|
|
|
201
201
|
};
|
|
202
202
|
name?: string | undefined;
|
|
203
203
|
body?: {
|
|
204
|
-
encoding: "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "
|
|
204
|
+
encoding: "binary" | "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "text/html" | "application/javascript" | "application/yaml" | "application/edn";
|
|
205
205
|
content: string | Record<string, any>;
|
|
206
206
|
file?: {
|
|
207
207
|
url: string;
|
|
@@ -217,7 +217,7 @@ export declare const oasRequestSchema: z.ZodObject<{
|
|
|
217
217
|
};
|
|
218
218
|
name?: string | undefined;
|
|
219
219
|
body?: {
|
|
220
|
-
encoding: "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "
|
|
220
|
+
encoding: "binary" | "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "text/html" | "application/javascript" | "application/yaml" | "application/edn";
|
|
221
221
|
content: string | Record<string, any>;
|
|
222
222
|
file?: {
|
|
223
223
|
url: string;
|
|
@@ -268,7 +268,7 @@ export declare const oasRequestSchema: z.ZodObject<{
|
|
|
268
268
|
};
|
|
269
269
|
name?: string | undefined;
|
|
270
270
|
body?: {
|
|
271
|
-
encoding: "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "
|
|
271
|
+
encoding: "binary" | "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "text/html" | "application/javascript" | "application/yaml" | "application/edn";
|
|
272
272
|
content: string | Record<string, any>;
|
|
273
273
|
file?: {
|
|
274
274
|
url: string;
|
|
@@ -316,7 +316,7 @@ export declare const oasRequestSchema: z.ZodObject<{
|
|
|
316
316
|
};
|
|
317
317
|
name?: string | undefined;
|
|
318
318
|
body?: {
|
|
319
|
-
encoding: "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "
|
|
319
|
+
encoding: "binary" | "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "text/html" | "application/javascript" | "application/yaml" | "application/edn";
|
|
320
320
|
content: string | Record<string, any>;
|
|
321
321
|
file?: {
|
|
322
322
|
url: string;
|
|
@@ -455,14 +455,14 @@ export declare const requestSchema: z.ZodObject<z.objectUtil.extendShape<z.objec
|
|
|
455
455
|
base64?: string | undefined;
|
|
456
456
|
}>>>;
|
|
457
457
|
}, "strip", z.ZodTypeAny, {
|
|
458
|
-
encoding: "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "
|
|
458
|
+
encoding: "binary" | "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "text/html" | "application/javascript" | "application/yaml" | "application/edn";
|
|
459
459
|
content: string | Record<string, any>;
|
|
460
460
|
file?: {
|
|
461
461
|
url: string;
|
|
462
462
|
base64?: string | undefined;
|
|
463
463
|
} | null | undefined;
|
|
464
464
|
}, {
|
|
465
|
-
encoding: "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "
|
|
465
|
+
encoding: "binary" | "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "text/html" | "application/javascript" | "application/yaml" | "application/edn";
|
|
466
466
|
content: string | Record<string, any>;
|
|
467
467
|
file?: {
|
|
468
468
|
url: string;
|
|
@@ -494,7 +494,7 @@ export declare const requestSchema: z.ZodObject<z.objectUtil.extendShape<z.objec
|
|
|
494
494
|
};
|
|
495
495
|
name?: string | undefined;
|
|
496
496
|
body?: {
|
|
497
|
-
encoding: "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "
|
|
497
|
+
encoding: "binary" | "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "text/html" | "application/javascript" | "application/yaml" | "application/edn";
|
|
498
498
|
content: string | Record<string, any>;
|
|
499
499
|
file?: {
|
|
500
500
|
url: string;
|
|
@@ -510,7 +510,7 @@ export declare const requestSchema: z.ZodObject<z.objectUtil.extendShape<z.objec
|
|
|
510
510
|
};
|
|
511
511
|
name?: string | undefined;
|
|
512
512
|
body?: {
|
|
513
|
-
encoding: "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "
|
|
513
|
+
encoding: "binary" | "application/json" | "application/octet-stream" | "application/x-www-form-urlencoded" | "application/xml" | "multipart/form-data" | "text/plain" | "text/html" | "application/javascript" | "application/yaml" | "application/edn";
|
|
514
514
|
content: string | Record<string, any>;
|
|
515
515
|
file?: {
|
|
516
516
|
url: string;
|
|
@@ -41,6 +41,7 @@ export declare const getSchemes: (selectedSecuritySchemes: Operation["selectedSe
|
|
|
41
41
|
"x-scalar-client-id": string;
|
|
42
42
|
tokenUrl: string;
|
|
43
43
|
clientSecret: string;
|
|
44
|
+
"x-scalar-security-query"?: Record<string, string> | undefined;
|
|
44
45
|
} | undefined;
|
|
45
46
|
implicit?: {
|
|
46
47
|
type: "implicit";
|
|
@@ -51,6 +52,7 @@ export declare const getSchemes: (selectedSecuritySchemes: Operation["selectedSe
|
|
|
51
52
|
"x-scalar-client-id": string;
|
|
52
53
|
authorizationUrl: string;
|
|
53
54
|
"x-scalar-redirect-uri": string;
|
|
55
|
+
"x-scalar-security-query"?: Record<string, string> | undefined;
|
|
54
56
|
} | undefined;
|
|
55
57
|
clientCredentials?: {
|
|
56
58
|
type: "clientCredentials";
|
|
@@ -61,6 +63,7 @@ export declare const getSchemes: (selectedSecuritySchemes: Operation["selectedSe
|
|
|
61
63
|
"x-scalar-client-id": string;
|
|
62
64
|
tokenUrl: string;
|
|
63
65
|
clientSecret: string;
|
|
66
|
+
"x-scalar-security-query"?: Record<string, string> | undefined;
|
|
64
67
|
} | undefined;
|
|
65
68
|
authorizationCode?: {
|
|
66
69
|
type: "authorizationCode";
|
|
@@ -74,6 +77,7 @@ export declare const getSchemes: (selectedSecuritySchemes: Operation["selectedSe
|
|
|
74
77
|
tokenUrl: string;
|
|
75
78
|
clientSecret: string;
|
|
76
79
|
"x-usePkce": "SHA-256" | "plain" | "no";
|
|
80
|
+
"x-scalar-security-query"?: Record<string, string> | undefined;
|
|
77
81
|
} | undefined;
|
|
78
82
|
};
|
|
79
83
|
description?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-schemes.d.ts","sourceRoot":"","sources":["../../../src/helpers/security/get-schemes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAG1D,2IAA2I;AAC3I,eAAO,MAAM,UAAU,4BACI,SAAS,CAAC,4BAA4B,CAAC,mBAC/C,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"get-schemes.d.ts","sourceRoot":"","sources":["../../../src/helpers/security/get-schemes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAG1D,2IAA2I;AAC3I,eAAO,MAAM,UAAU,4BACI,SAAS,CAAC,4BAA4B,CAAC,mBAC/C,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAO2tnE,CAAC;;;;;;;;;;;qCAA0X,CAAC;;gBAA6E,CAAC;;;;;;;;;qCAAiV,CAAC;;yBAAsF,CAAC;;;;;;;;;qCAAuU,CAAC;;yBAAsF,CAAC;;;;;;;;;;;;qCAA+c,CAAC;;;;;IAD5/qE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-example-from-schema.d.ts","sourceRoot":"","sources":["../../src/spec-getters/get-example-from-schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-example-from-schema.d.ts","sourceRoot":"","sources":["../../src/spec-getters/get-example-from-schema.ts"],"names":[],"mappings":"AA8DA;;GAEG;AACH,eAAO,MAAM,oBAAoB,WACvB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,YACjB;IACR;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAA;IACb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACvB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC/B;;;OAGG;IACH,8BAA8B,CAAC,EAAE,OAAO,CAAA;CACzC,UACM,MAAM,iBACE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,SAC3B,MAAM,KACZ,GAqRF,CAAA"}
|
|
@@ -31,8 +31,11 @@ const genericExampleValues = {
|
|
|
31
31
|
"uuid": "123e4567-e89b-12d3-a456-426614174000",
|
|
32
32
|
"object-id": "6592008029c8c3e4dc76256c"
|
|
33
33
|
};
|
|
34
|
-
function guessFromFormat(schema, fallback = "") {
|
|
35
|
-
|
|
34
|
+
function guessFromFormat(schema, makeUpRandomData = false, fallback = "") {
|
|
35
|
+
if (schema.format === "binary") {
|
|
36
|
+
return new File([""], "filename");
|
|
37
|
+
}
|
|
38
|
+
return makeUpRandomData ? genericExampleValues[schema.format] ?? fallback : "";
|
|
36
39
|
}
|
|
37
40
|
const resultCache = /* @__PURE__ */ new WeakMap();
|
|
38
41
|
function cache(schema, result) {
|
|
@@ -178,7 +181,7 @@ const getExampleFromSchema = (schema, options, level = 0, parentSchema, name) =>
|
|
|
178
181
|
return [];
|
|
179
182
|
}
|
|
180
183
|
const exampleValues = {
|
|
181
|
-
string:
|
|
184
|
+
string: guessFromFormat(schema, makeUpRandomData, options?.emptyString),
|
|
182
185
|
boolean: true,
|
|
183
186
|
integer: schema.min ?? 1,
|
|
184
187
|
number: schema.min ?? 1,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/spec-getters/get-example-from-schema.ts"],
|
|
4
|
-
"sourcesContent": ["/** Hard limit for rendering circular references */\nconst MAX_LEVELS_DEEP = 5\n/** Sets the max number of properties after the third level to prevent exponential horizontal growth */\nconst MAX_PROPERTIES = 10\n\nconst genericExampleValues: Record<string, string> = {\n // 'date-time': '1970-01-01T00:00:00Z',\n 'date-time': new Date().toISOString(),\n // 'date': '1970-01-01',\n 'date': new Date().toISOString().split('T')[0]!,\n 'email': 'hello@example.com',\n 'hostname': 'example.com',\n // https://tools.ietf.org/html/rfc6531#section-3.3\n 'idn-email': 'jane.doe@example.com',\n // https://tools.ietf.org/html/rfc5890#section-2.3.2.3\n 'idn-hostname': 'example.com',\n 'ipv4': '127.0.0.1',\n 'ipv6': '51d4:7fab:bfbf:b7d7:b2cb:d4b4:3dad:d998',\n 'iri-reference': '/entitiy/1',\n // https://tools.ietf.org/html/rfc3987\n 'iri': 'https://example.com/entity/123',\n 'json-pointer': '/nested/objects',\n 'password': 'super-secret',\n 'regex': '/[a-z]/',\n // https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01\n 'relative-json-pointer': '1/nested/objects',\n // full-time in https://tools.ietf.org/html/rfc3339#section-5.6\n // 'time': '00:00:00Z',\n 'time': new Date().toISOString().split('T')[1]!.split('.')[0]!,\n // either a URI or relative-reference https://tools.ietf.org/html/rfc3986#section-4.1\n 'uri-reference': '../folder',\n 'uri-template': 'https://example.com/{id}',\n 'uri': 'https://example.com',\n 'uuid': '123e4567-e89b-12d3-a456-426614174000',\n 'object-id': '6592008029c8c3e4dc76256c',\n}\n\n/**\n * We can use the `format` to generate some random values.\n */\nfunction guessFromFormat(schema: Record<string, any>, fallback: string = '') {\n return genericExampleValues[schema.format] ?? fallback\n}\n\n/** Map of all the results */\nconst resultCache = new WeakMap<Record<string, any>, any>()\n\n/** Store result in the cache, and return the result */\nfunction cache(schema: Record<string, any>, result: unknown) {\n // Avoid unnecessary WeakMap operations for primitive values\n if (typeof result !== 'object' || result === null) {\n return result\n }\n\n resultCache.set(schema, result)\n\n return result\n}\n\n/**\n * This function takes an OpenAPI schema and generates an example from it\n */\nexport const getExampleFromSchema = (\n schema: Record<string, any>,\n options?: {\n /**\n * The fallback string for empty string values.\n * @default ''\n */\n emptyString?: string\n /**\n * Whether to use the XML tag names as keys\n * @default false\n */\n xml?: boolean\n /**\n * Whether to show read-only/write-only properties. Otherwise all properties are shown.\n * @default undefined\n */\n mode?: 'read' | 'write'\n /**\n * Dynamic values to add to the example.\n */\n variables?: Record<string, any>\n /**\n * Whether to omit empty and optional properties.\n * @default false\n */\n omitEmptyAndOptionalProperties?: boolean\n },\n level: number = 0,\n parentSchema?: Record<string, any>,\n name?: string,\n): any => {\n // Check if the result is already cached\n if (resultCache.has(schema)) {\n return resultCache.get(schema)\n }\n\n // Check whether it\u2019s a circular reference\n if (level === MAX_LEVELS_DEEP + 1) {\n try {\n // Fails if it contains a circular reference\n JSON.stringify(schema)\n } catch {\n return '[Circular Reference]'\n }\n }\n\n // Sometimes, we just want the structure and no values.\n // But if `emptyString` is set, we do want to see some values.\n const makeUpRandomData = !!options?.emptyString\n\n // If the property is deprecated anyway, we don\u2019t want to show it.\n if (schema.deprecated) {\n return undefined\n }\n\n // Check if the property is read-only/write-only\n if ((options?.mode === 'write' && schema.readOnly) || (options?.mode === 'read' && schema.writeOnly)) {\n return undefined\n }\n\n // Use given variables as values\n if (schema['x-variable']) {\n const value = options?.variables?.[schema['x-variable']]\n\n // Return the value if it\u2019s defined\n if (value !== undefined) {\n // Type-casting\n if (schema.type === 'number' || schema.type === 'integer') {\n return Number.parseInt(value, 10)\n }\n\n return cache(schema, value)\n }\n }\n\n // Use the first example, if there\u2019s an array\n if (Array.isArray(schema.examples) && schema.examples.length > 0) {\n return cache(schema, schema.examples[0])\n }\n\n // Use an example, if there\u2019s one\n if (schema.example !== undefined) {\n return cache(schema, schema.example)\n }\n\n // Use a default value, if there\u2019s one\n if (schema.default !== undefined) {\n return cache(schema, schema.default)\n }\n\n // enum: [ 'available', 'pending', 'sold' ]\n if (Array.isArray(schema.enum) && schema.enum.length > 0) {\n return cache(schema, schema.enum[0])\n }\n\n // Check if the property is required\n const isObjectOrArray =\n schema.type === 'object' ||\n schema.type === 'array' ||\n !!schema.allOf?.at?.(0) ||\n !!schema.anyOf?.at?.(0) ||\n !!schema.oneOf?.at?.(0)\n if (!isObjectOrArray && options?.omitEmptyAndOptionalProperties === true) {\n const isRequired =\n schema.required === true ||\n parentSchema?.required === true ||\n parentSchema?.required?.includes(name ?? schema.name)\n\n if (!isRequired) {\n return undefined\n }\n }\n\n // Object\n if (schema.type === 'object' || schema.properties !== undefined) {\n const response: Record<string, any> = {}\n let propertyCount = 0\n\n // Regular properties\n if (schema.properties !== undefined) {\n for (const propertyName in schema.properties) {\n if (Object.prototype.hasOwnProperty.call(schema.properties, propertyName)) {\n // Only apply property limit for nested levels (level > 0)\n if (level > 3 && propertyCount >= MAX_PROPERTIES) {\n response['...'] = '[Additional Properties Truncated]'\n break\n }\n\n const property = schema.properties[propertyName]\n const propertyXmlTagName = options?.xml ? property.xml?.name : undefined\n\n const value = getExampleFromSchema(property, options, level + 1, schema, propertyName)\n\n if (typeof value !== 'undefined') {\n response[propertyXmlTagName ?? propertyName] = value\n propertyCount++\n }\n }\n }\n }\n\n // Pattern properties (regex)\n if (schema.patternProperties !== undefined) {\n for (const pattern in schema.patternProperties) {\n if (Object.prototype.hasOwnProperty.call(schema.patternProperties, pattern)) {\n const property = schema.patternProperties[pattern]\n\n // Use the regex pattern as an example key\n const exampleKey = pattern\n\n response[exampleKey] = getExampleFromSchema(property, options, level + 1, schema, exampleKey)\n }\n }\n }\n\n // Additional properties\n if (schema.additionalProperties !== undefined) {\n const anyTypeIsValid =\n // true\n schema.additionalProperties === true ||\n // or an empty object {}\n (typeof schema.additionalProperties === 'object' && !Object.keys(schema.additionalProperties).length)\n\n if (anyTypeIsValid) {\n response['ANY_ADDITIONAL_PROPERTY'] = 'anything'\n } else if (schema.additionalProperties !== false) {\n response['ANY_ADDITIONAL_PROPERTY'] = getExampleFromSchema(schema.additionalProperties, options, level + 1)\n }\n }\n\n if (schema.anyOf !== undefined) {\n Object.assign(response, getExampleFromSchema(schema.anyOf[0], options, level + 1))\n } else if (schema.oneOf !== undefined) {\n Object.assign(response, getExampleFromSchema(schema.oneOf[0], options, level + 1))\n } else if (schema.allOf !== undefined) {\n Object.assign(\n response,\n ...schema.allOf\n .map((item: Record<string, any>) => getExampleFromSchema(item, options, level + 1, schema))\n .filter((item: any) => item !== undefined),\n )\n }\n\n return cache(schema, response)\n }\n\n // Array\n if (schema.type === 'array' || schema.items !== undefined) {\n const itemsXmlTagName = schema?.items?.xml?.name\n const wrapItems = !!(options?.xml && schema.xml?.wrapped && itemsXmlTagName)\n\n if (schema.example !== undefined) {\n return cache(schema, wrapItems ? { [itemsXmlTagName]: schema.example } : schema.example)\n }\n\n // Check whether the array has a anyOf, oneOf, or allOf rule\n if (schema.items) {\n // First handle allOf separately since it needs special handling\n if (schema.items.allOf) {\n // If the first item is an object type, merge all schemas\n if (schema.items.allOf[0].type === 'object') {\n const mergedExample = getExampleFromSchema(\n { type: 'object', allOf: schema.items.allOf },\n options,\n level + 1,\n schema,\n )\n\n return cache(schema, wrapItems ? [{ [itemsXmlTagName]: mergedExample }] : [mergedExample])\n }\n // For non-objects (like strings), collect all examples\n const examples = schema.items.allOf\n .map((item: Record<string, any>) => getExampleFromSchema(item, options, level + 1, schema))\n .filter((item: any) => item !== undefined)\n\n return cache(schema, wrapItems ? examples.map((example: any) => ({ [itemsXmlTagName]: example })) : examples)\n }\n\n // Handle other rules (anyOf, oneOf)\n const rules = ['anyOf', 'oneOf']\n for (const rule of rules) {\n if (!schema.items[rule]) {\n continue\n }\n\n const schemas = schema.items[rule].slice(0, 1)\n const exampleFromRule = schemas\n .map((item: Record<string, any>) => getExampleFromSchema(item, options, level + 1, schema))\n .filter((item: any) => item !== undefined)\n\n return cache(schema, wrapItems ? [{ [itemsXmlTagName]: exampleFromRule }] : exampleFromRule)\n }\n }\n\n if (schema.items?.type) {\n const exampleFromSchema = getExampleFromSchema(schema.items, options, level + 1)\n\n return wrapItems ? [{ [itemsXmlTagName]: exampleFromSchema }] : [exampleFromSchema]\n }\n\n return []\n }\n\n const exampleValues: Record<any, any> = {\n string: makeUpRandomData ? guessFromFormat(schema, options?.emptyString) : '',\n boolean: true,\n integer: schema.min ?? 1,\n number: schema.min ?? 1,\n array: [],\n }\n\n if (schema.type !== undefined && exampleValues[schema.type] !== undefined) {\n return cache(schema, exampleValues[schema.type])\n }\n\n const discriminateSchema = schema.oneOf || schema.anyOf\n // Check if property has the `oneOf` | `anyOf` key\n if (Array.isArray(discriminateSchema) && discriminateSchema.length > 0) {\n // Get the first item from the `oneOf` | `anyOf` array\n const firstOneOfItem = discriminateSchema[0]\n\n // Return an example for the first item\n return getExampleFromSchema(firstOneOfItem, options, level + 1)\n }\n\n // Check if schema has the `allOf` key\n if (Array.isArray(schema.allOf)) {\n let example: any = null\n\n // Loop through all `allOf` schemas\n schema.allOf.forEach((allOfItem: Record<string, any>) => {\n // Return an example from the schema\n const newExample = getExampleFromSchema(allOfItem, options, level + 1)\n\n // Merge or overwrite the example\n example =\n typeof newExample === 'object' && typeof example === 'object'\n ? {\n ...(example ?? {}),\n ...newExample,\n }\n : Array.isArray(newExample) && Array.isArray(example)\n ? [...(example ?? {}), ...newExample]\n : newExample\n })\n\n return cache(schema, example)\n }\n\n // Check if schema is a union type\n if (Array.isArray(schema.type)) {\n // Return null if the type is nullable\n if (schema.type.includes('null')) {\n return null\n }\n // Return an example for the first type in the union\n const exampleValue = exampleValues[schema.type[0]]\n if (exampleValue !== undefined) {\n return cache(schema, exampleValue)\n }\n }\n\n // Warn if the type is unknown \u2026\n // console.warn(`[getExampleFromSchema] Unknown property type \"${schema.type}\".`)\n\n // \u2026 and just return null for now.\n return null\n}\n"],
|
|
5
|
-
"mappings": "AACA,MAAM,kBAAkB;AAExB,MAAM,iBAAiB;AAEvB,MAAM,uBAA+C;AAAA;AAAA,EAEnD,cAAa,oBAAI,KAAK,GAAE,YAAY;AAAA;AAAA,EAEpC,SAAQ,oBAAI,KAAK,GAAE,YAAY,EAAE,MAAM,GAAG,EAAE,CAAC;AAAA,EAC7C,SAAS;AAAA,EACT,YAAY;AAAA;AAAA,EAEZ,aAAa;AAAA;AAAA,EAEb,gBAAgB;AAAA,EAChB,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,iBAAiB;AAAA;AAAA,EAEjB,OAAO;AAAA,EACP,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,SAAS;AAAA;AAAA,EAET,yBAAyB;AAAA;AAAA;AAAA,EAGzB,SAAQ,oBAAI,KAAK,GAAE,YAAY,EAAE,MAAM,GAAG,EAAE,CAAC,EAAG,MAAM,GAAG,EAAE,CAAC;AAAA;AAAA,EAE5D,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,aAAa;AACf;AAKA,SAAS,gBAAgB,QAA6B,WAAmB,IAAI;
|
|
4
|
+
"sourcesContent": ["/** Hard limit for rendering circular references */\nconst MAX_LEVELS_DEEP = 5\n/** Sets the max number of properties after the third level to prevent exponential horizontal growth */\nconst MAX_PROPERTIES = 10\n\nconst genericExampleValues: Record<string, string> = {\n // 'date-time': '1970-01-01T00:00:00Z',\n 'date-time': new Date().toISOString(),\n // 'date': '1970-01-01',\n 'date': new Date().toISOString().split('T')[0]!,\n 'email': 'hello@example.com',\n 'hostname': 'example.com',\n // https://tools.ietf.org/html/rfc6531#section-3.3\n 'idn-email': 'jane.doe@example.com',\n // https://tools.ietf.org/html/rfc5890#section-2.3.2.3\n 'idn-hostname': 'example.com',\n 'ipv4': '127.0.0.1',\n 'ipv6': '51d4:7fab:bfbf:b7d7:b2cb:d4b4:3dad:d998',\n 'iri-reference': '/entitiy/1',\n // https://tools.ietf.org/html/rfc3987\n 'iri': 'https://example.com/entity/123',\n 'json-pointer': '/nested/objects',\n 'password': 'super-secret',\n 'regex': '/[a-z]/',\n // https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01\n 'relative-json-pointer': '1/nested/objects',\n // full-time in https://tools.ietf.org/html/rfc3339#section-5.6\n // 'time': '00:00:00Z',\n 'time': new Date().toISOString().split('T')[1]!.split('.')[0]!,\n // either a URI or relative-reference https://tools.ietf.org/html/rfc3986#section-4.1\n 'uri-reference': '../folder',\n 'uri-template': 'https://example.com/{id}',\n 'uri': 'https://example.com',\n 'uuid': '123e4567-e89b-12d3-a456-426614174000',\n 'object-id': '6592008029c8c3e4dc76256c',\n}\n\n/**\n * We can use the `format` to generate some random values.\n */\nfunction guessFromFormat(schema: Record<string, any>, makeUpRandomData: boolean = false, fallback: string = '') {\n if (schema.format === 'binary') {\n return new File([''], 'filename')\n }\n return makeUpRandomData ? (genericExampleValues[schema.format] ?? fallback) : ''\n}\n\n/** Map of all the results */\nconst resultCache = new WeakMap<Record<string, any>, any>()\n\n/** Store result in the cache, and return the result */\nfunction cache(schema: Record<string, any>, result: unknown) {\n // Avoid unnecessary WeakMap operations for primitive values\n if (typeof result !== 'object' || result === null) {\n return result\n }\n\n resultCache.set(schema, result)\n\n return result\n}\n\n/**\n * This function takes an OpenAPI schema and generates an example from it\n */\nexport const getExampleFromSchema = (\n schema: Record<string, any>,\n options?: {\n /**\n * The fallback string for empty string values.\n * @default ''\n */\n emptyString?: string\n /**\n * Whether to use the XML tag names as keys\n * @default false\n */\n xml?: boolean\n /**\n * Whether to show read-only/write-only properties. Otherwise all properties are shown.\n * @default undefined\n */\n mode?: 'read' | 'write'\n /**\n * Dynamic values to add to the example.\n */\n variables?: Record<string, any>\n /**\n * Whether to omit empty and optional properties.\n * @default false\n */\n omitEmptyAndOptionalProperties?: boolean\n },\n level: number = 0,\n parentSchema?: Record<string, any>,\n name?: string,\n): any => {\n // Check if the result is already cached\n if (resultCache.has(schema)) {\n return resultCache.get(schema)\n }\n\n // Check whether it\u2019s a circular reference\n if (level === MAX_LEVELS_DEEP + 1) {\n try {\n // Fails if it contains a circular reference\n JSON.stringify(schema)\n } catch {\n return '[Circular Reference]'\n }\n }\n\n // Sometimes, we just want the structure and no values.\n // But if `emptyString` is set, we do want to see some values.\n const makeUpRandomData = !!options?.emptyString\n\n // If the property is deprecated anyway, we don\u2019t want to show it.\n if (schema.deprecated) {\n return undefined\n }\n\n // Check if the property is read-only/write-only\n if ((options?.mode === 'write' && schema.readOnly) || (options?.mode === 'read' && schema.writeOnly)) {\n return undefined\n }\n\n // Use given variables as values\n if (schema['x-variable']) {\n const value = options?.variables?.[schema['x-variable']]\n\n // Return the value if it\u2019s defined\n if (value !== undefined) {\n // Type-casting\n if (schema.type === 'number' || schema.type === 'integer') {\n return Number.parseInt(value, 10)\n }\n\n return cache(schema, value)\n }\n }\n\n // Use the first example, if there\u2019s an array\n if (Array.isArray(schema.examples) && schema.examples.length > 0) {\n return cache(schema, schema.examples[0])\n }\n\n // Use an example, if there\u2019s one\n if (schema.example !== undefined) {\n return cache(schema, schema.example)\n }\n\n // Use a default value, if there\u2019s one\n if (schema.default !== undefined) {\n return cache(schema, schema.default)\n }\n\n // enum: [ 'available', 'pending', 'sold' ]\n if (Array.isArray(schema.enum) && schema.enum.length > 0) {\n return cache(schema, schema.enum[0])\n }\n\n // Check if the property is required\n const isObjectOrArray =\n schema.type === 'object' ||\n schema.type === 'array' ||\n !!schema.allOf?.at?.(0) ||\n !!schema.anyOf?.at?.(0) ||\n !!schema.oneOf?.at?.(0)\n if (!isObjectOrArray && options?.omitEmptyAndOptionalProperties === true) {\n const isRequired =\n schema.required === true ||\n parentSchema?.required === true ||\n parentSchema?.required?.includes(name ?? schema.name)\n\n if (!isRequired) {\n return undefined\n }\n }\n\n // Object\n if (schema.type === 'object' || schema.properties !== undefined) {\n const response: Record<string, any> = {}\n let propertyCount = 0\n\n // Regular properties\n if (schema.properties !== undefined) {\n for (const propertyName in schema.properties) {\n if (Object.prototype.hasOwnProperty.call(schema.properties, propertyName)) {\n // Only apply property limit for nested levels (level > 0)\n if (level > 3 && propertyCount >= MAX_PROPERTIES) {\n response['...'] = '[Additional Properties Truncated]'\n break\n }\n\n const property = schema.properties[propertyName]\n const propertyXmlTagName = options?.xml ? property.xml?.name : undefined\n\n const value = getExampleFromSchema(property, options, level + 1, schema, propertyName)\n\n if (typeof value !== 'undefined') {\n response[propertyXmlTagName ?? propertyName] = value\n propertyCount++\n }\n }\n }\n }\n\n // Pattern properties (regex)\n if (schema.patternProperties !== undefined) {\n for (const pattern in schema.patternProperties) {\n if (Object.prototype.hasOwnProperty.call(schema.patternProperties, pattern)) {\n const property = schema.patternProperties[pattern]\n\n // Use the regex pattern as an example key\n const exampleKey = pattern\n\n response[exampleKey] = getExampleFromSchema(property, options, level + 1, schema, exampleKey)\n }\n }\n }\n\n // Additional properties\n if (schema.additionalProperties !== undefined) {\n const anyTypeIsValid =\n // true\n schema.additionalProperties === true ||\n // or an empty object {}\n (typeof schema.additionalProperties === 'object' && !Object.keys(schema.additionalProperties).length)\n\n if (anyTypeIsValid) {\n response['ANY_ADDITIONAL_PROPERTY'] = 'anything'\n } else if (schema.additionalProperties !== false) {\n response['ANY_ADDITIONAL_PROPERTY'] = getExampleFromSchema(schema.additionalProperties, options, level + 1)\n }\n }\n\n if (schema.anyOf !== undefined) {\n Object.assign(response, getExampleFromSchema(schema.anyOf[0], options, level + 1))\n } else if (schema.oneOf !== undefined) {\n Object.assign(response, getExampleFromSchema(schema.oneOf[0], options, level + 1))\n } else if (schema.allOf !== undefined) {\n Object.assign(\n response,\n ...schema.allOf\n .map((item: Record<string, any>) => getExampleFromSchema(item, options, level + 1, schema))\n .filter((item: any) => item !== undefined),\n )\n }\n\n return cache(schema, response)\n }\n\n // Array\n if (schema.type === 'array' || schema.items !== undefined) {\n const itemsXmlTagName = schema?.items?.xml?.name\n const wrapItems = !!(options?.xml && schema.xml?.wrapped && itemsXmlTagName)\n\n if (schema.example !== undefined) {\n return cache(schema, wrapItems ? { [itemsXmlTagName]: schema.example } : schema.example)\n }\n\n // Check whether the array has a anyOf, oneOf, or allOf rule\n if (schema.items) {\n // First handle allOf separately since it needs special handling\n if (schema.items.allOf) {\n // If the first item is an object type, merge all schemas\n if (schema.items.allOf[0].type === 'object') {\n const mergedExample = getExampleFromSchema(\n { type: 'object', allOf: schema.items.allOf },\n options,\n level + 1,\n schema,\n )\n\n return cache(schema, wrapItems ? [{ [itemsXmlTagName]: mergedExample }] : [mergedExample])\n }\n // For non-objects (like strings), collect all examples\n const examples = schema.items.allOf\n .map((item: Record<string, any>) => getExampleFromSchema(item, options, level + 1, schema))\n .filter((item: any) => item !== undefined)\n\n return cache(schema, wrapItems ? examples.map((example: any) => ({ [itemsXmlTagName]: example })) : examples)\n }\n\n // Handle other rules (anyOf, oneOf)\n const rules = ['anyOf', 'oneOf']\n for (const rule of rules) {\n if (!schema.items[rule]) {\n continue\n }\n\n const schemas = schema.items[rule].slice(0, 1)\n const exampleFromRule = schemas\n .map((item: Record<string, any>) => getExampleFromSchema(item, options, level + 1, schema))\n .filter((item: any) => item !== undefined)\n\n return cache(schema, wrapItems ? [{ [itemsXmlTagName]: exampleFromRule }] : exampleFromRule)\n }\n }\n\n if (schema.items?.type) {\n const exampleFromSchema = getExampleFromSchema(schema.items, options, level + 1)\n\n return wrapItems ? [{ [itemsXmlTagName]: exampleFromSchema }] : [exampleFromSchema]\n }\n\n return []\n }\n\n const exampleValues: Record<any, any> = {\n string: guessFromFormat(schema, makeUpRandomData, options?.emptyString),\n boolean: true,\n integer: schema.min ?? 1,\n number: schema.min ?? 1,\n array: [],\n }\n\n if (schema.type !== undefined && exampleValues[schema.type] !== undefined) {\n return cache(schema, exampleValues[schema.type])\n }\n\n const discriminateSchema = schema.oneOf || schema.anyOf\n // Check if property has the `oneOf` | `anyOf` key\n if (Array.isArray(discriminateSchema) && discriminateSchema.length > 0) {\n // Get the first item from the `oneOf` | `anyOf` array\n const firstOneOfItem = discriminateSchema[0]\n\n // Return an example for the first item\n return getExampleFromSchema(firstOneOfItem, options, level + 1)\n }\n\n // Check if schema has the `allOf` key\n if (Array.isArray(schema.allOf)) {\n let example: any = null\n\n // Loop through all `allOf` schemas\n schema.allOf.forEach((allOfItem: Record<string, any>) => {\n // Return an example from the schema\n const newExample = getExampleFromSchema(allOfItem, options, level + 1)\n\n // Merge or overwrite the example\n example =\n typeof newExample === 'object' && typeof example === 'object'\n ? {\n ...(example ?? {}),\n ...newExample,\n }\n : Array.isArray(newExample) && Array.isArray(example)\n ? [...(example ?? {}), ...newExample]\n : newExample\n })\n\n return cache(schema, example)\n }\n\n // Check if schema is a union type\n if (Array.isArray(schema.type)) {\n // Return null if the type is nullable\n if (schema.type.includes('null')) {\n return null\n }\n // Return an example for the first type in the union\n const exampleValue = exampleValues[schema.type[0]]\n if (exampleValue !== undefined) {\n return cache(schema, exampleValue)\n }\n }\n\n // Warn if the type is unknown \u2026\n // console.warn(`[getExampleFromSchema] Unknown property type \"${schema.type}\".`)\n\n // \u2026 and just return null for now.\n return null\n}\n"],
|
|
5
|
+
"mappings": "AACA,MAAM,kBAAkB;AAEx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mBAAmB,SAAS,GAAG;AAEtE,UAAM,iBAAiB,mBAAmB,CAAC;AAG3C,WAAO,qBAAqB,gBAAgB,SAAS,QAAQ,CAAC;AAAA,EAChE;AAGA,MAAI,MAAM,QAAQ,OAAO,KAAK,GAAG;AAC/B,QAAI,UAAe;AAGnB,WAAO,MAAM,QAAQ,CAAC,cAAmC;AAEvD,YAAM,aAAa,qBAAqB,WAAW,SAAS,QAAQ,CAAC;AAGrE,gBACE,OAAO,eAAe,YAAY,OAAO,YAAY,WACjD;AAAA,QACE,GAAI,WAAW,CAAC;AAAA,QAChB,GAAG;AAAA,MACL,IACA,MAAM,QAAQ,UAAU,KAAK,MAAM,QAAQ,OAAO,IAChD,CAAC,GAAI,WAAW,CAAC,GAAI,GAAG,UAAU,IAClC;AAAA,IACV,CAAC;AAED,WAAO,MAAM,QAAQ,OAAO;AAAA,EAC9B;AAGA,MAAI,MAAM,QAAQ,OAAO,IAAI,GAAG;AAE9B,QAAI,OAAO,KAAK,SAAS,MAAM,GAAG;AAChC,aAAO;AAAA,IACT;AAEA,UAAM,eAAe,cAAc,OAAO,KAAK,CAAC,CAAC;AACjD,QAAI,iBAAiB,QAAW;AAC9B,aAAO,MAAM,QAAQ,YAAY;AAAA,IACnC;AAAA,EACF;AAMA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -7,7 +7,7 @@ export declare function getRequestBodyFromOperation(operation: Omit<TransformedO
|
|
|
7
7
|
text?: string | undefined;
|
|
8
8
|
params?: {
|
|
9
9
|
name: string;
|
|
10
|
-
value?: string;
|
|
10
|
+
value?: string | File;
|
|
11
11
|
}[];
|
|
12
12
|
} | null;
|
|
13
13
|
//# sourceMappingURL=get-request-body-from-operation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-request-body-from-operation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/get-request-body-from-operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"get-request-body-from-operation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/get-request-body-from-operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AA+C7E;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC,EACjD,kBAAkB,CAAC,EAAE,MAAM,GAAG,MAAM,EACpC,8BAA8B,CAAC,EAAE,OAAO,GACvC;IACD,QAAQ,EAAE,WAAW,CAAA;IACrB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,MAAM,CAAC,EAAE;QACP,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KACtB,EAAE,CAAA;CACJ,GAAG,IAAI,CA+JP"}
|
|
@@ -3,13 +3,16 @@ import { normalizeMimeTypeObject } from "../helpers/normalize-mime-type-object.j
|
|
|
3
3
|
import { prettyPrintJson } from "../helpers/pretty-print-json.js";
|
|
4
4
|
import { getExampleFromSchema } from "./get-example-from-schema.js";
|
|
5
5
|
import { getParametersFromOperation } from "./get-parameters-from-operation.js";
|
|
6
|
-
function getParamsFromObject(obj,
|
|
6
|
+
function getParamsFromObject(obj, nested = false, field) {
|
|
7
7
|
return Object.entries(obj).flatMap(([key, value]) => {
|
|
8
|
-
const
|
|
9
|
-
if (
|
|
10
|
-
return getParamsFromObject(value,
|
|
8
|
+
const name = field ?? key;
|
|
9
|
+
if (Array.isArray(value) && !nested) {
|
|
10
|
+
return getParamsFromObject(value, true, key);
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
if (typeof value === "object" && !(value instanceof File) && value !== null) {
|
|
13
|
+
value = JSON.stringify(value);
|
|
14
|
+
}
|
|
15
|
+
return [{ name, value }];
|
|
13
16
|
});
|
|
14
17
|
}
|
|
15
18
|
const standardMimeTypes = [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/spec-getters/get-request-body-from-operation.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ContentType, TransformedOperation } from '@scalar/types/legacy'\n\nimport { json2xml } from '@/helpers/json2xml'\nimport { normalizeMimeTypeObject } from '@/helpers/normalize-mime-type-object'\nimport { prettyPrintJson } from '@/helpers/pretty-print-json'\nimport { getExampleFromSchema } from './get-example-from-schema'\nimport { getParametersFromOperation } from './get-parameters-from-operation'\n\ntype AnyObject = Record<string, any>\n\n/**\n * Transform the object into a nested array of objects\n * that represent the key-value pairs of the object.\n */\nfunction getParamsFromObject(\n obj: AnyObject,\n
|
|
5
|
-
"mappings": "AAEA,SAAS,gBAAgB;AACzB,SAAS,+BAA+B;AACxC,SAAS,uBAAuB;AAChC,SAAS,4BAA4B;AACrC,SAAS,kCAAkC;AAQ3C,SAAS,oBACP,KACA,SAAS,
|
|
4
|
+
"sourcesContent": ["import type { ContentType, TransformedOperation } from '@scalar/types/legacy'\n\nimport { json2xml } from '@/helpers/json2xml'\nimport { normalizeMimeTypeObject } from '@/helpers/normalize-mime-type-object'\nimport { prettyPrintJson } from '@/helpers/pretty-print-json'\nimport { getExampleFromSchema } from './get-example-from-schema'\nimport { getParametersFromOperation } from './get-parameters-from-operation'\n\ntype AnyObject = Record<string, any>\n\n/**\n * Transform the object into a nested array of objects\n * that represent the key-value pairs of the object.\n */\nfunction getParamsFromObject(\n obj: AnyObject,\n nested = false,\n field?: string,\n): {\n name: string\n value: any\n}[] {\n return Object.entries(obj).flatMap(([key, value]) => {\n const name = field ?? key\n\n if (Array.isArray(value) && !nested) {\n return getParamsFromObject(value, true, key)\n }\n\n if (typeof value === 'object' && !(value instanceof File) && value !== null) {\n // Nested object inside formData field: no way to represent it, so just serialize to JSON string\n value = JSON.stringify(value)\n }\n\n return [{ name, value }]\n })\n}\n// Define preferred standard mime types (order indicates preference)\nconst standardMimeTypes: ContentType[] = [\n 'application/json',\n 'application/octet-stream',\n 'application/x-www-form-urlencoded',\n 'application/xml',\n 'multipart/form-data',\n 'text/plain',\n]\n\n/**\n * Get the request body from the operation.\n */\nexport function getRequestBodyFromOperation(\n operation: Omit<TransformedOperation, 'httpVerb'>,\n selectedExampleKey?: string | number,\n omitEmptyAndOptionalProperties?: boolean,\n): {\n mimeType: ContentType\n text?: string | undefined\n params?: {\n name: string\n value?: string | File\n }[]\n} | null {\n const originalContent = operation.information?.requestBody?.content\n const content = normalizeMimeTypeObject(originalContent)\n\n // First try to find a standard mime type\n const mimeType =\n standardMimeTypes.find((currentMimeType) => !!content?.[currentMimeType]) ??\n ((Object.keys(content ?? {})[0] || 'application/json') as ContentType)\n\n // Handle JSON-like content types (e.g., application/vnd.github+json)\n const isJsonLike = mimeType.includes('json') || mimeType.endsWith('+json')\n\n /** Examples */\n const examples = content?.[mimeType]?.examples ?? content?.['application/json']?.examples\n\n // Let\u2019s use the first example\n const selectedExample = examples?.[selectedExampleKey ?? Object.keys(examples ?? {})[0] ?? '']\n\n if (selectedExample) {\n return {\n mimeType,\n text: prettyPrintJson(selectedExample?.value),\n }\n }\n\n /**\n * Body Parameters (Swagger 2.0)\n *\n * \u201DThe payload that's appended to the HTTP request. Since there can only be one payload, there can only\n * be one body parameter. The name of the body parameter has no effect on the parameter itself and is used\n * for documentation purposes only. Since Form parameters are also in the payload, body and form\n * parameters cannot exist together for the same operation.\u201D\n */\n const bodyParameters = getParametersFromOperation(operation, 'body', false)\n\n if (bodyParameters.length > 0) {\n return {\n mimeType: 'application/json',\n text: prettyPrintJson(bodyParameters[0]?.value ?? ''),\n }\n }\n\n /**\n * FormData Parameters (Swagger 2.0)\n *\n * \u201DForm - Used to describe the payload of an HTTP request when either application/x-www-form-urlencoded,\n * multipart/form-data or both are used as the content type of the request (in Swagger's definition, the\n * consumes property of an operation). This is the only parameter type that can be used to send files,\n * thus supporting the file type. Since form parameters are sent in the payload, they cannot be declared\n * together with a body parameter for the same operation. Form parameters have a different format based on\n * the content-type used (for further details, consult http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4):\n * - application/x-www-form-urlencoded - Similar to the format of Query parameters but as a payload.\n * For example, foo=1&bar=swagger - both foo and bar are form parameters. This is normally used for simple\n * parameters that are being transferred.\n * - multipart/form-data - each parameter takes a section in the payload with an internal header.\n * For example, for the header Content-Disposition: form-data; name=\"submit-name\" the name of the parameter is\n * submit-name. This type of form parameters is more commonly used for file transfers.\u201D\n */\n\n const formDataParameters = getParametersFromOperation(operation, 'formData', false)\n\n if (formDataParameters.length > 0) {\n return {\n mimeType: 'application/x-www-form-urlencoded',\n params: formDataParameters.map((parameter) => ({\n name: parameter.name,\n /**\n * TODO: This value MUST be a string\n * Figure out why this is not always a string\n *\n * JSON.stringify is a TEMPORARY fix\n */\n value: typeof parameter.value === 'string' ? parameter.value : JSON.stringify(parameter.value),\n })),\n }\n }\n\n // If no mime type is supported, exit early\n if (!mimeType) {\n return null\n }\n\n // Get the request body object for the mime type\n const requestBodyObject = content?.[mimeType]\n\n // Get example from operation\n const example = requestBodyObject?.example ? requestBodyObject?.example : undefined\n\n // Update the JSON handling section\n if (isJsonLike) {\n const exampleFromSchema = requestBodyObject?.schema\n ? getExampleFromSchema(requestBodyObject?.schema, {\n mode: 'write',\n omitEmptyAndOptionalProperties: omitEmptyAndOptionalProperties ?? false,\n })\n : null\n\n const body = example ?? exampleFromSchema\n\n return {\n mimeType,\n text: body ? (typeof body === 'string' ? body : JSON.stringify(body, null, 2)) : undefined,\n }\n }\n\n // XML\n if (mimeType === 'application/xml') {\n const exampleFromSchema = requestBodyObject?.schema\n ? getExampleFromSchema(requestBodyObject?.schema, {\n xml: true,\n mode: 'write',\n })\n : null\n\n return {\n mimeType,\n text: example ?? json2xml(exampleFromSchema, ' '),\n }\n }\n\n // Binary data\n if (mimeType === 'application/octet-stream') {\n return {\n mimeType,\n text: 'BINARY',\n }\n }\n\n // Plain text\n if (mimeType === 'text/plain') {\n const exampleFromSchema = requestBodyObject?.schema\n ? getExampleFromSchema(requestBodyObject?.schema, {\n xml: true,\n mode: 'write',\n })\n : null\n\n return {\n mimeType,\n text: example ?? exampleFromSchema ?? '',\n }\n }\n\n // URL encoded data\n if (mimeType === 'multipart/form-data' || mimeType === 'application/x-www-form-urlencoded') {\n const exampleFromSchema = requestBodyObject?.schema\n ? getExampleFromSchema(requestBodyObject?.schema, {\n xml: true,\n mode: 'write',\n })\n : null\n\n return {\n mimeType,\n params: getParamsFromObject(example ?? exampleFromSchema ?? {}),\n }\n }\n\n return null\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,gBAAgB;AACzB,SAAS,+BAA+B;AACxC,SAAS,uBAAuB;AAChC,SAAS,4BAA4B;AACrC,SAAS,kCAAkC;AAQ3C,SAAS,oBACP,KACA,SAAS,OACT,OAIE;AACF,SAAO,OAAO,QAAQ,GAAG,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AACnD,UAAM,OAAO,SAAS;AAEtB,QAAI,MAAM,QAAQ,KAAK,KAAK,CAAC,QAAQ;AACnC,aAAO,oBAAoB,OAAO,MAAM,GAAG;AAAA,IAC7C;AAEA,QAAI,OAAO,UAAU,YAAY,EAAE,iBAAiB,SAAS,UAAU,MAAM;AAE3E,cAAQ,KAAK,UAAU,KAAK;AAAA,IAC9B;AAEA,WAAO,CAAC,EAAE,MAAM,MAAM,CAAC;AAAA,EACzB,CAAC;AACH;AAEA,MAAM,oBAAmC;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAKO,SAAS,4BACd,WACA,oBACA,gCAQO;AACP,QAAM,kBAAkB,UAAU,aAAa,aAAa;AAC5D,QAAM,UAAU,wBAAwB,eAAe;AAGvD,QAAM,WACJ,kBAAkB,KAAK,CAAC,oBAAoB,CAAC,CAAC,UAAU,eAAe,CAAC,MACtE,OAAO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,OAAQ,OAAO,SAAS,WAAW,OAAO,KAAK,UAAU,MAAM,MAAM,CAAC,IAAK;AAAA,IACnF;AAAA,EACF;AAGA,MAAI,aAAa,mBAAmB;AAClC,UAAM,oBAAoB,mBAAmB,SACzC,qBAAqB,mBAAmB,QAAQ;AAAA,MAC9C,KAAK;AAAA,MACL,MAAM;AAAA,IACR,CAAC,IACD;AAEJ,WAAO;AAAA,MACL;AAAA,MACA,MAAM,WAAW,SAAS,mBAAmB,IAAI;AAAA,IACnD;AAAA,EACF;AAGA,MAAI,aAAa,4BAA4B;AAC3C,WAAO;AAAA,MACL;AAAA,MACA,MAAM;AAAA,IACR;AAAA,EACF;AAGA,MAAI,aAAa,cAAc;AAC7B,UAAM,oBAAoB,mBAAmB,SACzC,qBAAqB,mBAAmB,QAAQ;AAAA,MAC9C,KAAK;AAAA,MACL,MAAM;AAAA,IACR,CAAC,IACD;AAEJ,WAAO;AAAA,MACL;AAAA,MACA,MAAM,WAAW,qBAAqB;AAAA,IACxC;AAAA,EACF;AAGA,MAAI,aAAa,yBAAyB,aAAa,qCAAqC;AAC1F,UAAM,oBAAoB,mBAAmB,SACzC,qBAAqB,mBAAmB,QAAQ;AAAA,MAC9C,KAAK;AAAA,MACL,MAAM;AAAA,IACR,CAAC,IACD;AAEJ,WAAO;AAAA,MACL;AAAA,MACA,QAAQ,oBAAoB,WAAW,qBAAqB,CAAC,CAAC;AAAA,IAChE;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"specification",
|
|
17
17
|
"yaml"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.2.
|
|
19
|
+
"version": "0.2.143",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=18"
|
|
22
22
|
},
|
|
@@ -94,9 +94,9 @@
|
|
|
94
94
|
"yaml": "^2.4.5",
|
|
95
95
|
"zod": "3.24.1",
|
|
96
96
|
"@scalar/object-utils": "1.1.14",
|
|
97
|
-
"@scalar/
|
|
98
|
-
"@scalar/types": "0.1.
|
|
99
|
-
"@scalar/
|
|
97
|
+
"@scalar/openapi-types": "0.2.3",
|
|
98
|
+
"@scalar/types": "0.1.15",
|
|
99
|
+
"@scalar/themes": "0.11.2"
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|
|
102
102
|
"@types/node": "^20.17.10",
|
|
@@ -105,8 +105,8 @@
|
|
|
105
105
|
"vitest": "^1.6.0",
|
|
106
106
|
"zod-to-ts": "github:amritk/zod-to-ts#build",
|
|
107
107
|
"@scalar/build-tooling": "0.1.19",
|
|
108
|
-
"@scalar/openapi-
|
|
109
|
-
"@scalar/openapi-
|
|
108
|
+
"@scalar/openapi-types": "0.2.3",
|
|
109
|
+
"@scalar/openapi-parser": "0.10.17"
|
|
110
110
|
},
|
|
111
111
|
"scripts": {
|
|
112
112
|
"build": "scalar-build-esbuild",
|