express-zod-api
Advanced tools
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"]();
Changelog
v20.21.0
input
property can be now omitted on the argument of the following methods:
Middlware::constructor
, EndpointsFactory::build()
, EndpointsFactory::addMiddleware()
;z.object({})
is used;Changelog
v20.20.1
Changelog
v20.20.0
errorHandler
option for testMiddleware()
method:
testMiddlware
itself
would not throw, enabling usage of all returned entities for mutiple assertions in test;import { testMiddleware, Middleware } from "express-zod-api";
const middlware = new Middleware({
input: z.object({}),
handler: async ({ logger }) => {
logger.info("logging something");
throw new Error("something went wrong");
},
});
test("a middleware throws, but it writes log as well", async () => {
const { loggerMock, responseMock } = await testMiddleware({
errorHandler: (error, response) => response.end(error.message),
middleware,
});
expect(loggerMock._getLogs().info).toEqual([["logging something"]]);
expect(responseMock._getData()).toBe("something went wrong");
});