express-zod-api
Advanced tools
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
Changelog
v20.22.0
Routing
for both /v1/path
and /v1/path/subpath
routes having Endpoints attached;.nest()
method is available both on Endpoint
and DependsOnMethod
instances:import { Routing } from "express-zod-api";
// Describing routes /v1/path and /v1/path/subpath both having endpoints assigned:
const before: Routing = {
v1: {
path: {
"": endpointA,
subpath: endpointB,
},
},
};
const after: Routing = {
v1: {
path: endpointA.nest({
subpath: endpointB,
}),
},
};
Changelog
v20.21.2
const jsonEndpoints
indexed by path
;path
used for the lookup already contained parameter substitutions so that JSON parser didn't work;response.headers
;- const parser = `${method} ${path}` in jsonEndpoints ? "json" : "text";
+ const isJSON = response.headers
+ .get("content-type")
+ ?.startsWith("application/json");
- return response[parser]();
+ return response[isJSON ? "json" : "text"]();