zod-openapi 5.0.0-beta.16 → 5.0.0-beta.17
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 +35 -1
- package/dist/api.js +1 -1
- package/dist/api.mjs +1 -1
- package/dist/{components-Cy7_OKKg.mjs → components-CncTLZvX.mjs} +2 -0
- package/dist/{components-D-fOeav1.js → components-D4JjPRqN.js} +2 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -632,6 +632,40 @@ createDocument({
|
|
|
632
632
|
});
|
|
633
633
|
```
|
|
634
634
|
|
|
635
|
+
#### Path Items
|
|
636
|
+
|
|
637
|
+
Path Items can also be registered
|
|
638
|
+
|
|
639
|
+
````typescript
|
|
640
|
+
const pathItem: ZodOpenApiPathItemObject = {
|
|
641
|
+
id: 'some-path-item',
|
|
642
|
+
get: {
|
|
643
|
+
responses: {
|
|
644
|
+
200: {
|
|
645
|
+
description: '200 OK',
|
|
646
|
+
content: {
|
|
647
|
+
'application/json': {
|
|
648
|
+
schema: z.object({ a: z.string() }),
|
|
649
|
+
},
|
|
650
|
+
},
|
|
651
|
+
},
|
|
652
|
+
},
|
|
653
|
+
},
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
// or
|
|
657
|
+
|
|
658
|
+
createDocument({
|
|
659
|
+
components: {
|
|
660
|
+
pathItems: {
|
|
661
|
+
'some-path-item': pathItem,
|
|
662
|
+
},
|
|
663
|
+
},
|
|
664
|
+
});
|
|
665
|
+
```
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
|
|
635
669
|
### Zod Types
|
|
636
670
|
|
|
637
671
|
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.
|
|
@@ -652,7 +686,7 @@ In general, you want to avoid using a registered input schema in an output conte
|
|
|
652
686
|
const schema = z.object({
|
|
653
687
|
name: z.string(),
|
|
654
688
|
});
|
|
655
|
-
|
|
689
|
+
````
|
|
656
690
|
|
|
657
691
|
Input schemas (request bodies, parameters):
|
|
658
692
|
|
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-CncTLZvX.mjs";
|
|
2
2
|
|
|
3
3
|
export { createComponents, createRegistry, isAnyZodType, unwrapZodObject };
|
|
@@ -467,6 +467,7 @@ const createRegistry = (components) => {
|
|
|
467
467
|
const meta = globalRegistry.get(parameter);
|
|
468
468
|
const name = opts?.location?.name ?? meta?.param?.name;
|
|
469
469
|
const inLocation = opts?.location?.in ?? meta?.param?.in;
|
|
470
|
+
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
471
|
if (!name || !inLocation) throw new Error(`Parameter at ${path.join(" > ")} is missing \`.meta({ param: { name, in } })\` information`);
|
|
471
472
|
const schemaObject = registry$1.addSchema(parameter, [
|
|
472
473
|
...path,
|
|
@@ -500,6 +501,7 @@ const createRegistry = (components) => {
|
|
|
500
501
|
registry$1.components.parameters.ids.set(id, parameterObject);
|
|
501
502
|
return ref;
|
|
502
503
|
}
|
|
504
|
+
if (opts?.location?.name || opts?.location?.in) return parameterObject;
|
|
503
505
|
registry$1.components.parameters.seen.set(parameter, parameterObject);
|
|
504
506
|
return parameterObject;
|
|
505
507
|
},
|
|
@@ -490,6 +490,7 @@ const createRegistry = (components) => {
|
|
|
490
490
|
const meta = zod_v4_core.globalRegistry.get(parameter);
|
|
491
491
|
const name = opts?.location?.name ?? meta?.param?.name;
|
|
492
492
|
const inLocation = opts?.location?.in ?? meta?.param?.in;
|
|
493
|
+
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
494
|
if (!name || !inLocation) throw new Error(`Parameter at ${path.join(" > ")} is missing \`.meta({ param: { name, in } })\` information`);
|
|
494
495
|
const schemaObject = registry$1.addSchema(parameter, [
|
|
495
496
|
...path,
|
|
@@ -523,6 +524,7 @@ const createRegistry = (components) => {
|
|
|
523
524
|
registry$1.components.parameters.ids.set(id, parameterObject);
|
|
524
525
|
return ref;
|
|
525
526
|
}
|
|
527
|
+
if (opts?.location?.name || opts?.location?.in) return parameterObject;
|
|
526
528
|
registry$1.components.parameters.seen.set(parameter, parameterObject);
|
|
527
529
|
return parameterObject;
|
|
528
530
|
},
|
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-CncTLZvX.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/create/document.ts
|
|
4
4
|
const createDocument = (zodOpenApiObject, opts = {}) => {
|