zod-openapi 5.0.0-beta.17 → 5.0.0-beta.19
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/README.md +92 -7
- package/dist/api.d.mts +1 -1
- package/dist/api.d.ts +1 -1
- package/dist/api.js +1 -1
- package/dist/api.mjs +1 -1
- package/dist/{components-Ds_qyBU9.d.ts → components-BLmIpmmY.d.ts} +44 -3
- package/dist/{components-D4JjPRqN.js → components-BuSFAjHY.js} +134 -13
- package/dist/{components-uNe8arnt.d.mts → components-DkESnIB9.d.mts} +44 -3
- package/dist/{components-CncTLZvX.mjs → components-n2uYApmq.mjs} +134 -13
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -15,6 +15,9 @@ A TypeScript library which uses <a href="https://github.com/colinhacks/zod">Zod<
|
|
|
15
15
|
</div>
|
|
16
16
|
<br>
|
|
17
17
|
|
|
18
|
+
> [!TIP]
|
|
19
|
+
> Zod v4 support is available via `zod-openapi@beta`. Please read the [documentation](https://github.com/samchungy/zod-openapi/blob/v4-stash/docs/v5.md) for more information. A codegen will be available on release to help you migrate if you wish to wait.
|
|
20
|
+
|
|
18
21
|
## Installation
|
|
19
22
|
|
|
20
23
|
Install via `npm`, `yarn`, or `pnpm`:
|
|
@@ -56,7 +59,7 @@ z.string().meta({
|
|
|
56
59
|
Generates an OpenAPI documentation object.
|
|
57
60
|
|
|
58
61
|
```typescript
|
|
59
|
-
import
|
|
62
|
+
import * as z from 'zod/v4';
|
|
60
63
|
import { createDocument } from 'zod-openapi';
|
|
61
64
|
|
|
62
65
|
const jobId = z.string().meta({
|
|
@@ -207,7 +210,7 @@ createDocument(doc, {
|
|
|
207
210
|
Creates an OpenAPI Schema Object along with any registered components. OpenAPI 3.1.0 Schema Objects are fully compatible with JSON Schema.
|
|
208
211
|
|
|
209
212
|
```typescript
|
|
210
|
-
import
|
|
213
|
+
import * as z from 'zod/v4';
|
|
211
214
|
import { createSchema } from 'zod-openapi';
|
|
212
215
|
|
|
213
216
|
const jobId = z.string().meta({
|
|
@@ -263,7 +266,7 @@ const { schema, components } = createSchema(job);
|
|
|
263
266
|
|
|
264
267
|
`createSchema` takes an optional `CreateSchemaOptions` parameter which includes all options from [CreateDocumentOptions](#createdocumentoptions) plus the following:
|
|
265
268
|
|
|
266
|
-
|
|
269
|
+
```typescript
|
|
267
270
|
const { schema, components } = createSchema(job, {
|
|
268
271
|
// Input/Output context - controls how schemas are generated
|
|
269
272
|
io: 'input', // 'input' for request bodies/params, 'output' for responses
|
|
@@ -272,6 +275,7 @@ const { schema, components } = createSchema(job, {
|
|
|
272
275
|
schemaComponents: { jobId: z.string() }, // Pre-defined components to use
|
|
273
276
|
schemaComponentRefPath: '#/definitions/', // Custom path prefix for component references
|
|
274
277
|
});
|
|
278
|
+
```
|
|
275
279
|
|
|
276
280
|
### Request Parameters
|
|
277
281
|
|
|
@@ -292,7 +296,7 @@ createDocument({
|
|
|
292
296
|
},
|
|
293
297
|
},
|
|
294
298
|
});
|
|
295
|
-
|
|
299
|
+
```
|
|
296
300
|
|
|
297
301
|
If you would like to declare parameters in a more traditional way you may also declare them using the [parameters](https://swagger.io/docs/specification/describing-parameters/) key. The definitions will then all be combined.
|
|
298
302
|
|
|
@@ -636,7 +640,7 @@ createDocument({
|
|
|
636
640
|
|
|
637
641
|
Path Items can also be registered
|
|
638
642
|
|
|
639
|
-
|
|
643
|
+
```typescript
|
|
640
644
|
const pathItem: ZodOpenApiPathItemObject = {
|
|
641
645
|
id: 'some-path-item',
|
|
642
646
|
get: {
|
|
@@ -664,7 +668,88 @@ createDocument({
|
|
|
664
668
|
});
|
|
665
669
|
```
|
|
666
670
|
|
|
671
|
+
#### Security Schemes
|
|
672
|
+
|
|
673
|
+
Security Schemes can be registered for authentication methods:
|
|
674
|
+
|
|
675
|
+
```typescript
|
|
676
|
+
createDocument({
|
|
677
|
+
components: {
|
|
678
|
+
securitySchemes: {
|
|
679
|
+
bearerAuth: {
|
|
680
|
+
type: 'http',
|
|
681
|
+
scheme: 'bearer',
|
|
682
|
+
bearerFormat: 'JWT',
|
|
683
|
+
description: 'JWT Authentication',
|
|
684
|
+
},
|
|
685
|
+
},
|
|
686
|
+
},
|
|
687
|
+
});
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
#### Links
|
|
691
|
+
|
|
692
|
+
Links can be registered to describe relationships between operations:
|
|
667
693
|
|
|
694
|
+
```typescript
|
|
695
|
+
const link: ZodOpenApiLinkObject = {
|
|
696
|
+
id: 'getUserById',
|
|
697
|
+
operationId: 'getUser',
|
|
698
|
+
parameters: {
|
|
699
|
+
userId: '$request.path.id',
|
|
700
|
+
},
|
|
701
|
+
description: 'Link to get user by id',
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
// or
|
|
705
|
+
|
|
706
|
+
createDocument({
|
|
707
|
+
components: {
|
|
708
|
+
links: {
|
|
709
|
+
getUserById: {
|
|
710
|
+
operationId: 'getUser',
|
|
711
|
+
parameters: {
|
|
712
|
+
userId: '$request.path.id',
|
|
713
|
+
},
|
|
714
|
+
description: 'Link to get user by id',
|
|
715
|
+
},
|
|
716
|
+
},
|
|
717
|
+
},
|
|
718
|
+
});
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
#### Examples
|
|
722
|
+
|
|
723
|
+
Examples can be registered to provide sample values for schemas:
|
|
724
|
+
|
|
725
|
+
```typescript
|
|
726
|
+
const example: ZodOpenApiExampleObject = {
|
|
727
|
+
id: 'userExample',
|
|
728
|
+
summary: 'A sample user',
|
|
729
|
+
value: {
|
|
730
|
+
id: '123',
|
|
731
|
+
name: 'Jane Doe',
|
|
732
|
+
email: 'jane@example.com',
|
|
733
|
+
},
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
// or
|
|
737
|
+
|
|
738
|
+
createDocument({
|
|
739
|
+
components: {
|
|
740
|
+
examples: {
|
|
741
|
+
userExample: {
|
|
742
|
+
summary: 'A sample user',
|
|
743
|
+
value: {
|
|
744
|
+
id: '123',
|
|
745
|
+
name: 'Jane Doe',
|
|
746
|
+
email: 'jane@example.com',
|
|
747
|
+
},
|
|
748
|
+
},
|
|
749
|
+
},
|
|
750
|
+
},
|
|
751
|
+
});
|
|
752
|
+
```
|
|
668
753
|
|
|
669
754
|
### Zod Types
|
|
670
755
|
|
|
@@ -682,11 +767,11 @@ Output:
|
|
|
682
767
|
|
|
683
768
|
In general, you want to avoid using a registered input schema in an output context and vice versa. This is because the rendered input and output schemas of a simple Zod schema will differ, even with a simple Zod schema like `z.object()`.
|
|
684
769
|
|
|
685
|
-
```
|
|
770
|
+
```typescript
|
|
686
771
|
const schema = z.object({
|
|
687
772
|
name: z.string(),
|
|
688
773
|
});
|
|
689
|
-
|
|
774
|
+
```
|
|
690
775
|
|
|
691
776
|
Input schemas (request bodies, parameters):
|
|
692
777
|
|
package/dist/api.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComponentRegistry, Override, createComponents, createRegistry } from "./components-
|
|
1
|
+
import { ComponentRegistry, Override, createComponents, createRegistry } from "./components-DkESnIB9.mjs";
|
|
2
2
|
import { $ZodObject, $ZodType, $ZodTypes } from "zod/v4/core";
|
|
3
3
|
import { core } from "zod/v4";
|
|
4
4
|
|
package/dist/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComponentRegistry, Override, createComponents, createRegistry } from "./components-
|
|
1
|
+
import { ComponentRegistry, Override, createComponents, createRegistry } from "./components-BLmIpmmY.js";
|
|
2
2
|
import { $ZodObject, $ZodType, $ZodTypes } from "zod/v4/core";
|
|
3
3
|
import { core } from "zod/v4";
|
|
4
4
|
|
package/dist/api.js
CHANGED
package/dist/api.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { createComponents, createRegistry, isAnyZodType, unwrapZodObject } from "./components-
|
|
1
|
+
import { createComponents, createRegistry, isAnyZodType, unwrapZodObject } from "./components-n2uYApmq.mjs";
|
|
2
2
|
|
|
3
3
|
export { createComponents, createRegistry, isAnyZodType, unwrapZodObject };
|
|
@@ -381,9 +381,10 @@ interface ZodOpenApiRequestBodyObject extends Omit<RequestBodyObject, 'content'>
|
|
|
381
381
|
id?: string;
|
|
382
382
|
}
|
|
383
383
|
type ZodOpenApiHeadersObject = ZodObjectInput | HeadersObject;
|
|
384
|
-
interface ZodOpenApiResponseObject extends Omit<ResponseObject, 'content' | 'headers'> {
|
|
384
|
+
interface ZodOpenApiResponseObject extends Omit<ResponseObject, 'content' | 'headers' | 'links'> {
|
|
385
385
|
content?: ZodOpenApiContentObject;
|
|
386
386
|
headers?: ZodOpenApiHeadersObject;
|
|
387
|
+
links?: ZodOpenApiLinksObject;
|
|
387
388
|
/** Use this field to auto register this response object as a component */
|
|
388
389
|
id?: string;
|
|
389
390
|
}
|
|
@@ -427,7 +428,23 @@ interface ZodOpenApiPathsObject extends ISpecificationExtension {
|
|
|
427
428
|
type ZodOpenApiParameterObject = $ZodType | ParameterObject | ReferenceObject;
|
|
428
429
|
type ZodOpenApiHeaderObject = $ZodType | HeaderObject | ReferenceObject;
|
|
429
430
|
type ZodOpenApiSchemaObject = $ZodType | SchemaObject | ReferenceObject;
|
|
430
|
-
interface
|
|
431
|
+
interface ZodOpenApiSecuritySchemeObject extends SecuritySchemeObject {
|
|
432
|
+
/**
|
|
433
|
+
* Used to register this security scheme as a component.
|
|
434
|
+
*/
|
|
435
|
+
id?: string;
|
|
436
|
+
}
|
|
437
|
+
interface ZodOpenApiLinkObject extends LinkObject {
|
|
438
|
+
/** Use this field to auto register this link object as a component */
|
|
439
|
+
id?: string;
|
|
440
|
+
}
|
|
441
|
+
type ZodOpenApiLinksObject = Record<string, ZodOpenApiLinkObject | ReferenceObject>;
|
|
442
|
+
interface ZodOpenApiExampleObject extends ExampleObject {
|
|
443
|
+
/** Use this field to auto register this example object as a component */
|
|
444
|
+
id?: string;
|
|
445
|
+
}
|
|
446
|
+
type ZodOpenApiExamplesObject = Record<string, ZodOpenApiExampleObject | ReferenceObject>;
|
|
447
|
+
interface ZodOpenApiComponentsObject extends Omit<ComponentsObject, 'schemas' | 'responses' | 'requestBodies' | 'headers' | 'parameters' | 'pathItems' | 'callbacks' | 'securitySchemes' | 'examples'> {
|
|
431
448
|
parameters?: Record<string, ZodOpenApiParameterObject>;
|
|
432
449
|
schemas?: Record<string, ZodOpenApiSchemaObject>;
|
|
433
450
|
requestBodies?: Record<string, ZodOpenApiRequestBodyObject>;
|
|
@@ -435,6 +452,9 @@ interface ZodOpenApiComponentsObject extends Omit<ComponentsObject, 'schemas' |
|
|
|
435
452
|
responses?: Record<string, ZodOpenApiResponseObject>;
|
|
436
453
|
callbacks?: Record<string, ZodOpenApiCallbackObject>;
|
|
437
454
|
pathItems?: Record<string, ZodOpenApiPathItemObject>;
|
|
455
|
+
securitySchemes?: Record<string, ZodOpenApiSecuritySchemeObject>;
|
|
456
|
+
links?: Record<string, ZodOpenApiLinkObject>;
|
|
457
|
+
examples?: Record<string, ZodOpenApiExampleObject>;
|
|
438
458
|
}
|
|
439
459
|
type ZodOpenApiVersion = OpenApiVersion;
|
|
440
460
|
interface ZodOpenApiObject extends Omit<OpenAPIObject, 'openapi' | 'paths' | 'webhooks' | 'components'> {
|
|
@@ -553,6 +573,18 @@ interface ComponentRegistry {
|
|
|
553
573
|
ids: Map<string, PathItemObject | ReferenceObject>;
|
|
554
574
|
seen: WeakMap<ZodOpenApiPathItemObject, PathItemObject | ReferenceObject>;
|
|
555
575
|
};
|
|
576
|
+
securitySchemes: {
|
|
577
|
+
ids: Map<string, SecuritySchemeObject | ReferenceObject>;
|
|
578
|
+
seen: WeakMap<ZodOpenApiSecuritySchemeObject, SecuritySchemeObject | ReferenceObject>;
|
|
579
|
+
};
|
|
580
|
+
links: {
|
|
581
|
+
ids: Map<string, LinkObject | ReferenceObject>;
|
|
582
|
+
seen: WeakMap<ZodOpenApiLinkObject, LinkObject | ReferenceObject>;
|
|
583
|
+
};
|
|
584
|
+
examples: {
|
|
585
|
+
ids: Map<string, ExampleObject | ReferenceObject>;
|
|
586
|
+
seen: WeakMap<ZodOpenApiExampleObject, ExampleObject | ReferenceObject>;
|
|
587
|
+
};
|
|
556
588
|
};
|
|
557
589
|
addSchema: (schema: $ZodType, path: string[], opts: {
|
|
558
590
|
io: 'input' | 'output';
|
|
@@ -580,8 +612,17 @@ interface ComponentRegistry {
|
|
|
580
612
|
addCallback: (callback: ZodOpenApiCallbackObject, path: string[], opts?: {
|
|
581
613
|
manualId?: string;
|
|
582
614
|
}) => CallbackObject | ReferenceObject;
|
|
615
|
+
addSecurityScheme: (securityScheme: ZodOpenApiSecuritySchemeObject, path: string[], opts?: {
|
|
616
|
+
manualId?: string;
|
|
617
|
+
}) => SecuritySchemeObject | ReferenceObject;
|
|
618
|
+
addLink: (link: ZodOpenApiLinkObject, path: string[], opts?: {
|
|
619
|
+
manualId?: string;
|
|
620
|
+
}) => LinkObject | ReferenceObject;
|
|
621
|
+
addExample: (example: ZodOpenApiExampleObject, path: string[], opts?: {
|
|
622
|
+
manualId?: string;
|
|
623
|
+
}) => ExampleObject | ReferenceObject;
|
|
583
624
|
}
|
|
584
625
|
declare const createRegistry: (components?: ZodOpenApiComponentsObject) => ComponentRegistry;
|
|
585
626
|
declare const createComponents: (registry: ComponentRegistry, opts: CreateDocumentOptions) => ComponentsObject;
|
|
586
627
|
//#endregion
|
|
587
|
-
export { BaseParameterObject, CallbackObject, CallbacksObject, ComponentRegistry, ComponentsObject, ContactObject, ContentObject, CreateDocumentOptions, DiscriminatorObject, EncodingObject, EncodingPropertyObject, ExampleObject, ExamplesObject, ExternalDocumentationObject, HeaderObject, HeadersObject, IExtensionName, IExtensionType, ISpecificationExtension, InfoObject, LicenseObject, LinkObject, LinkParametersObject, LinksObject, MediaTypeObject, OAuthFlowObject, OAuthFlowsObject, OpenAPIObject, OperationObject, Override, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiVersion, createComponents, createDocument, createRegistry };
|
|
628
|
+
export { BaseParameterObject, CallbackObject, CallbacksObject, ComponentRegistry, ComponentsObject, ContactObject, ContentObject, CreateDocumentOptions, DiscriminatorObject, EncodingObject, EncodingPropertyObject, ExampleObject, ExamplesObject, ExternalDocumentationObject, HeaderObject, HeadersObject, IExtensionName, IExtensionType, ISpecificationExtension, InfoObject, LicenseObject, LinkObject, LinkParametersObject, LinksObject, MediaTypeObject, OAuthFlowObject, OAuthFlowsObject, OpenAPIObject, OperationObject, Override, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiExampleObject, ZodOpenApiExamplesObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiLinkObject, ZodOpenApiLinksObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiSecuritySchemeObject, ZodOpenApiVersion, createComponents, createDocument, createRegistry };
|
|
@@ -27,19 +27,31 @@ const zod_v4 = __toESM(require("zod/v4"));
|
|
|
27
27
|
//#region src/zod.ts
|
|
28
28
|
const isAnyZodType = (schema) => typeof schema === "object" && schema !== null && "_zod" in schema;
|
|
29
29
|
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/create/examples.ts
|
|
32
|
+
const createExamples = (examples, registry$1, path) => {
|
|
33
|
+
if (!examples) return void 0;
|
|
34
|
+
const examplesObject = {};
|
|
35
|
+
for (const [name, example] of Object.entries(examples)) {
|
|
36
|
+
const exampleObject = registry$1.addExample(example, [...path, name]);
|
|
37
|
+
examplesObject[name] = exampleObject;
|
|
38
|
+
}
|
|
39
|
+
return examplesObject;
|
|
40
|
+
};
|
|
41
|
+
|
|
30
42
|
//#endregion
|
|
31
43
|
//#region src/create/content.ts
|
|
32
|
-
const createMediaTypeObject = (
|
|
33
|
-
|
|
34
|
-
|
|
44
|
+
const createMediaTypeObject = (mediaType, ctx, path) => {
|
|
45
|
+
const { schema, examples,...rest } = mediaType;
|
|
46
|
+
const mediaTypeObject = rest;
|
|
47
|
+
if (isAnyZodType(schema)) {
|
|
48
|
+
const schemaObject = ctx.registry.addSchema(schema, [...path, "schema"], {
|
|
35
49
|
io: ctx.io,
|
|
36
50
|
source: { type: "mediaType" }
|
|
37
51
|
});
|
|
38
|
-
|
|
39
|
-
...mediaTypeObject,
|
|
40
|
-
schema: schemaObject
|
|
41
|
-
};
|
|
52
|
+
mediaTypeObject.schema = schemaObject;
|
|
42
53
|
}
|
|
54
|
+
if (examples) mediaTypeObject.examples = createExamples(examples, ctx.registry, [...path, "examples"]);
|
|
43
55
|
return mediaTypeObject;
|
|
44
56
|
};
|
|
45
57
|
const createContent = (content, ctx, path) => {
|
|
@@ -83,6 +95,18 @@ const createHeaders = (headers, registry$1, path) => {
|
|
|
83
95
|
return headers;
|
|
84
96
|
};
|
|
85
97
|
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/create/links.ts
|
|
100
|
+
const createLinks = (links, registry$1, path) => {
|
|
101
|
+
if (!links) return void 0;
|
|
102
|
+
const linksObject = {};
|
|
103
|
+
for (const [name, link] of Object.entries(links)) {
|
|
104
|
+
const linkObject = registry$1.addLink(link, [...path, name]);
|
|
105
|
+
linksObject[name] = linkObject;
|
|
106
|
+
}
|
|
107
|
+
return linksObject;
|
|
108
|
+
};
|
|
109
|
+
|
|
86
110
|
//#endregion
|
|
87
111
|
//#region src/create/parameters.ts
|
|
88
112
|
const createManualParameters = (parameters, registry$1, path) => {
|
|
@@ -206,7 +230,10 @@ const override = (ctx) => {
|
|
|
206
230
|
const mapping = {};
|
|
207
231
|
for (const [index, obj] of Object.entries(ctx.jsonSchema.oneOf)) {
|
|
208
232
|
const ref = obj.$ref;
|
|
209
|
-
if (!ref)
|
|
233
|
+
if (!ref) {
|
|
234
|
+
delete ctx.jsonSchema.discriminator;
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
210
237
|
const discriminatorValues = def.options[Number(index)]._zod.propValues?.[def.discriminator];
|
|
211
238
|
if (!discriminatorValues?.size) return;
|
|
212
239
|
for (const value of [...discriminatorValues ?? []]) {
|
|
@@ -470,6 +497,18 @@ const createRegistry = (components) => {
|
|
|
470
497
|
pathItems: {
|
|
471
498
|
ids: /* @__PURE__ */ new Map(),
|
|
472
499
|
seen: /* @__PURE__ */ new WeakMap()
|
|
500
|
+
},
|
|
501
|
+
securitySchemes: {
|
|
502
|
+
ids: /* @__PURE__ */ new Map(),
|
|
503
|
+
seen: /* @__PURE__ */ new WeakMap()
|
|
504
|
+
},
|
|
505
|
+
links: {
|
|
506
|
+
ids: /* @__PURE__ */ new Map(),
|
|
507
|
+
seen: /* @__PURE__ */ new WeakMap()
|
|
508
|
+
},
|
|
509
|
+
examples: {
|
|
510
|
+
ids: /* @__PURE__ */ new Map(),
|
|
511
|
+
seen: /* @__PURE__ */ new WeakMap()
|
|
473
512
|
}
|
|
474
513
|
},
|
|
475
514
|
addSchema: (schema, path, opts) => {
|
|
@@ -507,13 +546,20 @@ const createRegistry = (components) => {
|
|
|
507
546
|
}
|
|
508
547
|
}
|
|
509
548
|
});
|
|
510
|
-
const { id: metaId,...rest } = meta?.param ?? {};
|
|
549
|
+
const { id: metaId, examples,...rest } = meta?.param ?? {};
|
|
511
550
|
const parameterObject = {
|
|
512
|
-
...rest,
|
|
513
|
-
name,
|
|
514
551
|
in: inLocation,
|
|
515
|
-
|
|
552
|
+
name,
|
|
553
|
+
schema: schemaObject,
|
|
554
|
+
...rest
|
|
516
555
|
};
|
|
556
|
+
const examplesObject = createExamples(examples, registry$1, [
|
|
557
|
+
...path,
|
|
558
|
+
inLocation,
|
|
559
|
+
name,
|
|
560
|
+
"examples"
|
|
561
|
+
]);
|
|
562
|
+
if (examplesObject) parameterObject.examples = examplesObject;
|
|
517
563
|
if (isRequired(parameter, "input")) parameterObject.required = true;
|
|
518
564
|
if (!parameterObject.description && meta?.description) parameterObject.description = meta.description;
|
|
519
565
|
const id = metaId ?? opts?.manualId;
|
|
@@ -607,7 +653,7 @@ const createRegistry = (components) => {
|
|
|
607
653
|
addResponse: (response, path, opts) => {
|
|
608
654
|
const seenResponse = registry$1.components.responses.seen.get(response);
|
|
609
655
|
if (seenResponse) return seenResponse;
|
|
610
|
-
const { content, headers, id: metaId,...rest } = response;
|
|
656
|
+
const { content, headers, links, id: metaId,...rest } = response;
|
|
611
657
|
const responseObject = rest;
|
|
612
658
|
const maybeHeaders = createHeaders(headers, registry$1, [...path, "headers"]);
|
|
613
659
|
if (maybeHeaders) responseObject.headers = maybeHeaders;
|
|
@@ -615,6 +661,7 @@ const createRegistry = (components) => {
|
|
|
615
661
|
registry: registry$1,
|
|
616
662
|
io: "output"
|
|
617
663
|
}, [...path, "content"]);
|
|
664
|
+
if (links) responseObject.links = createLinks(links, registry$1, [...path, "links"]);
|
|
618
665
|
const id = metaId ?? opts?.manualId;
|
|
619
666
|
if (id) {
|
|
620
667
|
if (registry$1.components.responses.ids.has(id)) throw new Error(`Response "${id}" at ${path.join(" > ")} is already registered`);
|
|
@@ -648,6 +695,54 @@ const createRegistry = (components) => {
|
|
|
648
695
|
}
|
|
649
696
|
registry$1.components.callbacks.seen.set(callback, callbackObject);
|
|
650
697
|
return callbackObject;
|
|
698
|
+
},
|
|
699
|
+
addSecurityScheme: (securityScheme, path, opts) => {
|
|
700
|
+
const seenSecurityScheme = registry$1.components.securitySchemes.seen.get(securityScheme);
|
|
701
|
+
if (seenSecurityScheme) return seenSecurityScheme;
|
|
702
|
+
const { id: metaId,...rest } = securityScheme;
|
|
703
|
+
const securitySchemeObject = rest;
|
|
704
|
+
const id = metaId ?? opts?.manualId;
|
|
705
|
+
if (id) {
|
|
706
|
+
if (registry$1.components.securitySchemes.ids.has(id)) throw new Error(`SecurityScheme "${id}" at ${path.join(" > ")} is already registered`);
|
|
707
|
+
const ref = { $ref: `#/components/securitySchemes/${id}` };
|
|
708
|
+
registry$1.components.securitySchemes.ids.set(id, securitySchemeObject);
|
|
709
|
+
registry$1.components.securitySchemes.seen.set(securityScheme, ref);
|
|
710
|
+
return ref;
|
|
711
|
+
}
|
|
712
|
+
registry$1.components.securitySchemes.seen.set(securityScheme, securitySchemeObject);
|
|
713
|
+
return securitySchemeObject;
|
|
714
|
+
},
|
|
715
|
+
addLink: (link, path, opts) => {
|
|
716
|
+
const seenLink = registry$1.components.links.seen.get(link);
|
|
717
|
+
if (seenLink) return seenLink;
|
|
718
|
+
const { id: metaId,...rest } = link;
|
|
719
|
+
const linkObject = rest;
|
|
720
|
+
const id = metaId ?? opts?.manualId;
|
|
721
|
+
if (id) {
|
|
722
|
+
if (registry$1.components.links.ids.has(id)) throw new Error(`Link "${id}" at ${path.join(" > ")} is already registered`);
|
|
723
|
+
const ref = { $ref: `#/components/links/${id}` };
|
|
724
|
+
registry$1.components.links.ids.set(id, linkObject);
|
|
725
|
+
registry$1.components.links.seen.set(link, ref);
|
|
726
|
+
return ref;
|
|
727
|
+
}
|
|
728
|
+
registry$1.components.links.seen.set(link, linkObject);
|
|
729
|
+
return linkObject;
|
|
730
|
+
},
|
|
731
|
+
addExample: (example, path, opts) => {
|
|
732
|
+
const seenExample = registry$1.components.examples.seen.get(example);
|
|
733
|
+
if (seenExample) return seenExample;
|
|
734
|
+
const { id: metaId,...rest } = example;
|
|
735
|
+
const exampleObject = rest;
|
|
736
|
+
const id = metaId ?? opts?.manualId;
|
|
737
|
+
if (id) {
|
|
738
|
+
if (registry$1.components.examples.ids.has(id)) throw new Error(`Example "${id}" at ${path.join(" > ")} is already registered`);
|
|
739
|
+
const ref = { $ref: `#/components/examples/${id}` };
|
|
740
|
+
registry$1.components.examples.ids.set(id, exampleObject);
|
|
741
|
+
registry$1.components.examples.seen.set(example, ref);
|
|
742
|
+
return ref;
|
|
743
|
+
}
|
|
744
|
+
registry$1.components.examples.seen.set(example, exampleObject);
|
|
745
|
+
return exampleObject;
|
|
651
746
|
}
|
|
652
747
|
};
|
|
653
748
|
registerSchemas(components?.schemas, registry$1);
|
|
@@ -657,6 +752,9 @@ const createRegistry = (components) => {
|
|
|
657
752
|
registerPathItems(components?.pathItems, registry$1);
|
|
658
753
|
registerRequestBodies(components?.requestBodies, registry$1);
|
|
659
754
|
registerCallbacks(components?.callbacks, registry$1);
|
|
755
|
+
registerSecuritySchemes(components?.securitySchemes, registry$1);
|
|
756
|
+
registerLinks(components?.links, registry$1);
|
|
757
|
+
registerExamples(components?.examples, registry$1);
|
|
660
758
|
return registry$1;
|
|
661
759
|
};
|
|
662
760
|
const registerSchemas = (schemas, registry$1) => {
|
|
@@ -746,6 +844,26 @@ const registerPathItems = (pathItems, registry$1) => {
|
|
|
746
844
|
key
|
|
747
845
|
], { manualId: key });
|
|
748
846
|
};
|
|
847
|
+
const registerSecuritySchemes = (securitySchemes, registry$1) => {
|
|
848
|
+
if (!securitySchemes) return;
|
|
849
|
+
for (const [key, schema] of Object.entries(securitySchemes)) registry$1.addSecurityScheme(schema, [
|
|
850
|
+
"components",
|
|
851
|
+
"securitySchemes",
|
|
852
|
+
key
|
|
853
|
+
], { manualId: key });
|
|
854
|
+
};
|
|
855
|
+
const registerLinks = (links, registry$1) => {
|
|
856
|
+
if (!links) return;
|
|
857
|
+
for (const [key, schema] of Object.entries(links)) registry$1.addLink(schema, [
|
|
858
|
+
"components",
|
|
859
|
+
"links",
|
|
860
|
+
key
|
|
861
|
+
], { manualId: key });
|
|
862
|
+
};
|
|
863
|
+
const registerExamples = (examples, registry$1) => {
|
|
864
|
+
if (!examples) return;
|
|
865
|
+
for (const [key, schema] of Object.entries(examples)) registry$1.components.examples.ids.set(key, schema);
|
|
866
|
+
};
|
|
749
867
|
const createIOSchemas = (ctx) => {
|
|
750
868
|
const { schemas, components, manual } = createSchemas(Object.fromEntries(ctx.registry.components.schemas[ctx.io]), ctx);
|
|
751
869
|
for (const [key, schema] of Object.entries(components)) ctx.registry.components.schemas.ids.set(key, schema);
|
|
@@ -787,6 +905,9 @@ const createComponents = (registry$1, opts) => {
|
|
|
787
905
|
if (registry$1.components.parameters.ids.size > 0) components.parameters = Object.fromEntries(registry$1.components.parameters.ids);
|
|
788
906
|
if (registry$1.components.callbacks.ids.size > 0) components.callbacks = Object.fromEntries(registry$1.components.callbacks.ids);
|
|
789
907
|
if (registry$1.components.pathItems.ids.size > 0) components.pathItems = Object.fromEntries(registry$1.components.pathItems.ids);
|
|
908
|
+
if (registry$1.components.securitySchemes.ids.size > 0) components.securitySchemes = Object.fromEntries(registry$1.components.securitySchemes.ids);
|
|
909
|
+
if (registry$1.components.links.ids.size > 0) components.links = Object.fromEntries(registry$1.components.links.ids);
|
|
910
|
+
if (registry$1.components.examples.ids.size > 0) components.examples = Object.fromEntries(registry$1.components.examples.ids);
|
|
790
911
|
return components;
|
|
791
912
|
};
|
|
792
913
|
|
|
@@ -381,9 +381,10 @@ interface ZodOpenApiRequestBodyObject extends Omit<RequestBodyObject, 'content'>
|
|
|
381
381
|
id?: string;
|
|
382
382
|
}
|
|
383
383
|
type ZodOpenApiHeadersObject = ZodObjectInput | HeadersObject;
|
|
384
|
-
interface ZodOpenApiResponseObject extends Omit<ResponseObject, 'content' | 'headers'> {
|
|
384
|
+
interface ZodOpenApiResponseObject extends Omit<ResponseObject, 'content' | 'headers' | 'links'> {
|
|
385
385
|
content?: ZodOpenApiContentObject;
|
|
386
386
|
headers?: ZodOpenApiHeadersObject;
|
|
387
|
+
links?: ZodOpenApiLinksObject;
|
|
387
388
|
/** Use this field to auto register this response object as a component */
|
|
388
389
|
id?: string;
|
|
389
390
|
}
|
|
@@ -427,7 +428,23 @@ interface ZodOpenApiPathsObject extends ISpecificationExtension {
|
|
|
427
428
|
type ZodOpenApiParameterObject = $ZodType | ParameterObject | ReferenceObject;
|
|
428
429
|
type ZodOpenApiHeaderObject = $ZodType | HeaderObject | ReferenceObject;
|
|
429
430
|
type ZodOpenApiSchemaObject = $ZodType | SchemaObject | ReferenceObject;
|
|
430
|
-
interface
|
|
431
|
+
interface ZodOpenApiSecuritySchemeObject extends SecuritySchemeObject {
|
|
432
|
+
/**
|
|
433
|
+
* Used to register this security scheme as a component.
|
|
434
|
+
*/
|
|
435
|
+
id?: string;
|
|
436
|
+
}
|
|
437
|
+
interface ZodOpenApiLinkObject extends LinkObject {
|
|
438
|
+
/** Use this field to auto register this link object as a component */
|
|
439
|
+
id?: string;
|
|
440
|
+
}
|
|
441
|
+
type ZodOpenApiLinksObject = Record<string, ZodOpenApiLinkObject | ReferenceObject>;
|
|
442
|
+
interface ZodOpenApiExampleObject extends ExampleObject {
|
|
443
|
+
/** Use this field to auto register this example object as a component */
|
|
444
|
+
id?: string;
|
|
445
|
+
}
|
|
446
|
+
type ZodOpenApiExamplesObject = Record<string, ZodOpenApiExampleObject | ReferenceObject>;
|
|
447
|
+
interface ZodOpenApiComponentsObject extends Omit<ComponentsObject, 'schemas' | 'responses' | 'requestBodies' | 'headers' | 'parameters' | 'pathItems' | 'callbacks' | 'securitySchemes' | 'examples'> {
|
|
431
448
|
parameters?: Record<string, ZodOpenApiParameterObject>;
|
|
432
449
|
schemas?: Record<string, ZodOpenApiSchemaObject>;
|
|
433
450
|
requestBodies?: Record<string, ZodOpenApiRequestBodyObject>;
|
|
@@ -435,6 +452,9 @@ interface ZodOpenApiComponentsObject extends Omit<ComponentsObject, 'schemas' |
|
|
|
435
452
|
responses?: Record<string, ZodOpenApiResponseObject>;
|
|
436
453
|
callbacks?: Record<string, ZodOpenApiCallbackObject>;
|
|
437
454
|
pathItems?: Record<string, ZodOpenApiPathItemObject>;
|
|
455
|
+
securitySchemes?: Record<string, ZodOpenApiSecuritySchemeObject>;
|
|
456
|
+
links?: Record<string, ZodOpenApiLinkObject>;
|
|
457
|
+
examples?: Record<string, ZodOpenApiExampleObject>;
|
|
438
458
|
}
|
|
439
459
|
type ZodOpenApiVersion = OpenApiVersion;
|
|
440
460
|
interface ZodOpenApiObject extends Omit<OpenAPIObject, 'openapi' | 'paths' | 'webhooks' | 'components'> {
|
|
@@ -553,6 +573,18 @@ interface ComponentRegistry {
|
|
|
553
573
|
ids: Map<string, PathItemObject | ReferenceObject>;
|
|
554
574
|
seen: WeakMap<ZodOpenApiPathItemObject, PathItemObject | ReferenceObject>;
|
|
555
575
|
};
|
|
576
|
+
securitySchemes: {
|
|
577
|
+
ids: Map<string, SecuritySchemeObject | ReferenceObject>;
|
|
578
|
+
seen: WeakMap<ZodOpenApiSecuritySchemeObject, SecuritySchemeObject | ReferenceObject>;
|
|
579
|
+
};
|
|
580
|
+
links: {
|
|
581
|
+
ids: Map<string, LinkObject | ReferenceObject>;
|
|
582
|
+
seen: WeakMap<ZodOpenApiLinkObject, LinkObject | ReferenceObject>;
|
|
583
|
+
};
|
|
584
|
+
examples: {
|
|
585
|
+
ids: Map<string, ExampleObject | ReferenceObject>;
|
|
586
|
+
seen: WeakMap<ZodOpenApiExampleObject, ExampleObject | ReferenceObject>;
|
|
587
|
+
};
|
|
556
588
|
};
|
|
557
589
|
addSchema: (schema: $ZodType, path: string[], opts: {
|
|
558
590
|
io: 'input' | 'output';
|
|
@@ -580,8 +612,17 @@ interface ComponentRegistry {
|
|
|
580
612
|
addCallback: (callback: ZodOpenApiCallbackObject, path: string[], opts?: {
|
|
581
613
|
manualId?: string;
|
|
582
614
|
}) => CallbackObject | ReferenceObject;
|
|
615
|
+
addSecurityScheme: (securityScheme: ZodOpenApiSecuritySchemeObject, path: string[], opts?: {
|
|
616
|
+
manualId?: string;
|
|
617
|
+
}) => SecuritySchemeObject | ReferenceObject;
|
|
618
|
+
addLink: (link: ZodOpenApiLinkObject, path: string[], opts?: {
|
|
619
|
+
manualId?: string;
|
|
620
|
+
}) => LinkObject | ReferenceObject;
|
|
621
|
+
addExample: (example: ZodOpenApiExampleObject, path: string[], opts?: {
|
|
622
|
+
manualId?: string;
|
|
623
|
+
}) => ExampleObject | ReferenceObject;
|
|
583
624
|
}
|
|
584
625
|
declare const createRegistry: (components?: ZodOpenApiComponentsObject) => ComponentRegistry;
|
|
585
626
|
declare const createComponents: (registry: ComponentRegistry, opts: CreateDocumentOptions) => ComponentsObject;
|
|
586
627
|
//#endregion
|
|
587
|
-
export { BaseParameterObject, CallbackObject, CallbacksObject, ComponentRegistry, ComponentsObject, ContactObject, ContentObject, CreateDocumentOptions, DiscriminatorObject, EncodingObject, EncodingPropertyObject, ExampleObject, ExamplesObject, ExternalDocumentationObject, HeaderObject, HeadersObject, IExtensionName, IExtensionType, ISpecificationExtension, InfoObject, LicenseObject, LinkObject, LinkParametersObject, LinksObject, MediaTypeObject, OAuthFlowObject, OAuthFlowsObject, OpenAPIObject, OperationObject, Override, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiVersion, createComponents, createDocument, createRegistry };
|
|
628
|
+
export { BaseParameterObject, CallbackObject, CallbacksObject, ComponentRegistry, ComponentsObject, ContactObject, ContentObject, CreateDocumentOptions, DiscriminatorObject, EncodingObject, EncodingPropertyObject, ExampleObject, ExamplesObject, ExternalDocumentationObject, HeaderObject, HeadersObject, IExtensionName, IExtensionType, ISpecificationExtension, InfoObject, LicenseObject, LinkObject, LinkParametersObject, LinksObject, MediaTypeObject, OAuthFlowObject, OAuthFlowsObject, OpenAPIObject, OperationObject, Override, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiExampleObject, ZodOpenApiExamplesObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiLinkObject, ZodOpenApiLinksObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiSecuritySchemeObject, ZodOpenApiVersion, createComponents, createDocument, createRegistry };
|
|
@@ -4,19 +4,31 @@ import { object, registry, toJSONSchema } from "zod/v4";
|
|
|
4
4
|
//#region src/zod.ts
|
|
5
5
|
const isAnyZodType = (schema) => typeof schema === "object" && schema !== null && "_zod" in schema;
|
|
6
6
|
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/create/examples.ts
|
|
9
|
+
const createExamples = (examples, registry$1, path) => {
|
|
10
|
+
if (!examples) return void 0;
|
|
11
|
+
const examplesObject = {};
|
|
12
|
+
for (const [name, example] of Object.entries(examples)) {
|
|
13
|
+
const exampleObject = registry$1.addExample(example, [...path, name]);
|
|
14
|
+
examplesObject[name] = exampleObject;
|
|
15
|
+
}
|
|
16
|
+
return examplesObject;
|
|
17
|
+
};
|
|
18
|
+
|
|
7
19
|
//#endregion
|
|
8
20
|
//#region src/create/content.ts
|
|
9
|
-
const createMediaTypeObject = (
|
|
10
|
-
|
|
11
|
-
|
|
21
|
+
const createMediaTypeObject = (mediaType, ctx, path) => {
|
|
22
|
+
const { schema, examples,...rest } = mediaType;
|
|
23
|
+
const mediaTypeObject = rest;
|
|
24
|
+
if (isAnyZodType(schema)) {
|
|
25
|
+
const schemaObject = ctx.registry.addSchema(schema, [...path, "schema"], {
|
|
12
26
|
io: ctx.io,
|
|
13
27
|
source: { type: "mediaType" }
|
|
14
28
|
});
|
|
15
|
-
|
|
16
|
-
...mediaTypeObject,
|
|
17
|
-
schema: schemaObject
|
|
18
|
-
};
|
|
29
|
+
mediaTypeObject.schema = schemaObject;
|
|
19
30
|
}
|
|
31
|
+
if (examples) mediaTypeObject.examples = createExamples(examples, ctx.registry, [...path, "examples"]);
|
|
20
32
|
return mediaTypeObject;
|
|
21
33
|
};
|
|
22
34
|
const createContent = (content, ctx, path) => {
|
|
@@ -60,6 +72,18 @@ const createHeaders = (headers, registry$1, path) => {
|
|
|
60
72
|
return headers;
|
|
61
73
|
};
|
|
62
74
|
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/create/links.ts
|
|
77
|
+
const createLinks = (links, registry$1, path) => {
|
|
78
|
+
if (!links) return void 0;
|
|
79
|
+
const linksObject = {};
|
|
80
|
+
for (const [name, link] of Object.entries(links)) {
|
|
81
|
+
const linkObject = registry$1.addLink(link, [...path, name]);
|
|
82
|
+
linksObject[name] = linkObject;
|
|
83
|
+
}
|
|
84
|
+
return linksObject;
|
|
85
|
+
};
|
|
86
|
+
|
|
63
87
|
//#endregion
|
|
64
88
|
//#region src/create/parameters.ts
|
|
65
89
|
const createManualParameters = (parameters, registry$1, path) => {
|
|
@@ -183,7 +207,10 @@ const override = (ctx) => {
|
|
|
183
207
|
const mapping = {};
|
|
184
208
|
for (const [index, obj] of Object.entries(ctx.jsonSchema.oneOf)) {
|
|
185
209
|
const ref = obj.$ref;
|
|
186
|
-
if (!ref)
|
|
210
|
+
if (!ref) {
|
|
211
|
+
delete ctx.jsonSchema.discriminator;
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
187
214
|
const discriminatorValues = def.options[Number(index)]._zod.propValues?.[def.discriminator];
|
|
188
215
|
if (!discriminatorValues?.size) return;
|
|
189
216
|
for (const value of [...discriminatorValues ?? []]) {
|
|
@@ -447,6 +474,18 @@ const createRegistry = (components) => {
|
|
|
447
474
|
pathItems: {
|
|
448
475
|
ids: /* @__PURE__ */ new Map(),
|
|
449
476
|
seen: /* @__PURE__ */ new WeakMap()
|
|
477
|
+
},
|
|
478
|
+
securitySchemes: {
|
|
479
|
+
ids: /* @__PURE__ */ new Map(),
|
|
480
|
+
seen: /* @__PURE__ */ new WeakMap()
|
|
481
|
+
},
|
|
482
|
+
links: {
|
|
483
|
+
ids: /* @__PURE__ */ new Map(),
|
|
484
|
+
seen: /* @__PURE__ */ new WeakMap()
|
|
485
|
+
},
|
|
486
|
+
examples: {
|
|
487
|
+
ids: /* @__PURE__ */ new Map(),
|
|
488
|
+
seen: /* @__PURE__ */ new WeakMap()
|
|
450
489
|
}
|
|
451
490
|
},
|
|
452
491
|
addSchema: (schema, path, opts) => {
|
|
@@ -484,13 +523,20 @@ const createRegistry = (components) => {
|
|
|
484
523
|
}
|
|
485
524
|
}
|
|
486
525
|
});
|
|
487
|
-
const { id: metaId,...rest } = meta?.param ?? {};
|
|
526
|
+
const { id: metaId, examples,...rest } = meta?.param ?? {};
|
|
488
527
|
const parameterObject = {
|
|
489
|
-
...rest,
|
|
490
|
-
name,
|
|
491
528
|
in: inLocation,
|
|
492
|
-
|
|
529
|
+
name,
|
|
530
|
+
schema: schemaObject,
|
|
531
|
+
...rest
|
|
493
532
|
};
|
|
533
|
+
const examplesObject = createExamples(examples, registry$1, [
|
|
534
|
+
...path,
|
|
535
|
+
inLocation,
|
|
536
|
+
name,
|
|
537
|
+
"examples"
|
|
538
|
+
]);
|
|
539
|
+
if (examplesObject) parameterObject.examples = examplesObject;
|
|
494
540
|
if (isRequired(parameter, "input")) parameterObject.required = true;
|
|
495
541
|
if (!parameterObject.description && meta?.description) parameterObject.description = meta.description;
|
|
496
542
|
const id = metaId ?? opts?.manualId;
|
|
@@ -584,7 +630,7 @@ const createRegistry = (components) => {
|
|
|
584
630
|
addResponse: (response, path, opts) => {
|
|
585
631
|
const seenResponse = registry$1.components.responses.seen.get(response);
|
|
586
632
|
if (seenResponse) return seenResponse;
|
|
587
|
-
const { content, headers, id: metaId,...rest } = response;
|
|
633
|
+
const { content, headers, links, id: metaId,...rest } = response;
|
|
588
634
|
const responseObject = rest;
|
|
589
635
|
const maybeHeaders = createHeaders(headers, registry$1, [...path, "headers"]);
|
|
590
636
|
if (maybeHeaders) responseObject.headers = maybeHeaders;
|
|
@@ -592,6 +638,7 @@ const createRegistry = (components) => {
|
|
|
592
638
|
registry: registry$1,
|
|
593
639
|
io: "output"
|
|
594
640
|
}, [...path, "content"]);
|
|
641
|
+
if (links) responseObject.links = createLinks(links, registry$1, [...path, "links"]);
|
|
595
642
|
const id = metaId ?? opts?.manualId;
|
|
596
643
|
if (id) {
|
|
597
644
|
if (registry$1.components.responses.ids.has(id)) throw new Error(`Response "${id}" at ${path.join(" > ")} is already registered`);
|
|
@@ -625,6 +672,54 @@ const createRegistry = (components) => {
|
|
|
625
672
|
}
|
|
626
673
|
registry$1.components.callbacks.seen.set(callback, callbackObject);
|
|
627
674
|
return callbackObject;
|
|
675
|
+
},
|
|
676
|
+
addSecurityScheme: (securityScheme, path, opts) => {
|
|
677
|
+
const seenSecurityScheme = registry$1.components.securitySchemes.seen.get(securityScheme);
|
|
678
|
+
if (seenSecurityScheme) return seenSecurityScheme;
|
|
679
|
+
const { id: metaId,...rest } = securityScheme;
|
|
680
|
+
const securitySchemeObject = rest;
|
|
681
|
+
const id = metaId ?? opts?.manualId;
|
|
682
|
+
if (id) {
|
|
683
|
+
if (registry$1.components.securitySchemes.ids.has(id)) throw new Error(`SecurityScheme "${id}" at ${path.join(" > ")} is already registered`);
|
|
684
|
+
const ref = { $ref: `#/components/securitySchemes/${id}` };
|
|
685
|
+
registry$1.components.securitySchemes.ids.set(id, securitySchemeObject);
|
|
686
|
+
registry$1.components.securitySchemes.seen.set(securityScheme, ref);
|
|
687
|
+
return ref;
|
|
688
|
+
}
|
|
689
|
+
registry$1.components.securitySchemes.seen.set(securityScheme, securitySchemeObject);
|
|
690
|
+
return securitySchemeObject;
|
|
691
|
+
},
|
|
692
|
+
addLink: (link, path, opts) => {
|
|
693
|
+
const seenLink = registry$1.components.links.seen.get(link);
|
|
694
|
+
if (seenLink) return seenLink;
|
|
695
|
+
const { id: metaId,...rest } = link;
|
|
696
|
+
const linkObject = rest;
|
|
697
|
+
const id = metaId ?? opts?.manualId;
|
|
698
|
+
if (id) {
|
|
699
|
+
if (registry$1.components.links.ids.has(id)) throw new Error(`Link "${id}" at ${path.join(" > ")} is already registered`);
|
|
700
|
+
const ref = { $ref: `#/components/links/${id}` };
|
|
701
|
+
registry$1.components.links.ids.set(id, linkObject);
|
|
702
|
+
registry$1.components.links.seen.set(link, ref);
|
|
703
|
+
return ref;
|
|
704
|
+
}
|
|
705
|
+
registry$1.components.links.seen.set(link, linkObject);
|
|
706
|
+
return linkObject;
|
|
707
|
+
},
|
|
708
|
+
addExample: (example, path, opts) => {
|
|
709
|
+
const seenExample = registry$1.components.examples.seen.get(example);
|
|
710
|
+
if (seenExample) return seenExample;
|
|
711
|
+
const { id: metaId,...rest } = example;
|
|
712
|
+
const exampleObject = rest;
|
|
713
|
+
const id = metaId ?? opts?.manualId;
|
|
714
|
+
if (id) {
|
|
715
|
+
if (registry$1.components.examples.ids.has(id)) throw new Error(`Example "${id}" at ${path.join(" > ")} is already registered`);
|
|
716
|
+
const ref = { $ref: `#/components/examples/${id}` };
|
|
717
|
+
registry$1.components.examples.ids.set(id, exampleObject);
|
|
718
|
+
registry$1.components.examples.seen.set(example, ref);
|
|
719
|
+
return ref;
|
|
720
|
+
}
|
|
721
|
+
registry$1.components.examples.seen.set(example, exampleObject);
|
|
722
|
+
return exampleObject;
|
|
628
723
|
}
|
|
629
724
|
};
|
|
630
725
|
registerSchemas(components?.schemas, registry$1);
|
|
@@ -634,6 +729,9 @@ const createRegistry = (components) => {
|
|
|
634
729
|
registerPathItems(components?.pathItems, registry$1);
|
|
635
730
|
registerRequestBodies(components?.requestBodies, registry$1);
|
|
636
731
|
registerCallbacks(components?.callbacks, registry$1);
|
|
732
|
+
registerSecuritySchemes(components?.securitySchemes, registry$1);
|
|
733
|
+
registerLinks(components?.links, registry$1);
|
|
734
|
+
registerExamples(components?.examples, registry$1);
|
|
637
735
|
return registry$1;
|
|
638
736
|
};
|
|
639
737
|
const registerSchemas = (schemas, registry$1) => {
|
|
@@ -723,6 +821,26 @@ const registerPathItems = (pathItems, registry$1) => {
|
|
|
723
821
|
key
|
|
724
822
|
], { manualId: key });
|
|
725
823
|
};
|
|
824
|
+
const registerSecuritySchemes = (securitySchemes, registry$1) => {
|
|
825
|
+
if (!securitySchemes) return;
|
|
826
|
+
for (const [key, schema] of Object.entries(securitySchemes)) registry$1.addSecurityScheme(schema, [
|
|
827
|
+
"components",
|
|
828
|
+
"securitySchemes",
|
|
829
|
+
key
|
|
830
|
+
], { manualId: key });
|
|
831
|
+
};
|
|
832
|
+
const registerLinks = (links, registry$1) => {
|
|
833
|
+
if (!links) return;
|
|
834
|
+
for (const [key, schema] of Object.entries(links)) registry$1.addLink(schema, [
|
|
835
|
+
"components",
|
|
836
|
+
"links",
|
|
837
|
+
key
|
|
838
|
+
], { manualId: key });
|
|
839
|
+
};
|
|
840
|
+
const registerExamples = (examples, registry$1) => {
|
|
841
|
+
if (!examples) return;
|
|
842
|
+
for (const [key, schema] of Object.entries(examples)) registry$1.components.examples.ids.set(key, schema);
|
|
843
|
+
};
|
|
726
844
|
const createIOSchemas = (ctx) => {
|
|
727
845
|
const { schemas, components, manual } = createSchemas(Object.fromEntries(ctx.registry.components.schemas[ctx.io]), ctx);
|
|
728
846
|
for (const [key, schema] of Object.entries(components)) ctx.registry.components.schemas.ids.set(key, schema);
|
|
@@ -764,6 +882,9 @@ const createComponents = (registry$1, opts) => {
|
|
|
764
882
|
if (registry$1.components.parameters.ids.size > 0) components.parameters = Object.fromEntries(registry$1.components.parameters.ids);
|
|
765
883
|
if (registry$1.components.callbacks.ids.size > 0) components.callbacks = Object.fromEntries(registry$1.components.callbacks.ids);
|
|
766
884
|
if (registry$1.components.pathItems.ids.size > 0) components.pathItems = Object.fromEntries(registry$1.components.pathItems.ids);
|
|
885
|
+
if (registry$1.components.securitySchemes.ids.size > 0) components.securitySchemes = Object.fromEntries(registry$1.components.securitySchemes.ids);
|
|
886
|
+
if (registry$1.components.links.ids.size > 0) components.links = Object.fromEntries(registry$1.components.links.ids);
|
|
887
|
+
if (registry$1.components.examples.ids.size > 0) components.examples = Object.fromEntries(registry$1.components.examples.ids);
|
|
767
888
|
return components;
|
|
768
889
|
};
|
|
769
890
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseParameterObject, CallbackObject, CallbacksObject, ComponentRegistry, ComponentsObject, ContactObject, ContentObject, CreateDocumentOptions, DiscriminatorObject, EncodingObject, EncodingPropertyObject, ExampleObject, ExamplesObject, ExternalDocumentationObject, HeaderObject, HeadersObject, IExtensionName, IExtensionType, ISpecificationExtension, InfoObject, LicenseObject, LinkObject, LinkParametersObject, LinksObject, MediaTypeObject, OAuthFlowObject, OAuthFlowsObject, OpenAPIObject, OperationObject, Override, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiVersion, createDocument } from "./components-
|
|
1
|
+
import { BaseParameterObject, CallbackObject, CallbacksObject, ComponentRegistry, ComponentsObject, ContactObject, ContentObject, CreateDocumentOptions, DiscriminatorObject, EncodingObject, EncodingPropertyObject, ExampleObject, ExamplesObject, ExternalDocumentationObject, HeaderObject, HeadersObject, IExtensionName, IExtensionType, ISpecificationExtension, InfoObject, LicenseObject, LinkObject, LinkParametersObject, LinksObject, MediaTypeObject, OAuthFlowObject, OAuthFlowsObject, OpenAPIObject, OperationObject, Override, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiExampleObject, ZodOpenApiExamplesObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiLinkObject, ZodOpenApiLinksObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiSecuritySchemeObject, ZodOpenApiVersion, createDocument } from "./components-DkESnIB9.mjs";
|
|
2
2
|
import { core } from "zod/v4";
|
|
3
3
|
|
|
4
4
|
//#region rolldown:runtime
|
|
@@ -22,4 +22,4 @@ declare namespace oas31_d_exports {
|
|
|
22
22
|
export { BaseParameterObject, CallbackObject, CallbacksObject, ComponentsObject, ContactObject, ContentObject, DiscriminatorObject, EncodingObject, EncodingPropertyObject, ExampleObject, ExamplesObject, ExternalDocumentationObject, HeaderObject, HeadersObject, IExtensionName, IExtensionType, ISpecificationExtension, InfoObject, LicenseObject, LinkObject, LinkParametersObject, LinksObject, MediaTypeObject, OAuthFlowObject, OAuthFlowsObject, OpenAPIObject, OperationObject, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject };
|
|
23
23
|
}
|
|
24
24
|
//#endregion
|
|
25
|
-
export { CreateDocumentOptions, Override, SchemaResult, ZodObjectInput, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiVersion, createDocument, createSchema, oas31_d_exports as oas31 };
|
|
25
|
+
export { CreateDocumentOptions, Override, SchemaResult, ZodObjectInput, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiExampleObject, ZodOpenApiExamplesObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiLinkObject, ZodOpenApiLinksObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiSecuritySchemeObject, ZodOpenApiVersion, createDocument, createSchema, oas31_d_exports as oas31 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseParameterObject, CallbackObject, CallbacksObject, ComponentRegistry, ComponentsObject, ContactObject, ContentObject, CreateDocumentOptions, DiscriminatorObject, EncodingObject, EncodingPropertyObject, ExampleObject, ExamplesObject, ExternalDocumentationObject, HeaderObject, HeadersObject, IExtensionName, IExtensionType, ISpecificationExtension, InfoObject, LicenseObject, LinkObject, LinkParametersObject, LinksObject, MediaTypeObject, OAuthFlowObject, OAuthFlowsObject, OpenAPIObject, OperationObject, Override, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiVersion, createDocument } from "./components-
|
|
1
|
+
import { BaseParameterObject, CallbackObject, CallbacksObject, ComponentRegistry, ComponentsObject, ContactObject, ContentObject, CreateDocumentOptions, DiscriminatorObject, EncodingObject, EncodingPropertyObject, ExampleObject, ExamplesObject, ExternalDocumentationObject, HeaderObject, HeadersObject, IExtensionName, IExtensionType, ISpecificationExtension, InfoObject, LicenseObject, LinkObject, LinkParametersObject, LinksObject, MediaTypeObject, OAuthFlowObject, OAuthFlowsObject, OpenAPIObject, OperationObject, Override, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiExampleObject, ZodOpenApiExamplesObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiLinkObject, ZodOpenApiLinksObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiSecuritySchemeObject, ZodOpenApiVersion, createDocument } from "./components-BLmIpmmY.js";
|
|
2
2
|
import { core } from "zod/v4";
|
|
3
3
|
|
|
4
4
|
//#region rolldown:runtime
|
|
@@ -22,4 +22,4 @@ declare namespace oas31_d_exports {
|
|
|
22
22
|
export { BaseParameterObject, CallbackObject, CallbacksObject, ComponentsObject, ContactObject, ContentObject, DiscriminatorObject, EncodingObject, EncodingPropertyObject, ExampleObject, ExamplesObject, ExternalDocumentationObject, HeaderObject, HeadersObject, IExtensionName, IExtensionType, ISpecificationExtension, InfoObject, LicenseObject, LinkObject, LinkParametersObject, LinksObject, MediaTypeObject, OAuthFlowObject, OAuthFlowsObject, OpenAPIObject, OperationObject, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject };
|
|
23
23
|
}
|
|
24
24
|
//#endregion
|
|
25
|
-
export { CreateDocumentOptions, Override, SchemaResult, ZodObjectInput, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiVersion, createDocument, createSchema, oas31_d_exports as oas31 };
|
|
25
|
+
export { CreateDocumentOptions, Override, SchemaResult, ZodObjectInput, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiExampleObject, ZodOpenApiExamplesObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiLinkObject, ZodOpenApiLinksObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiSecuritySchemeObject, ZodOpenApiVersion, createDocument, createSchema, oas31_d_exports as oas31 };
|
package/dist/index.js
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createComponents, createPaths, createRegistry, createSchema } from "./components-
|
|
1
|
+
import { createComponents, createPaths, createRegistry, createSchema } from "./components-n2uYApmq.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/create/document.ts
|
|
4
4
|
const createDocument = (zodOpenApiObject, opts = {}) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod-openapi",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.19",
|
|
4
4
|
"description": "Convert Zod Schemas to OpenAPI v3.x documentation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"@arethetypeswrong/cli": "0.18.1",
|
|
55
55
|
"@redocly/cli": "1.34.3",
|
|
56
56
|
"@types/node": "22.15.21",
|
|
57
|
+
"eslint-plugin-import-zod": "1.0.3",
|
|
57
58
|
"eslint-plugin-zod-openapi": "2.0.0-beta.1",
|
|
58
59
|
"openapi3-ts": "4.5.0",
|
|
59
60
|
"skuba": "11.0.1",
|