express-zod-api
Advanced tools
Changelog
v22.10.1
ResultHandler
used as errorHandler
for Not Found routes having async handler
.// reproduction
import { createConfig, ResultHandler } from "express-zod-api";
createConfig({
errorHandler: new ResultHandler({
// rejected promise was not awaited:
handler: async () => {
throw new Error(
"You should not do it. But if you do, we've got LastResortHandler to catch it.",
);
},
}),
});
Changelog
v22.10.0
required
property to requestBody
when:
ez.raw()
(proprietary schema);requestBody
depends on the Endpoint method(s) and the configuration of inputSources
;Changelog
v22.9.0
Endpoint
using EndpointsFactory::build({ deprecated: true })
;Endpoint::deprecated()
or DependsOnMethod::deprecated()
;ZodType::deprecated()
;.deprecated()
methods are immutable — they create a new copy of the subject;Documentation
and Integration
;import { Routing, DependsOnMethod } from "express-zod-api";
import { z } from "zod";
const someEndpoint = factory.build({
deprecated: true, // deprecates all routes the endpoint assigned to
input: z.object({
prop: z.string().deprecated(), // deprecates the property or a path parameter
}),
});
const routing: Routing = {
v1: oldEndpoint.deprecated(), // deprecates the /v1 path
v2: new DependsOnMethod({ get: oldEndpoint }).deprecated(), // deprecates the /v2 path
v3: someEndpoint, // the path is assigned with initially deprecated endpoint (also deprecated)
};
Changelog
v22.8.0
input
schema;const updateUserEndpoint = factory.build({
method: "patch",
input: z.object({
id: z.string(), // implies path parameter "id"
}),
});
const routing: Routing = {
v1: {
user: {
":username": updateUserEndpoint, // path parameter is "username" instead of "id"
},
},
};
warn: The input schema of the endpoint is most likely missing the parameter of the path it is assigned to.
{ method: 'patch', path: '/v1/user/:username', param: 'username' }
Changelog
v22.7.0
Changelog
v22.6.0
Documentation
the examples used to work properly only when assigned to
the top level (z.object().example()
), especially complex scenarios involving path parameters and middlewares;const before = factory.build({
input: z
.object({
key: z.string(),
})
.example({
key: "1234-5678-90",
}),
});
const after = factory.build({
input: z.object({
key: z.string().example("1234-5678-90"),
}),
});
Changelog
v22.5.0
defaultResultHandler
sets headers from HttpError
:
throw createHttpError(400, "message", { headers })
those headers
go to the negative response.405
(Method not allowed) to requests having wrong method:
404
;405
:
wrongMethodBehavior
config option 405
(default: 404
).import { createConfig } from "express-zod-api";
createConfig({ wrongMethodBehavior: 405 });