jsonContent — JSON media-type wrapper
Imported from the facade: import { jsonContent } from "@/framework/facade.js".
Wraps a Zod schema as an application/json media type with a description — used in createRoute request.body and responses. See OpenAPI.
Signature
| Function | Signature | Description |
|---|---|---|
jsonContent | (schema, description) => { content } | Wrap a schema as a JSON media type with description |
Use cases
Response
ts
responses: {
[HttpStatusCodes.OK]: jsonContent(z.array(PostSchema), "list of posts"),
[HttpStatusCodes.CREATED]: jsonContent(PostSchema, "created post"),
}Request body
ts
request: { body: jsonContent(CreatePostSchema, "post data") },Notes
- Works with any
zschema — including inlinez.object({ message, data })wrappers andz.array(...). - Combined with
HttpStatusCodesinresponses, it drives the Scalar UI.
