express-zod-api
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -5,2 +5,29 @@ # Changelog | ||
### v2.3.0 | ||
- Changes and improvements of the generated Swagger / OpenAPI documentation: | ||
```yaml | ||
ZodArray: # z.array() | ||
before: | ||
type: array | ||
items: | ||
type: type # type of the array items | ||
after: | ||
type: array | ||
items: | ||
type: type | ||
minItems: value # optional, when z.array().min(value) | ||
maxItems: value # optional, when z.array().max(value) | ||
ZodTuple: # z.tuple() | ||
before: | ||
error: unsupported | ||
after: | ||
type: array | ||
items: | ||
oneOf: [] # schemas of the tuple items | ||
minItems: value # number of items in the tuple | ||
maxItems: value # number of items in the tuple | ||
description: '0: type, 1: type, ...' | ||
``` | ||
### v2.2.0 | ||
@@ -7,0 +34,0 @@ |
@@ -39,5 +39,9 @@ "use strict"; | ||
...otherProps, | ||
type: 'array', | ||
items: describeSchema(value._def.type, isResponse) | ||
...describeArray(value._def, isResponse) | ||
}; | ||
case value instanceof zod_1.z.ZodTuple: | ||
return { | ||
...otherProps, | ||
...describeTuple(value, isResponse) | ||
}; | ||
case value instanceof zod_1.z.ZodRecord: | ||
@@ -109,3 +113,2 @@ return { | ||
case value instanceof zod_1.z.ZodUndefined: | ||
case value instanceof zod_1.z.ZodTuple: | ||
case value instanceof zod_1.z.ZodMap: | ||
@@ -122,2 +125,27 @@ case value instanceof zod_1.z.ZodFunction: | ||
}; | ||
const describeArray = (definition, isResponse) => { | ||
var _a; | ||
return ({ | ||
type: 'array', | ||
items: describeSchema(definition.type, isResponse), | ||
...(definition.minLength ? { minItems: definition.minLength.value } : {}), | ||
...(definition.maxLength ? { maxItems: (_a = definition.maxLength) === null || _a === void 0 ? void 0 : _a.value } : {}) | ||
}); | ||
}; | ||
/** @todo improve it when OpenAPI 3.1.0 will be released */ | ||
const describeTuple = (schema, isResponse) => { | ||
const types = schema.items.map((item) => describeSchema(item, isResponse)); | ||
return { | ||
type: 'array', | ||
minItems: types.length, | ||
maxItems: types.length, | ||
items: { | ||
oneOf: types, | ||
format: 'tuple', | ||
...(types.length === 0 ? {} : { | ||
description: types.map((schema, index) => `${index}: ${schema.type}`).join(', ') | ||
}) | ||
} | ||
}; | ||
}; | ||
const describeString = (schema) => { | ||
@@ -124,0 +152,0 @@ const checks = schema._def.checks; |
{ | ||
"name": "express-zod-api", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "A Typescript library to help you get an API server up and running with I/O schema validation and custom middlewares in minutes.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
124631
1281