express-zod-api
Advanced tools
Changelog
v22.0.0
BuiltinLogger::profile()
behavior changed for picoseconds: expressing them through nanoseconds;x-
prefixed) headers as an input source (when enabled):
headers
inside inputSources
config option: all headers are addressed to the input
object;x-
prefixed headers;inputSources
matters, consider moving headers
to the first place to avoid overwrites;Documentation
recognizes both x-
prefixed inputs and well-known headers listed on IANA.ORG;isHeader
of the Documentation::constructor()
.splitResponse
property on the Integration::constructor()
argument is removed;Integration
:
ExpressZodAPIClient
to just Client
;Client::provide()
having 3 arguments and the Provider
type are removed;jsonEndpoints
const is removed — use the content-type
header of an actual response instead;MethodPath
is removed — use the Request
type instead.tags
property moved from the argument of createConfig()
to Documentation::constructor()
;EndpointsFactory::constructor()
accepting config
property is removed;EventStreamFactory::constructor()
is now the events map (formerly assigned to events
property);TagOverrides
instead;Endpoint::getSecurity()
now returns an array;// 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/v22": "error" } },
];
createConfig({
- tags: {},
inputSources: {
- get: ["query", "headers"] // if you have headers on last place
+ get: ["headers", "query"] // move headers to avoid overwrites
}
});
new Documentation({
+ tags: {},
+ isHeader: (name, method, path) => {} // optional
});
new EndpointsFactory(
- { config, resultHandler: new ResultHandler() }
+ new ResultHandler()
);
new EventStreamFactory(
- { config, events: {} }
+ {} // events map only
);
// new tagging approach
import { defaultEndpointsFactory, Documentation } from "express-zod-api";
// Add similar declaration once, somewhere in your code, preferably near config
declare module "express-zod-api" {
interface TagOverrides {
users: unknown;
files: unknown;
subscriptions: unknown;
}
}
// Add extended description of the tags to Documentation (optional)
new Documentation({
tags: {
users: "All about users",
files: { description: "All about files", url: "https://example.com" },
},
});
Changelog
v21.11.1
Changelog
v21.11.0
ctx
is available on instances of BuiltinLogger
:
childLoggerProvider
config option, the ctx
property contains the argument
that was used for creating the child logger using its .child()
method;requestId
property for purposes other than logging;ctx
is an empty object (when the instance is not a child logger).import { BuiltinLogger, createConfig, createMiddleware } from "express-zod-api";
// Declaring the logger type in use
declare module "express-zod-api" {
interface LoggerOverrides extends BuiltinLogger {}
}
// Configuring child logger provider
const config = createConfig({
childLoggerProvider: ({ parent }) =>
parent.child({ requestId: randomUUID() }),
});
// Accessing child logger context
createMiddleware({
handler: async ({ logger }) => {
doSomething(logger.ctx.requestId); // <—
},
});
Changelog
v21.10.0
Integration
option: serverUrl
, string, optional, the API URL for the generated client:
https://example.com
;new URL()
for constructing the final request URL in the example implementation of the generated client:
serverUrl
both with and without trailing slash;Changelog
v21.9.0
MethodPath
type in the code generated by Integration
:
Request
type to be used instead;Integration
;