express-zod-api
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -5,2 +5,23 @@ # Changelog | ||
### v2.1.0 | ||
- Zod version is 3.7.1. | ||
- New response schema type `ZodFile` can be created using `z.file()`. It has two refinements: `.binary()` and | ||
`.base64()` which also reflected in the generated Swagger / OpenAPI documentation. | ||
You can use it instead of `z.string()` with `createApiResponse()`: | ||
```typescript | ||
// before | ||
const fileStreamingEndpointsFactoryBefore = new EndpointsFactory(createResultHandler({ | ||
getPositiveResponse: () => createApiResponse(z.string(), 'image/*'), | ||
... | ||
})); | ||
// after | ||
const fileStreamingEndpointsFactoryAfter = new EndpointsFactory(createResultHandler({ | ||
getPositiveResponse: () => createApiResponse(z.file().binary(), 'image/*'), | ||
... | ||
})); | ||
``` | ||
- Please do NOT use `z.file()` within the `Endpoint` input / output object schemas. | ||
### v2.0.0 | ||
@@ -7,0 +28,0 @@ |
@@ -13,4 +13,4 @@ export { ConfigType, LoggerConfig } from './config-type'; | ||
export { OpenAPIError, DependsOnMethodError, RoutingError } from './errors'; | ||
import { z } from 'zod'; | ||
import * as z from './extend-zod'; | ||
import createHttpError from 'http-errors'; | ||
export { createHttpError, z }; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -33,6 +52,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "RoutingError", { enumerable: true, get: function () { return errors_1.RoutingError; } }); | ||
const zod_1 = require("zod"); | ||
Object.defineProperty(exports, "z", { enumerable: true, get: function () { return zod_1.z; } }); | ||
const z = __importStar(require("./extend-zod")); | ||
exports.z = z; | ||
const http_errors_1 = __importDefault(require("http-errors")); | ||
exports.createHttpError = http_errors_1.default; | ||
//# sourceMappingURL=index.js.map |
@@ -7,2 +7,3 @@ "use strict"; | ||
const errors_1 = require("./errors"); | ||
const file_schema_1 = require("./file-schema"); | ||
const helpers_1 = require("./helpers"); | ||
@@ -29,3 +30,2 @@ const routing_1 = require("./routing"); | ||
// null is not supported https://swagger.io/docs/specification/data-models/data-types/ | ||
// return {...otherProps, type: 'null'}; | ||
return { ...otherProps, type: 'string', nullable: true, format: 'null' }; | ||
@@ -86,2 +86,9 @@ case value instanceof zod_1.z.ZodArray: | ||
}; | ||
case value instanceof file_schema_1.ZodFile: | ||
return { | ||
...otherProps, | ||
type: 'string', | ||
format: value.isBinary ? 'binary' : | ||
value.isBase64 ? 'byte' : 'file' | ||
}; | ||
case value instanceof zod_1.z.ZodUndefined: | ||
@@ -88,0 +95,0 @@ case value instanceof zod_1.z.ZodTuple: |
{ | ||
"name": "express-zod-api", | ||
"version": "2.0.0", | ||
"version": "2.1.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", |
@@ -46,3 +46,3 @@ # Express Zod API | ||
- [Typescript](https://www.typescriptlang.org/) first | ||
- Schema validation — [Zod 3.x](https://github.com/colinhacks/zod) *(stable)*. | ||
- Schema validation — [Zod 3.x](https://github.com/colinhacks/zod). | ||
- Webserver — [Express.js](https://expressjs.com/). | ||
@@ -312,7 +312,10 @@ - Logger — [Winston](https://github.com/winstonjs/winston). | ||
[in this example](https://github.com/RobinTail/express-zod-api/blob/master/example/factories.ts). | ||
One of them implements file streaming, in this case the endpoint just has to provide the filename: | ||
One of them implements file streaming, in this case the endpoint just has to provide the filename. | ||
The response schema generally may be just `z.string()`, but there is also a specific one: `z.file()` that also supports | ||
`.binary()` and `.base64()` refinements which are reflected in the | ||
[generated documentation](#swagger--openapi-specification). | ||
```typescript | ||
const fileStreamingEndpointsFactory = new EndpointsFactory(createResultHandler({ | ||
getPositiveResponse: () => createApiResponse(z.string(), 'image/*'), | ||
getPositiveResponse: () => createApiResponse(z.file().binary(), 'image/*'), | ||
getNegativeResponse: () => createApiResponse(z.string(), 'text/plain'), | ||
@@ -319,0 +322,0 @@ handler: ({response, error, output}) => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
115298
50
1204
476