zod-openapi 2.14.0 → 2.15.0
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
CHANGED
|
@@ -518,6 +518,7 @@ For example in `z.string().nullable()` will be rendered differently
|
|
|
518
518
|
- `pre-process` support. We assume that the input type is the same as the output type. Otherwise pipe and transform can be used instead.
|
|
519
519
|
- `refine` full support
|
|
520
520
|
- ZodEnum
|
|
521
|
+
- ZodIntersection
|
|
521
522
|
- ZodLazy
|
|
522
523
|
- The recursive schema within the ZodLazy or the ZodLazy _**must**_ be registered as a component. See [Creating Components](#creating-components) for more information.
|
|
523
524
|
- ZodLiteral
|
package/lib-commonjs/index.js
CHANGED
|
@@ -356,15 +356,47 @@ var createLazySchema = (zodLazy, state) => {
|
|
|
356
356
|
return createSchemaObject(innerSchema, state, ["lazy schema"]);
|
|
357
357
|
};
|
|
358
358
|
|
|
359
|
-
// src/
|
|
360
|
-
var
|
|
359
|
+
// src/openapi.ts
|
|
360
|
+
var openApiVersions = [
|
|
361
|
+
"3.0.0",
|
|
362
|
+
"3.0.1",
|
|
363
|
+
"3.0.2",
|
|
364
|
+
"3.0.3",
|
|
365
|
+
"3.1.0"
|
|
366
|
+
];
|
|
367
|
+
var satisfiesVersion = (test, against) => openApiVersions.indexOf(test) >= openApiVersions.indexOf(against);
|
|
368
|
+
|
|
369
|
+
// src/create/schema/parsers/null.ts
|
|
370
|
+
var createNullSchema = () => ({
|
|
361
371
|
type: "schema",
|
|
362
372
|
schema: {
|
|
363
|
-
type:
|
|
364
|
-
enum: [zodLiteral._def.value]
|
|
373
|
+
type: "null"
|
|
365
374
|
}
|
|
366
375
|
});
|
|
367
376
|
|
|
377
|
+
// src/create/schema/parsers/literal.ts
|
|
378
|
+
var createLiteralSchema = (zodLiteral, state) => {
|
|
379
|
+
if (zodLiteral.value === null) {
|
|
380
|
+
return createNullSchema();
|
|
381
|
+
}
|
|
382
|
+
if (satisfiesVersion(state.components.openapi, "3.1.0")) {
|
|
383
|
+
return {
|
|
384
|
+
type: "schema",
|
|
385
|
+
schema: {
|
|
386
|
+
type: typeof zodLiteral.value,
|
|
387
|
+
const: zodLiteral.value
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
return {
|
|
392
|
+
type: "schema",
|
|
393
|
+
schema: {
|
|
394
|
+
type: typeof zodLiteral.value,
|
|
395
|
+
enum: [zodLiteral.value]
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
};
|
|
399
|
+
|
|
368
400
|
// src/create/schema/parsers/manual.ts
|
|
369
401
|
var createManualTypeSchema = (zodSchema, state) => {
|
|
370
402
|
if (!zodSchema._def.openapi?.type) {
|
|
@@ -383,16 +415,6 @@ var createManualTypeSchema = (zodSchema, state) => {
|
|
|
383
415
|
};
|
|
384
416
|
};
|
|
385
417
|
|
|
386
|
-
// src/openapi.ts
|
|
387
|
-
var openApiVersions = [
|
|
388
|
-
"3.0.0",
|
|
389
|
-
"3.0.1",
|
|
390
|
-
"3.0.2",
|
|
391
|
-
"3.0.3",
|
|
392
|
-
"3.1.0"
|
|
393
|
-
];
|
|
394
|
-
var satisfiesVersion = (test, against) => openApiVersions.indexOf(test) >= openApiVersions.indexOf(against);
|
|
395
|
-
|
|
396
418
|
// src/create/schema/parsers/nativeEnum.ts
|
|
397
419
|
var createNativeEnumSchema = (zodEnum, state) => {
|
|
398
420
|
const enumValues = getValidEnumValues(zodEnum._def.values);
|
|
@@ -444,14 +466,6 @@ var sortStringsAndNumbers = (values) => ({
|
|
|
444
466
|
numbers: values.filter((value) => typeof value === "number")
|
|
445
467
|
});
|
|
446
468
|
|
|
447
|
-
// src/create/schema/parsers/null.ts
|
|
448
|
-
var createNullSchema = (_zodNull) => ({
|
|
449
|
-
type: "schema",
|
|
450
|
-
schema: {
|
|
451
|
-
type: "null"
|
|
452
|
-
}
|
|
453
|
-
});
|
|
454
|
-
|
|
455
469
|
// src/create/schema/parsers/nullable.ts
|
|
456
470
|
var createNullableSchema = (zodNullable, state) => {
|
|
457
471
|
const schemaObject = createSchemaObject(zodNullable.unwrap(), state, [
|
|
@@ -589,7 +603,7 @@ var mapNumberType = (zodNumberChecks) => zodNumberChecks.int ? "integer" : "numb
|
|
|
589
603
|
// src/create/schema/parsers/optional.ts
|
|
590
604
|
var createOptionalSchema = (zodOptional, state) => createSchemaObject(zodOptional.unwrap(), state, ["optional"]);
|
|
591
605
|
var isOptionalSchema = (zodSchema, state) => {
|
|
592
|
-
if (isZodType(zodSchema, "ZodOptional") || isZodType(zodSchema, "ZodNever") || isZodType(zodSchema, "ZodUndefined")) {
|
|
606
|
+
if (isZodType(zodSchema, "ZodOptional") || isZodType(zodSchema, "ZodNever") || isZodType(zodSchema, "ZodUndefined") || isZodType(zodSchema, "ZodLiteral") && zodSchema._def.value === void 0) {
|
|
593
607
|
return { optional: true };
|
|
594
608
|
}
|
|
595
609
|
if (isZodType(zodSchema, "ZodDefault")) {
|
|
@@ -1189,7 +1203,7 @@ var createSchemaSwitch = (zodSchema, state) => {
|
|
|
1189
1203
|
return createEnumSchema(zodSchema);
|
|
1190
1204
|
}
|
|
1191
1205
|
if (isZodType(zodSchema, "ZodLiteral")) {
|
|
1192
|
-
return createLiteralSchema(zodSchema);
|
|
1206
|
+
return createLiteralSchema(zodSchema, state);
|
|
1193
1207
|
}
|
|
1194
1208
|
if (isZodType(zodSchema, "ZodNativeEnum")) {
|
|
1195
1209
|
return createNativeEnumSchema(zodSchema, state);
|
|
@@ -1207,7 +1221,7 @@ var createSchemaSwitch = (zodSchema, state) => {
|
|
|
1207
1221
|
return createDiscriminatedUnionSchema(zodSchema, state);
|
|
1208
1222
|
}
|
|
1209
1223
|
if (isZodType(zodSchema, "ZodNull")) {
|
|
1210
|
-
return createNullSchema(
|
|
1224
|
+
return createNullSchema();
|
|
1211
1225
|
}
|
|
1212
1226
|
if (isZodType(zodSchema, "ZodNullable")) {
|
|
1213
1227
|
return createNullableSchema(zodSchema, state);
|
package/lib-esm/index.mjs
CHANGED
|
@@ -332,15 +332,47 @@ var createLazySchema = (zodLazy, state) => {
|
|
|
332
332
|
return createSchemaObject(innerSchema, state, ["lazy schema"]);
|
|
333
333
|
};
|
|
334
334
|
|
|
335
|
-
// src/
|
|
336
|
-
var
|
|
335
|
+
// src/openapi.ts
|
|
336
|
+
var openApiVersions = [
|
|
337
|
+
"3.0.0",
|
|
338
|
+
"3.0.1",
|
|
339
|
+
"3.0.2",
|
|
340
|
+
"3.0.3",
|
|
341
|
+
"3.1.0"
|
|
342
|
+
];
|
|
343
|
+
var satisfiesVersion = (test, against) => openApiVersions.indexOf(test) >= openApiVersions.indexOf(against);
|
|
344
|
+
|
|
345
|
+
// src/create/schema/parsers/null.ts
|
|
346
|
+
var createNullSchema = () => ({
|
|
337
347
|
type: "schema",
|
|
338
348
|
schema: {
|
|
339
|
-
type:
|
|
340
|
-
enum: [zodLiteral._def.value]
|
|
349
|
+
type: "null"
|
|
341
350
|
}
|
|
342
351
|
});
|
|
343
352
|
|
|
353
|
+
// src/create/schema/parsers/literal.ts
|
|
354
|
+
var createLiteralSchema = (zodLiteral, state) => {
|
|
355
|
+
if (zodLiteral.value === null) {
|
|
356
|
+
return createNullSchema();
|
|
357
|
+
}
|
|
358
|
+
if (satisfiesVersion(state.components.openapi, "3.1.0")) {
|
|
359
|
+
return {
|
|
360
|
+
type: "schema",
|
|
361
|
+
schema: {
|
|
362
|
+
type: typeof zodLiteral.value,
|
|
363
|
+
const: zodLiteral.value
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
return {
|
|
368
|
+
type: "schema",
|
|
369
|
+
schema: {
|
|
370
|
+
type: typeof zodLiteral.value,
|
|
371
|
+
enum: [zodLiteral.value]
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
};
|
|
375
|
+
|
|
344
376
|
// src/create/schema/parsers/manual.ts
|
|
345
377
|
var createManualTypeSchema = (zodSchema, state) => {
|
|
346
378
|
if (!zodSchema._def.openapi?.type) {
|
|
@@ -359,16 +391,6 @@ var createManualTypeSchema = (zodSchema, state) => {
|
|
|
359
391
|
};
|
|
360
392
|
};
|
|
361
393
|
|
|
362
|
-
// src/openapi.ts
|
|
363
|
-
var openApiVersions = [
|
|
364
|
-
"3.0.0",
|
|
365
|
-
"3.0.1",
|
|
366
|
-
"3.0.2",
|
|
367
|
-
"3.0.3",
|
|
368
|
-
"3.1.0"
|
|
369
|
-
];
|
|
370
|
-
var satisfiesVersion = (test, against) => openApiVersions.indexOf(test) >= openApiVersions.indexOf(against);
|
|
371
|
-
|
|
372
394
|
// src/create/schema/parsers/nativeEnum.ts
|
|
373
395
|
var createNativeEnumSchema = (zodEnum, state) => {
|
|
374
396
|
const enumValues = getValidEnumValues(zodEnum._def.values);
|
|
@@ -420,14 +442,6 @@ var sortStringsAndNumbers = (values) => ({
|
|
|
420
442
|
numbers: values.filter((value) => typeof value === "number")
|
|
421
443
|
});
|
|
422
444
|
|
|
423
|
-
// src/create/schema/parsers/null.ts
|
|
424
|
-
var createNullSchema = (_zodNull) => ({
|
|
425
|
-
type: "schema",
|
|
426
|
-
schema: {
|
|
427
|
-
type: "null"
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
|
|
431
445
|
// src/create/schema/parsers/nullable.ts
|
|
432
446
|
var createNullableSchema = (zodNullable, state) => {
|
|
433
447
|
const schemaObject = createSchemaObject(zodNullable.unwrap(), state, [
|
|
@@ -565,7 +579,7 @@ var mapNumberType = (zodNumberChecks) => zodNumberChecks.int ? "integer" : "numb
|
|
|
565
579
|
// src/create/schema/parsers/optional.ts
|
|
566
580
|
var createOptionalSchema = (zodOptional, state) => createSchemaObject(zodOptional.unwrap(), state, ["optional"]);
|
|
567
581
|
var isOptionalSchema = (zodSchema, state) => {
|
|
568
|
-
if (isZodType(zodSchema, "ZodOptional") || isZodType(zodSchema, "ZodNever") || isZodType(zodSchema, "ZodUndefined")) {
|
|
582
|
+
if (isZodType(zodSchema, "ZodOptional") || isZodType(zodSchema, "ZodNever") || isZodType(zodSchema, "ZodUndefined") || isZodType(zodSchema, "ZodLiteral") && zodSchema._def.value === void 0) {
|
|
569
583
|
return { optional: true };
|
|
570
584
|
}
|
|
571
585
|
if (isZodType(zodSchema, "ZodDefault")) {
|
|
@@ -1165,7 +1179,7 @@ var createSchemaSwitch = (zodSchema, state) => {
|
|
|
1165
1179
|
return createEnumSchema(zodSchema);
|
|
1166
1180
|
}
|
|
1167
1181
|
if (isZodType(zodSchema, "ZodLiteral")) {
|
|
1168
|
-
return createLiteralSchema(zodSchema);
|
|
1182
|
+
return createLiteralSchema(zodSchema, state);
|
|
1169
1183
|
}
|
|
1170
1184
|
if (isZodType(zodSchema, "ZodNativeEnum")) {
|
|
1171
1185
|
return createNativeEnumSchema(zodSchema, state);
|
|
@@ -1183,7 +1197,7 @@ var createSchemaSwitch = (zodSchema, state) => {
|
|
|
1183
1197
|
return createDiscriminatedUnionSchema(zodSchema, state);
|
|
1184
1198
|
}
|
|
1185
1199
|
if (isZodType(zodSchema, "ZodNull")) {
|
|
1186
|
-
return createNullSchema(
|
|
1200
|
+
return createNullSchema();
|
|
1187
1201
|
}
|
|
1188
1202
|
if (isZodType(zodSchema, "ZodNullable")) {
|
|
1189
1203
|
return createNullableSchema(zodSchema, state);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ZodLiteral } from 'zod';
|
|
2
|
-
import type { Schema } from '..';
|
|
3
|
-
export declare const createLiteralSchema: (zodLiteral: ZodLiteral<unknown
|
|
2
|
+
import type { Schema, SchemaState } from '..';
|
|
3
|
+
export declare const createLiteralSchema: (zodLiteral: ZodLiteral<unknown>, state: SchemaState) => Schema;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod-openapi",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.15.0",
|
|
4
4
|
"description": "Convert Zod Schemas to OpenAPI v3.x documentation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -47,14 +47,13 @@
|
|
|
47
47
|
"test:ci": "skuba test --coverage",
|
|
48
48
|
"test:watch": "skuba test --watch"
|
|
49
49
|
},
|
|
50
|
-
"dependencies": {},
|
|
51
50
|
"devDependencies": {
|
|
52
|
-
"@redocly/cli": "1.
|
|
51
|
+
"@redocly/cli": "1.10.5",
|
|
53
52
|
"@types/node": "^20.3.0",
|
|
54
53
|
"eslint-plugin-zod-openapi": "^0.1.0",
|
|
55
|
-
"openapi3-ts": "4.
|
|
56
|
-
"skuba": "7.5.
|
|
57
|
-
"yaml": "2.4.
|
|
54
|
+
"openapi3-ts": "4.3.1",
|
|
55
|
+
"skuba": "7.5.1",
|
|
56
|
+
"yaml": "2.4.1",
|
|
58
57
|
"zod": "3.22.4"
|
|
59
58
|
},
|
|
60
59
|
"peerDependencies": {
|