-
-
Notifications
You must be signed in to change notification settings - Fork 37
v28 is for Koko Da Doll
#3208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
v28 is for Koko Da Doll
#3208
Changes from all commits
2c98073
25910d5
ad4b5ec
3e1d7a3
751feb6
ba0de05
9801f9f
1dafe94
a1762d4
4bd1266
670535f
0fd0d08
edb84ef
61bf5bd
52ba492
43fc509
843bf23
606a45b
d0813cf
a6f48d6
f320254
495053c
cdab2ac
db876a2
994d600
ab4bd18
a9f4a0f
144c2d2
321bc7a
061e59f
db7ecb2
2babbfe
fd0dae1
d82e00e
6733c73
d29892b
9f91c4f
377fc3e
2f92153
a355124
5b11b09
94a210a
c4603d4
f1ee242
a25887b
30a91e4
99c94c0
13fcd0f
2d7a095
5d8af02
c7a46da
10553c6
bd5152a
4cfd7c8
1e88e5c
d25ab9b
786235d
ebb59da
43deaaf
15bbe5c
f1813f5
7c402a2
2a47cd4
bf42a25
a38351c
f09ff93
3f8b431
6f1355f
6771142
c55d4bb
90a2c30
e72b8ec
f7e0946
58c648a
ca38a61
5111f35
0592f22
34158a2
b3c6499
80f9fab
5d9c291
97a32e0
3f3296e
bfa68fd
c04d26f
55c94bf
7b217ea
5e1a249
0e372e7
8a1afcc
9afb519
7cbc2f0
44b77e2
7935b92
bf9e63d
c926a80
a367cfd
e4697d0
11c4af1
87afa56
c3e128e
6bb6c37
257b5fd
1185c23
db72038
9725d04
20daea5
abd0d31
a2e5a6e
f603c72
cf34dff
5181d18
ffbc0f6
b321427
83e74a4
3f88085
a2f7a07
0cec360
3b9244e
ad8ff20
a13017c
8fa06c4
40062e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,8 +164,7 @@ Much can be customized to fit your needs. | |
|
|
||
| - [Typescript](https://www.typescriptlang.org/) first. | ||
| - Web server — [Express.js](https://expressjs.com/) v5. | ||
| - Schema validation — [Zod 4.x](https://github.com/colinhacks/zod) including [Zod Plugin](#zod-plugin): | ||
| - For using with Zod 3.x, install the framework versions below 24.0.0. | ||
| - Schema validation — [Zod 4.x](https://github.com/colinhacks/zod); | ||
| - Supports any logger having `info()`, `debug()`, `error()` and `warn()` methods; | ||
| - Built-in console logger with colorful and pretty inspections by default. | ||
| - Generators: | ||
|
|
@@ -243,7 +242,7 @@ const helloWorldEndpoint = defaultEndpointsFactory.build({ | |
| Connect your endpoint to the `/v1/hello` route: | ||
|
|
||
| ```ts | ||
| import { Routing } from "express-zod-api"; | ||
| import type { Routing } from "express-zod-api"; | ||
|
|
||
| const routing: Routing = { | ||
| v1: { | ||
|
|
@@ -920,7 +919,7 @@ it normalizes errors into consistent HTTP responses with sensible status codes. | |
| - Routing, parsing and upload issues: | ||
| - Handled by `ResultHandler` configured as `errorHandler` (the defaults is `defaultResultHandler`); | ||
| - Parsing errors: passed through as-is (typically `HttpError` with `4XX` code used for response by default); | ||
| - Routing errors: `404` or `405`, based on `wrongMethodBehavior` configuration; | ||
| - Routing errors: `404` or `405`, based on `hintAllowedMethods` configuration; | ||
| - Upload issues: thrown only if `upload.limitError` is configured (`HttpError::statusCode` can be used for response); | ||
| - For other errors the default status code is `500`; | ||
| - `ResultHandler` failures: | ||
|
|
@@ -1100,8 +1099,21 @@ expect(output).toEqual({ collectedContext: ["prev"], testLength: 9 }); | |
|
|
||
| ## Zod Plugin | ||
|
|
||
| Express Zod API augments Zod using [Zod Plugin](https://www.npmjs.com/package/@express-zod-api/zod-plugin), | ||
| adding the runtime helpers the framework relies on. | ||
| The [@express-zod-api/zod-plugin](https://www.npmjs.com/package/@express-zod-api/zod-plugin) is an optional package | ||
| that extends Zod with convenience methods: | ||
|
|
||
| - `.xBrand(name)` — shorthand for `.meta({ "x-brand": name })`; | ||
| - `.example(value)` — shorthand for `.meta({ examples: [value] })`; | ||
| - `.deprecated()` — shorthand for `.meta({ deprecated: true })`; | ||
| - `.label(text)` — shorthand for `.meta({ default: text })` on `ZodDefault`; | ||
| - `.remap(mapping)` — for renaming `ZodObject` shape properties; | ||
|
|
||
| To benefit from these methods, install `@express-zod-api/zod-plugin` and import it once, preferably at the top of a | ||
| file declaring your `Routing`. | ||
|
|
||
| ```ts | ||
| import "@express-zod-api/zod-plugin"; // in your routing.ts file | ||
| ``` | ||
|
|
||
| ## End-to-End Type Safety | ||
|
|
||
|
|
@@ -1162,20 +1174,21 @@ in the generated documentation of your API. Consider the following example: | |
| import { defaultEndpointsFactory } from "express-zod-api"; | ||
|
|
||
| const exampleEndpoint = defaultEndpointsFactory.build({ | ||
| shortDescription: "Retrieves the user.", // <—— this becomes the summary line | ||
| summary: "Retrieves the user.", | ||
| description: "The detailed explanaition on what this endpoint does.", | ||
| input: z.object({ | ||
| id: z | ||
| .string() | ||
| .example("123") // input examples should be set before transformations | ||
| .string() // input examples should be set before transformations | ||
| .example("123") // requires Zod Plugin, or .meta({ examples: ["123"] }) | ||
| .transform(Number) | ||
| .describe("the ID of the user"), | ||
| }), | ||
| // ..., similarly for output and middlewares | ||
| }); | ||
| ``` | ||
|
|
||
| You can also use `schema.meta({ id: "UniqueName" })` for custom schema naming. | ||
| Setting examples via `.example()` requires [Zod Plugin](#zod-plugin). You can also use `.meta({ examples: [] })` and | ||
| `.meta({ id: "UniqueName" })` for custom schema naming. | ||
| _See the complete example of the generated documentation | ||
| [here](https://github.com/RobinTail/express-zod-api/blob/master/example/example.documentation.yaml)_ | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The CHANGELOG introduces |
||
|
|
@@ -1213,18 +1226,18 @@ new Documentation({ | |
|
|
||
| ## Deprecated schemas and routes | ||
|
|
||
| As your API evolves, you may need to mark some parameters or routes as deprecated before deleting them. For this | ||
| purpose, the `.deprecated()` method is available on each schema and `Endpoint`, it's immutable. | ||
| You can also deprecate all routes the `Endpoint` assigned to by setting `EndpointsFactory::build({ deprecated: true })`. | ||
| As your API evolves, you may need to mark some parameters or routes as deprecated before deleting them. This can be | ||
| achieved using the corresponding method or metadata. The `.deprecated()` method on Zod schema requires to install the | ||
| [Zod Plugin](#zod-plugin). Consider the following example: | ||
|
|
||
| ```ts | ||
| import { Routing } from "express-zod-api"; | ||
| import type { Routing } 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 | ||
| prop: z.string().deprecated(), // requires Zod Plugin, or .meta({ deprecated: true }) | ||
| }), | ||
| }); | ||
|
|
||
|
|
@@ -1236,10 +1249,11 @@ const routing: Routing = { | |
|
|
||
| ## Customizable brands handling | ||
|
|
||
| You can customize handling rules for your schemas in Documentation and Integration. Use the `.brand()` method on your | ||
| schema to make it special and distinguishable for the framework in runtime. Using symbols is recommended for branding. | ||
| After that use the `brandHandling` feature of both constructors to declare your custom implementation. In case you need | ||
| to reuse a handling rule for multiple brands, use the exposed types `Depicter` and `Producer`. | ||
| You can customize handling rules for your schemas in Documentation and Integration. The framework treats your schema | ||
| specially based on its `x-brand` metadata. When the [Zod Plugin](#zod-plugin) is installed you can conveniently use | ||
| the `.xBrand()` method on Zod schema, preferably with a symbol argument for its branding. After that use the | ||
| `brandHandling` feature of both constructors to declare your custom implementation. In case you need to reuse a | ||
| handling rule for multiple brands, use the exposed types `Depicter` and `Producer`. | ||
|
|
||
| ```ts | ||
| import ts from "typescript"; | ||
|
|
@@ -1252,7 +1266,7 @@ import { | |
| } from "express-zod-api"; | ||
|
|
||
| const myBrand = Symbol("MamaToldMeImSpecial"); // I recommend to use symbols for this purpose | ||
| const myBrandedSchema = z.string().brand(myBrand); | ||
| const myBrandedSchema = z.string().xBrand(myBrand); // requires Zod Plugin, or .meta({ "x-brand": myBrand }) | ||
|
|
||
| const ruleForDocs: Depicter = ( | ||
| { zodSchema, jsonSchema }, // jsonSchema is the default depiction | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "extends": "@tsconfig/node20/tsconfig.json", | ||
| "extends": "@tsconfig/node22/tsconfig.json", | ||
| "include": ["quick-start.ts"] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two small additions worth considering under the migration bullet: (a) the migration now requires ESLint ≥ 10 and typescript-eslint ≥ 8.58 (peer-dep bump in
migration/package.json), so users on ESLint 9 will see a peer-dep error when installing; (b)getBrand()was removed from@express-zod-api/zod-plugin's exports — users who imported it (as encouraged by the oldbrandHandlingdocs) now needschema.meta()?.["x-brand"]. Currently only documented in the plugin's own CHANGELOG.