zod-openapi 5.0.0-beta.16 → 5.0.0-beta.18
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 +119 -3
- 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-D-fOeav1.js → components-BqmhtKMD.js} +132 -12
- package/dist/{components-Cy7_OKKg.mjs → components-Cblv9pY1.mjs} +132 -12
- package/dist/{components-uNe8arnt.d.mts → components-DkESnIB9.d.mts} +44 -3
- 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 +1 -1
package/README.md
CHANGED
|
@@ -263,7 +263,7 @@ const { schema, components } = createSchema(job);
|
|
|
263
263
|
|
|
264
264
|
`createSchema` takes an optional `CreateSchemaOptions` parameter which includes all options from [CreateDocumentOptions](#createdocumentoptions) plus the following:
|
|
265
265
|
|
|
266
|
-
|
|
266
|
+
```typescript
|
|
267
267
|
const { schema, components } = createSchema(job, {
|
|
268
268
|
// Input/Output context - controls how schemas are generated
|
|
269
269
|
io: 'input', // 'input' for request bodies/params, 'output' for responses
|
|
@@ -272,6 +272,7 @@ const { schema, components } = createSchema(job, {
|
|
|
272
272
|
schemaComponents: { jobId: z.string() }, // Pre-defined components to use
|
|
273
273
|
schemaComponentRefPath: '#/definitions/', // Custom path prefix for component references
|
|
274
274
|
});
|
|
275
|
+
```
|
|
275
276
|
|
|
276
277
|
### Request Parameters
|
|
277
278
|
|
|
@@ -292,7 +293,7 @@ createDocument({
|
|
|
292
293
|
},
|
|
293
294
|
},
|
|
294
295
|
});
|
|
295
|
-
|
|
296
|
+
```
|
|
296
297
|
|
|
297
298
|
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
299
|
|
|
@@ -632,6 +633,121 @@ createDocument({
|
|
|
632
633
|
});
|
|
633
634
|
```
|
|
634
635
|
|
|
636
|
+
#### Path Items
|
|
637
|
+
|
|
638
|
+
Path Items can also be registered
|
|
639
|
+
|
|
640
|
+
```typescript
|
|
641
|
+
const pathItem: ZodOpenApiPathItemObject = {
|
|
642
|
+
id: 'some-path-item',
|
|
643
|
+
get: {
|
|
644
|
+
responses: {
|
|
645
|
+
200: {
|
|
646
|
+
description: '200 OK',
|
|
647
|
+
content: {
|
|
648
|
+
'application/json': {
|
|
649
|
+
schema: z.object({ a: z.string() }),
|
|
650
|
+
},
|
|
651
|
+
},
|
|
652
|
+
},
|
|
653
|
+
},
|
|
654
|
+
},
|
|
655
|
+
};
|
|
656
|
+
|
|
657
|
+
// or
|
|
658
|
+
|
|
659
|
+
createDocument({
|
|
660
|
+
components: {
|
|
661
|
+
pathItems: {
|
|
662
|
+
'some-path-item': pathItem,
|
|
663
|
+
},
|
|
664
|
+
},
|
|
665
|
+
});
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
#### Security Schemes
|
|
669
|
+
|
|
670
|
+
Security Schemes can be registered for authentication methods:
|
|
671
|
+
|
|
672
|
+
```typescript
|
|
673
|
+
createDocument({
|
|
674
|
+
components: {
|
|
675
|
+
securitySchemes: {
|
|
676
|
+
bearerAuth: {
|
|
677
|
+
type: 'http',
|
|
678
|
+
scheme: 'bearer',
|
|
679
|
+
bearerFormat: 'JWT',
|
|
680
|
+
description: 'JWT Authentication',
|
|
681
|
+
},
|
|
682
|
+
},
|
|
683
|
+
},
|
|
684
|
+
});
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
#### Links
|
|
688
|
+
|
|
689
|
+
Links can be registered to describe relationships between operations:
|
|
690
|
+
|
|
691
|
+
```typescript
|
|
692
|
+
const link: ZodOpenApiLinkObject = {
|
|
693
|
+
id: 'getUserById',
|
|
694
|
+
operationId: 'getUser',
|
|
695
|
+
parameters: {
|
|
696
|
+
userId: '$request.path.id',
|
|
697
|
+
},
|
|
698
|
+
description: 'Link to get user by id',
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
// or
|
|
702
|
+
|
|
703
|
+
createDocument({
|
|
704
|
+
components: {
|
|
705
|
+
links: {
|
|
706
|
+
getUserById: {
|
|
707
|
+
operationId: 'getUser',
|
|
708
|
+
parameters: {
|
|
709
|
+
userId: '$request.path.id',
|
|
710
|
+
},
|
|
711
|
+
description: 'Link to get user by id',
|
|
712
|
+
},
|
|
713
|
+
},
|
|
714
|
+
},
|
|
715
|
+
});
|
|
716
|
+
```
|
|
717
|
+
|
|
718
|
+
#### Examples
|
|
719
|
+
|
|
720
|
+
Examples can be registered to provide sample values for schemas:
|
|
721
|
+
|
|
722
|
+
```typescript
|
|
723
|
+
const example: ZodOpenApiExampleObject = {
|
|
724
|
+
id: 'userExample',
|
|
725
|
+
summary: 'A sample user',
|
|
726
|
+
value: {
|
|
727
|
+
id: '123',
|
|
728
|
+
name: 'Jane Doe',
|
|
729
|
+
email: 'jane@example.com',
|
|
730
|
+
},
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
// or
|
|
734
|
+
|
|
735
|
+
createDocument({
|
|
736
|
+
components: {
|
|
737
|
+
examples: {
|
|
738
|
+
userExample: {
|
|
739
|
+
summary: 'A sample user',
|
|
740
|
+
value: {
|
|
741
|
+
id: '123',
|
|
742
|
+
name: 'Jane Doe',
|
|
743
|
+
email: 'jane@example.com',
|
|
744
|
+
},
|
|
745
|
+
},
|
|
746
|
+
},
|
|
747
|
+
},
|
|
748
|
+
});
|
|
749
|
+
```
|
|
750
|
+
|
|
635
751
|
### Zod Types
|
|
636
752
|
|
|
637
753
|
Zod types are composed of two different parts: the input and the output. This library decides which type to create based on if it is used in a request or response context.
|
|
@@ -648,7 +764,7 @@ Output:
|
|
|
648
764
|
|
|
649
765
|
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()`.
|
|
650
766
|
|
|
651
|
-
```
|
|
767
|
+
```typescript
|
|
652
768
|
const schema = z.object({
|
|
653
769
|
name: z.string(),
|
|
654
770
|
});
|
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-Cblv9pY1.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) => {
|
|
@@ -470,6 +494,18 @@ const createRegistry = (components) => {
|
|
|
470
494
|
pathItems: {
|
|
471
495
|
ids: /* @__PURE__ */ new Map(),
|
|
472
496
|
seen: /* @__PURE__ */ new WeakMap()
|
|
497
|
+
},
|
|
498
|
+
securitySchemes: {
|
|
499
|
+
ids: /* @__PURE__ */ new Map(),
|
|
500
|
+
seen: /* @__PURE__ */ new WeakMap()
|
|
501
|
+
},
|
|
502
|
+
links: {
|
|
503
|
+
ids: /* @__PURE__ */ new Map(),
|
|
504
|
+
seen: /* @__PURE__ */ new WeakMap()
|
|
505
|
+
},
|
|
506
|
+
examples: {
|
|
507
|
+
ids: /* @__PURE__ */ new Map(),
|
|
508
|
+
seen: /* @__PURE__ */ new WeakMap()
|
|
473
509
|
}
|
|
474
510
|
},
|
|
475
511
|
addSchema: (schema, path, opts) => {
|
|
@@ -490,6 +526,7 @@ const createRegistry = (components) => {
|
|
|
490
526
|
const meta = zod_v4_core.globalRegistry.get(parameter);
|
|
491
527
|
const name = opts?.location?.name ?? meta?.param?.name;
|
|
492
528
|
const inLocation = opts?.location?.in ?? meta?.param?.in;
|
|
529
|
+
if (opts?.location?.name && meta?.param?.name || opts?.location?.in && meta?.param?.in) throw new Error(`Parameter at ${path.join(" > ")} has both \`.meta({ param: { name, in } })\` and \`.meta({ param: { location: { in, name } } })\` information`);
|
|
493
530
|
if (!name || !inLocation) throw new Error(`Parameter at ${path.join(" > ")} is missing \`.meta({ param: { name, in } })\` information`);
|
|
494
531
|
const schemaObject = registry$1.addSchema(parameter, [
|
|
495
532
|
...path,
|
|
@@ -506,13 +543,20 @@ const createRegistry = (components) => {
|
|
|
506
543
|
}
|
|
507
544
|
}
|
|
508
545
|
});
|
|
509
|
-
const { id: metaId,...rest } = meta?.param ?? {};
|
|
546
|
+
const { id: metaId, examples,...rest } = meta?.param ?? {};
|
|
510
547
|
const parameterObject = {
|
|
511
|
-
...rest,
|
|
512
|
-
name,
|
|
513
548
|
in: inLocation,
|
|
514
|
-
|
|
549
|
+
name,
|
|
550
|
+
schema: schemaObject,
|
|
551
|
+
...rest
|
|
515
552
|
};
|
|
553
|
+
const examplesObject = createExamples(examples, registry$1, [
|
|
554
|
+
...path,
|
|
555
|
+
inLocation,
|
|
556
|
+
name,
|
|
557
|
+
"examples"
|
|
558
|
+
]);
|
|
559
|
+
if (examplesObject) parameterObject.examples = examplesObject;
|
|
516
560
|
if (isRequired(parameter, "input")) parameterObject.required = true;
|
|
517
561
|
if (!parameterObject.description && meta?.description) parameterObject.description = meta.description;
|
|
518
562
|
const id = metaId ?? opts?.manualId;
|
|
@@ -523,6 +567,7 @@ const createRegistry = (components) => {
|
|
|
523
567
|
registry$1.components.parameters.ids.set(id, parameterObject);
|
|
524
568
|
return ref;
|
|
525
569
|
}
|
|
570
|
+
if (opts?.location?.name || opts?.location?.in) return parameterObject;
|
|
526
571
|
registry$1.components.parameters.seen.set(parameter, parameterObject);
|
|
527
572
|
return parameterObject;
|
|
528
573
|
},
|
|
@@ -605,7 +650,7 @@ const createRegistry = (components) => {
|
|
|
605
650
|
addResponse: (response, path, opts) => {
|
|
606
651
|
const seenResponse = registry$1.components.responses.seen.get(response);
|
|
607
652
|
if (seenResponse) return seenResponse;
|
|
608
|
-
const { content, headers, id: metaId,...rest } = response;
|
|
653
|
+
const { content, headers, links, id: metaId,...rest } = response;
|
|
609
654
|
const responseObject = rest;
|
|
610
655
|
const maybeHeaders = createHeaders(headers, registry$1, [...path, "headers"]);
|
|
611
656
|
if (maybeHeaders) responseObject.headers = maybeHeaders;
|
|
@@ -613,6 +658,7 @@ const createRegistry = (components) => {
|
|
|
613
658
|
registry: registry$1,
|
|
614
659
|
io: "output"
|
|
615
660
|
}, [...path, "content"]);
|
|
661
|
+
if (links) responseObject.links = createLinks(links, registry$1, [...path, "links"]);
|
|
616
662
|
const id = metaId ?? opts?.manualId;
|
|
617
663
|
if (id) {
|
|
618
664
|
if (registry$1.components.responses.ids.has(id)) throw new Error(`Response "${id}" at ${path.join(" > ")} is already registered`);
|
|
@@ -646,6 +692,54 @@ const createRegistry = (components) => {
|
|
|
646
692
|
}
|
|
647
693
|
registry$1.components.callbacks.seen.set(callback, callbackObject);
|
|
648
694
|
return callbackObject;
|
|
695
|
+
},
|
|
696
|
+
addSecurityScheme: (securityScheme, path, opts) => {
|
|
697
|
+
const seenSecurityScheme = registry$1.components.securitySchemes.seen.get(securityScheme);
|
|
698
|
+
if (seenSecurityScheme) return seenSecurityScheme;
|
|
699
|
+
const { id: metaId,...rest } = securityScheme;
|
|
700
|
+
const securitySchemeObject = rest;
|
|
701
|
+
const id = metaId ?? opts?.manualId;
|
|
702
|
+
if (id) {
|
|
703
|
+
if (registry$1.components.securitySchemes.ids.has(id)) throw new Error(`SecurityScheme "${id}" at ${path.join(" > ")} is already registered`);
|
|
704
|
+
const ref = { $ref: `#/components/securitySchemes/${id}` };
|
|
705
|
+
registry$1.components.securitySchemes.ids.set(id, securitySchemeObject);
|
|
706
|
+
registry$1.components.securitySchemes.seen.set(securityScheme, ref);
|
|
707
|
+
return ref;
|
|
708
|
+
}
|
|
709
|
+
registry$1.components.securitySchemes.seen.set(securityScheme, securitySchemeObject);
|
|
710
|
+
return securitySchemeObject;
|
|
711
|
+
},
|
|
712
|
+
addLink: (link, path, opts) => {
|
|
713
|
+
const seenLink = registry$1.components.links.seen.get(link);
|
|
714
|
+
if (seenLink) return seenLink;
|
|
715
|
+
const { id: metaId,...rest } = link;
|
|
716
|
+
const linkObject = rest;
|
|
717
|
+
const id = metaId ?? opts?.manualId;
|
|
718
|
+
if (id) {
|
|
719
|
+
if (registry$1.components.links.ids.has(id)) throw new Error(`Link "${id}" at ${path.join(" > ")} is already registered`);
|
|
720
|
+
const ref = { $ref: `#/components/links/${id}` };
|
|
721
|
+
registry$1.components.links.ids.set(id, linkObject);
|
|
722
|
+
registry$1.components.links.seen.set(link, ref);
|
|
723
|
+
return ref;
|
|
724
|
+
}
|
|
725
|
+
registry$1.components.links.seen.set(link, linkObject);
|
|
726
|
+
return linkObject;
|
|
727
|
+
},
|
|
728
|
+
addExample: (example, path, opts) => {
|
|
729
|
+
const seenExample = registry$1.components.examples.seen.get(example);
|
|
730
|
+
if (seenExample) return seenExample;
|
|
731
|
+
const { id: metaId,...rest } = example;
|
|
732
|
+
const exampleObject = rest;
|
|
733
|
+
const id = metaId ?? opts?.manualId;
|
|
734
|
+
if (id) {
|
|
735
|
+
if (registry$1.components.examples.ids.has(id)) throw new Error(`Example "${id}" at ${path.join(" > ")} is already registered`);
|
|
736
|
+
const ref = { $ref: `#/components/examples/${id}` };
|
|
737
|
+
registry$1.components.examples.ids.set(id, exampleObject);
|
|
738
|
+
registry$1.components.examples.seen.set(example, ref);
|
|
739
|
+
return ref;
|
|
740
|
+
}
|
|
741
|
+
registry$1.components.examples.seen.set(example, exampleObject);
|
|
742
|
+
return exampleObject;
|
|
649
743
|
}
|
|
650
744
|
};
|
|
651
745
|
registerSchemas(components?.schemas, registry$1);
|
|
@@ -655,6 +749,9 @@ const createRegistry = (components) => {
|
|
|
655
749
|
registerPathItems(components?.pathItems, registry$1);
|
|
656
750
|
registerRequestBodies(components?.requestBodies, registry$1);
|
|
657
751
|
registerCallbacks(components?.callbacks, registry$1);
|
|
752
|
+
registerSecuritySchemes(components?.securitySchemes, registry$1);
|
|
753
|
+
registerLinks(components?.links, registry$1);
|
|
754
|
+
registerExamples(components?.examples, registry$1);
|
|
658
755
|
return registry$1;
|
|
659
756
|
};
|
|
660
757
|
const registerSchemas = (schemas, registry$1) => {
|
|
@@ -744,6 +841,26 @@ const registerPathItems = (pathItems, registry$1) => {
|
|
|
744
841
|
key
|
|
745
842
|
], { manualId: key });
|
|
746
843
|
};
|
|
844
|
+
const registerSecuritySchemes = (securitySchemes, registry$1) => {
|
|
845
|
+
if (!securitySchemes) return;
|
|
846
|
+
for (const [key, schema] of Object.entries(securitySchemes)) registry$1.addSecurityScheme(schema, [
|
|
847
|
+
"components",
|
|
848
|
+
"securitySchemes",
|
|
849
|
+
key
|
|
850
|
+
], { manualId: key });
|
|
851
|
+
};
|
|
852
|
+
const registerLinks = (links, registry$1) => {
|
|
853
|
+
if (!links) return;
|
|
854
|
+
for (const [key, schema] of Object.entries(links)) registry$1.addLink(schema, [
|
|
855
|
+
"components",
|
|
856
|
+
"links",
|
|
857
|
+
key
|
|
858
|
+
], { manualId: key });
|
|
859
|
+
};
|
|
860
|
+
const registerExamples = (examples, registry$1) => {
|
|
861
|
+
if (!examples) return;
|
|
862
|
+
for (const [key, schema] of Object.entries(examples)) registry$1.components.examples.ids.set(key, schema);
|
|
863
|
+
};
|
|
747
864
|
const createIOSchemas = (ctx) => {
|
|
748
865
|
const { schemas, components, manual } = createSchemas(Object.fromEntries(ctx.registry.components.schemas[ctx.io]), ctx);
|
|
749
866
|
for (const [key, schema] of Object.entries(components)) ctx.registry.components.schemas.ids.set(key, schema);
|
|
@@ -785,6 +902,9 @@ const createComponents = (registry$1, opts) => {
|
|
|
785
902
|
if (registry$1.components.parameters.ids.size > 0) components.parameters = Object.fromEntries(registry$1.components.parameters.ids);
|
|
786
903
|
if (registry$1.components.callbacks.ids.size > 0) components.callbacks = Object.fromEntries(registry$1.components.callbacks.ids);
|
|
787
904
|
if (registry$1.components.pathItems.ids.size > 0) components.pathItems = Object.fromEntries(registry$1.components.pathItems.ids);
|
|
905
|
+
if (registry$1.components.securitySchemes.ids.size > 0) components.securitySchemes = Object.fromEntries(registry$1.components.securitySchemes.ids);
|
|
906
|
+
if (registry$1.components.links.ids.size > 0) components.links = Object.fromEntries(registry$1.components.links.ids);
|
|
907
|
+
if (registry$1.components.examples.ids.size > 0) components.examples = Object.fromEntries(registry$1.components.examples.ids);
|
|
788
908
|
return components;
|
|
789
909
|
};
|
|
790
910
|
|
|
@@ -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) => {
|
|
@@ -447,6 +471,18 @@ const createRegistry = (components) => {
|
|
|
447
471
|
pathItems: {
|
|
448
472
|
ids: /* @__PURE__ */ new Map(),
|
|
449
473
|
seen: /* @__PURE__ */ new WeakMap()
|
|
474
|
+
},
|
|
475
|
+
securitySchemes: {
|
|
476
|
+
ids: /* @__PURE__ */ new Map(),
|
|
477
|
+
seen: /* @__PURE__ */ new WeakMap()
|
|
478
|
+
},
|
|
479
|
+
links: {
|
|
480
|
+
ids: /* @__PURE__ */ new Map(),
|
|
481
|
+
seen: /* @__PURE__ */ new WeakMap()
|
|
482
|
+
},
|
|
483
|
+
examples: {
|
|
484
|
+
ids: /* @__PURE__ */ new Map(),
|
|
485
|
+
seen: /* @__PURE__ */ new WeakMap()
|
|
450
486
|
}
|
|
451
487
|
},
|
|
452
488
|
addSchema: (schema, path, opts) => {
|
|
@@ -467,6 +503,7 @@ const createRegistry = (components) => {
|
|
|
467
503
|
const meta = globalRegistry.get(parameter);
|
|
468
504
|
const name = opts?.location?.name ?? meta?.param?.name;
|
|
469
505
|
const inLocation = opts?.location?.in ?? meta?.param?.in;
|
|
506
|
+
if (opts?.location?.name && meta?.param?.name || opts?.location?.in && meta?.param?.in) throw new Error(`Parameter at ${path.join(" > ")} has both \`.meta({ param: { name, in } })\` and \`.meta({ param: { location: { in, name } } })\` information`);
|
|
470
507
|
if (!name || !inLocation) throw new Error(`Parameter at ${path.join(" > ")} is missing \`.meta({ param: { name, in } })\` information`);
|
|
471
508
|
const schemaObject = registry$1.addSchema(parameter, [
|
|
472
509
|
...path,
|
|
@@ -483,13 +520,20 @@ const createRegistry = (components) => {
|
|
|
483
520
|
}
|
|
484
521
|
}
|
|
485
522
|
});
|
|
486
|
-
const { id: metaId,...rest } = meta?.param ?? {};
|
|
523
|
+
const { id: metaId, examples,...rest } = meta?.param ?? {};
|
|
487
524
|
const parameterObject = {
|
|
488
|
-
...rest,
|
|
489
|
-
name,
|
|
490
525
|
in: inLocation,
|
|
491
|
-
|
|
526
|
+
name,
|
|
527
|
+
schema: schemaObject,
|
|
528
|
+
...rest
|
|
492
529
|
};
|
|
530
|
+
const examplesObject = createExamples(examples, registry$1, [
|
|
531
|
+
...path,
|
|
532
|
+
inLocation,
|
|
533
|
+
name,
|
|
534
|
+
"examples"
|
|
535
|
+
]);
|
|
536
|
+
if (examplesObject) parameterObject.examples = examplesObject;
|
|
493
537
|
if (isRequired(parameter, "input")) parameterObject.required = true;
|
|
494
538
|
if (!parameterObject.description && meta?.description) parameterObject.description = meta.description;
|
|
495
539
|
const id = metaId ?? opts?.manualId;
|
|
@@ -500,6 +544,7 @@ const createRegistry = (components) => {
|
|
|
500
544
|
registry$1.components.parameters.ids.set(id, parameterObject);
|
|
501
545
|
return ref;
|
|
502
546
|
}
|
|
547
|
+
if (opts?.location?.name || opts?.location?.in) return parameterObject;
|
|
503
548
|
registry$1.components.parameters.seen.set(parameter, parameterObject);
|
|
504
549
|
return parameterObject;
|
|
505
550
|
},
|
|
@@ -582,7 +627,7 @@ const createRegistry = (components) => {
|
|
|
582
627
|
addResponse: (response, path, opts) => {
|
|
583
628
|
const seenResponse = registry$1.components.responses.seen.get(response);
|
|
584
629
|
if (seenResponse) return seenResponse;
|
|
585
|
-
const { content, headers, id: metaId,...rest } = response;
|
|
630
|
+
const { content, headers, links, id: metaId,...rest } = response;
|
|
586
631
|
const responseObject = rest;
|
|
587
632
|
const maybeHeaders = createHeaders(headers, registry$1, [...path, "headers"]);
|
|
588
633
|
if (maybeHeaders) responseObject.headers = maybeHeaders;
|
|
@@ -590,6 +635,7 @@ const createRegistry = (components) => {
|
|
|
590
635
|
registry: registry$1,
|
|
591
636
|
io: "output"
|
|
592
637
|
}, [...path, "content"]);
|
|
638
|
+
if (links) responseObject.links = createLinks(links, registry$1, [...path, "links"]);
|
|
593
639
|
const id = metaId ?? opts?.manualId;
|
|
594
640
|
if (id) {
|
|
595
641
|
if (registry$1.components.responses.ids.has(id)) throw new Error(`Response "${id}" at ${path.join(" > ")} is already registered`);
|
|
@@ -623,6 +669,54 @@ const createRegistry = (components) => {
|
|
|
623
669
|
}
|
|
624
670
|
registry$1.components.callbacks.seen.set(callback, callbackObject);
|
|
625
671
|
return callbackObject;
|
|
672
|
+
},
|
|
673
|
+
addSecurityScheme: (securityScheme, path, opts) => {
|
|
674
|
+
const seenSecurityScheme = registry$1.components.securitySchemes.seen.get(securityScheme);
|
|
675
|
+
if (seenSecurityScheme) return seenSecurityScheme;
|
|
676
|
+
const { id: metaId,...rest } = securityScheme;
|
|
677
|
+
const securitySchemeObject = rest;
|
|
678
|
+
const id = metaId ?? opts?.manualId;
|
|
679
|
+
if (id) {
|
|
680
|
+
if (registry$1.components.securitySchemes.ids.has(id)) throw new Error(`SecurityScheme "${id}" at ${path.join(" > ")} is already registered`);
|
|
681
|
+
const ref = { $ref: `#/components/securitySchemes/${id}` };
|
|
682
|
+
registry$1.components.securitySchemes.ids.set(id, securitySchemeObject);
|
|
683
|
+
registry$1.components.securitySchemes.seen.set(securityScheme, ref);
|
|
684
|
+
return ref;
|
|
685
|
+
}
|
|
686
|
+
registry$1.components.securitySchemes.seen.set(securityScheme, securitySchemeObject);
|
|
687
|
+
return securitySchemeObject;
|
|
688
|
+
},
|
|
689
|
+
addLink: (link, path, opts) => {
|
|
690
|
+
const seenLink = registry$1.components.links.seen.get(link);
|
|
691
|
+
if (seenLink) return seenLink;
|
|
692
|
+
const { id: metaId,...rest } = link;
|
|
693
|
+
const linkObject = rest;
|
|
694
|
+
const id = metaId ?? opts?.manualId;
|
|
695
|
+
if (id) {
|
|
696
|
+
if (registry$1.components.links.ids.has(id)) throw new Error(`Link "${id}" at ${path.join(" > ")} is already registered`);
|
|
697
|
+
const ref = { $ref: `#/components/links/${id}` };
|
|
698
|
+
registry$1.components.links.ids.set(id, linkObject);
|
|
699
|
+
registry$1.components.links.seen.set(link, ref);
|
|
700
|
+
return ref;
|
|
701
|
+
}
|
|
702
|
+
registry$1.components.links.seen.set(link, linkObject);
|
|
703
|
+
return linkObject;
|
|
704
|
+
},
|
|
705
|
+
addExample: (example, path, opts) => {
|
|
706
|
+
const seenExample = registry$1.components.examples.seen.get(example);
|
|
707
|
+
if (seenExample) return seenExample;
|
|
708
|
+
const { id: metaId,...rest } = example;
|
|
709
|
+
const exampleObject = rest;
|
|
710
|
+
const id = metaId ?? opts?.manualId;
|
|
711
|
+
if (id) {
|
|
712
|
+
if (registry$1.components.examples.ids.has(id)) throw new Error(`Example "${id}" at ${path.join(" > ")} is already registered`);
|
|
713
|
+
const ref = { $ref: `#/components/examples/${id}` };
|
|
714
|
+
registry$1.components.examples.ids.set(id, exampleObject);
|
|
715
|
+
registry$1.components.examples.seen.set(example, ref);
|
|
716
|
+
return ref;
|
|
717
|
+
}
|
|
718
|
+
registry$1.components.examples.seen.set(example, exampleObject);
|
|
719
|
+
return exampleObject;
|
|
626
720
|
}
|
|
627
721
|
};
|
|
628
722
|
registerSchemas(components?.schemas, registry$1);
|
|
@@ -632,6 +726,9 @@ const createRegistry = (components) => {
|
|
|
632
726
|
registerPathItems(components?.pathItems, registry$1);
|
|
633
727
|
registerRequestBodies(components?.requestBodies, registry$1);
|
|
634
728
|
registerCallbacks(components?.callbacks, registry$1);
|
|
729
|
+
registerSecuritySchemes(components?.securitySchemes, registry$1);
|
|
730
|
+
registerLinks(components?.links, registry$1);
|
|
731
|
+
registerExamples(components?.examples, registry$1);
|
|
635
732
|
return registry$1;
|
|
636
733
|
};
|
|
637
734
|
const registerSchemas = (schemas, registry$1) => {
|
|
@@ -721,6 +818,26 @@ const registerPathItems = (pathItems, registry$1) => {
|
|
|
721
818
|
key
|
|
722
819
|
], { manualId: key });
|
|
723
820
|
};
|
|
821
|
+
const registerSecuritySchemes = (securitySchemes, registry$1) => {
|
|
822
|
+
if (!securitySchemes) return;
|
|
823
|
+
for (const [key, schema] of Object.entries(securitySchemes)) registry$1.addSecurityScheme(schema, [
|
|
824
|
+
"components",
|
|
825
|
+
"securitySchemes",
|
|
826
|
+
key
|
|
827
|
+
], { manualId: key });
|
|
828
|
+
};
|
|
829
|
+
const registerLinks = (links, registry$1) => {
|
|
830
|
+
if (!links) return;
|
|
831
|
+
for (const [key, schema] of Object.entries(links)) registry$1.addLink(schema, [
|
|
832
|
+
"components",
|
|
833
|
+
"links",
|
|
834
|
+
key
|
|
835
|
+
], { manualId: key });
|
|
836
|
+
};
|
|
837
|
+
const registerExamples = (examples, registry$1) => {
|
|
838
|
+
if (!examples) return;
|
|
839
|
+
for (const [key, schema] of Object.entries(examples)) registry$1.components.examples.ids.set(key, schema);
|
|
840
|
+
};
|
|
724
841
|
const createIOSchemas = (ctx) => {
|
|
725
842
|
const { schemas, components, manual } = createSchemas(Object.fromEntries(ctx.registry.components.schemas[ctx.io]), ctx);
|
|
726
843
|
for (const [key, schema] of Object.entries(components)) ctx.registry.components.schemas.ids.set(key, schema);
|
|
@@ -762,6 +879,9 @@ const createComponents = (registry$1, opts) => {
|
|
|
762
879
|
if (registry$1.components.parameters.ids.size > 0) components.parameters = Object.fromEntries(registry$1.components.parameters.ids);
|
|
763
880
|
if (registry$1.components.callbacks.ids.size > 0) components.callbacks = Object.fromEntries(registry$1.components.callbacks.ids);
|
|
764
881
|
if (registry$1.components.pathItems.ids.size > 0) components.pathItems = Object.fromEntries(registry$1.components.pathItems.ids);
|
|
882
|
+
if (registry$1.components.securitySchemes.ids.size > 0) components.securitySchemes = Object.fromEntries(registry$1.components.securitySchemes.ids);
|
|
883
|
+
if (registry$1.components.links.ids.size > 0) components.links = Object.fromEntries(registry$1.components.links.ids);
|
|
884
|
+
if (registry$1.components.examples.ids.size > 0) components.examples = Object.fromEntries(registry$1.components.examples.ids);
|
|
765
885
|
return components;
|
|
766
886
|
};
|
|
767
887
|
|
|
@@ -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 };
|
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-Cblv9pY1.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/create/document.ts
|
|
4
4
|
const createDocument = (zodOpenApiObject, opts = {}) => {
|