- Notifications
You must be signed in to change notification settings - Fork1
lzehrung/zod-express-openapi-routes
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
- Find an ergonomic way (minimize boilerplate and code duplication) to get typed, zod-validated express routes and an OpenAPIschema at the same time
- Minimize code duplication and boilerplate between express routes, request parameter validation, and OpenAPI definitions
- base
Controllerclass that consolidates creation of express route, zod-validated request parameters, OpenAPI definition, and getting a typedexpress.RouteHandler:src/zod-openapi-express-routes/zod-api.controller.ts - example controller instance:src/products/products.controller.ts
- example request parameter zod schemas:src/products/api-schemas.ts
- example manually-defined file upload route usingmulter for uploads:src/products/products.controller.ts#L148
- clone the repository
npm installnpm run dev- open the generated OpenAPI docshttp://localhost:3250/api/reference
- open the generated
swagger.jsonhttp://localhost:3250/api/swagger.json - get a single resourcehttp://localhost:3250/api/products/1
- an invalid path parameter results in validation errorshttp://localhost:3250/api/products/abc
@anatine/zod-openapi: generates request parameter OpenAPI definitions from zod schemasopenapi3-ts: used to define OpenAPI schema in TypeScriptswagger-ui-express: serves the OpenAPI documentationzod: used to define request parameter validation schemas
- file upload routes must be documented manually
- haven't tested nested routers / routes
- not extensively tested
About
POC for cozy API validation, typing, and OpenAPI/swagger schema generation with Zod and Express
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.