express-zod-api
Advanced tools
Changelog
v21.3.0
provide()
method usage example in the code of the generated client;splitResponse
property on the Integration
class constructor argument is deprecated.Changelog
v21.2.0
ExpressZodAPIClient::provide()
method:
ExpressZodAPIClient::provide()
with three arguments is deprecated:
unknown
.Provider
type of the generated client is deprecated;Input
, Response
, PositiveResponse
, NegativeResponse
, MethodPath
.- client.provide("get", "/v1/user/retrieve", { id: "10" }); // deprecated
+ client.provide("get /v1/user/retrieve", { id: "10" }); // featured
Changelog
v21.1.0
204
(No Content) and redirects (302);mimeType
property can now be assigned with null
in ResultHandler
definition;Documentation
and Integration
generators ignore such entries so that the schema
can be z.never()
:
Documentation
;undefined
(configurable) by Integration
.import { z } from "zod";
import {
ResultHandler,
ensureHttpError,
EndpointsFactory,
Integration,
} from "express-zod-api";
const resultHandler = new ResultHandler({
positive: { statusCode: 204, mimeType: null, schema: z.never() },
negative: { statusCode: 404, mimeType: null, schema: z.never() },
handler: ({ error, response }) => {
response.status(error ? ensureHttpError(error).statusCode : 204).end(); // no content
},
});
new Integration({ noContent: z.undefined() }); // undefined is default
Changelog
v21.0.0
express
: 4.21.1 and 5.0.1 (fixed vulnerabilities);createConfig()
argument:
server
property renamed to http
and made optional — (can now configure HTTPS only);jsonParser
, upload
, compression
, rawParser
and beforeRouting
;logger
and getChildLogger
arguments of beforeRouting
function are replaced with all-purpose getLogger
.createServer()
resolved return:
httpServer
and httpsServer
are combined into single servers
property (array, same order).EndpointsFactory::build()
argument:
methods
, tags
and scopes
properties replaced with singular method
, tag
, scope
accordingly;method
property also made optional and can now be derived from DependsOnMethod
or imply GET
by default;method
is assigned with an array, it must be non-empty.positive
and negative
properties of ResultHandler
constructor argument:
statusCodes
and mimeTypes
props within the values are replaced with singular statusCode
and mimeType
.serializer
property of Documentation
and Integration
constructor argument removed;originalError
property of InputValidationError
and OutputValidationError
removed (use cause
instead);getStatusCodeFromError()
method removed (use the ensureHttpError().statusCode
instead);testEndpoint()
method can no longer test CORS headers — that function moved to Routing
traverse;Endpoint
: getMethods()
may return undefined
, getMimeTypes()
removed, getSchema()
variants reduced;pairs
, firstEndpoint
and siblingMethods
of DependsOnMethod
replaced with entries
.// eslint.config.mjs — minimal ESLint 9 config to apply migrations automatically using "eslint --fix"
import parser from "@typescript-eslint/parser";
import migration from "express-zod-api/migration";
export default [
{ languageOptions: { parser }, plugins: { migration } },
{ files: ["**/*.ts"], rules: { "migration/v21": "error" } },
];
// The sample of new structure
const config = createConfig({
http: { listen: 80 }, // became optional
https: { listen: 443, options: {} },
upload: true,
compression: true,
beforeRouting: ({ app, getLogger }) => {
const logger = getLogger();
app.use((req, res, next) => {
const childLogger = getLogger(req);
});
},
});
const { servers } = await createServer(config, {});
Changelog
v20.22.1