The routes to generate documentation for.
Optional
document: Document<{}>The OpenAPI document to extend/override the generated documentation.
A middleware function that serves the Swagger UI documentation.
Example usage:
import { start, router, json, swaggerMiddleware } from "@pulsar-http/core";
import { z } from "zod";
const userSchema = z.object({
name: z.string(),
age: z.number(),
});
const usersResponseSchema = z.object({
message: z.string(),
user: userSchema,
}).strict();
const routes = [
router.get("/", async () => json({ message: "Hello, world!" })),
router.post('/users', async ({ body }) => json({
message: "User created",
user: body,
}), { bodySchema: userSchema, responseSchema: usersResponseSchema }),
];
start({
routes,
middlewares: [swaggerMiddleware(routes)],
});
In this example, the /swagger
route will serve the Swagger UI documentation for the provided routes.
Middleware to generate and serve Swagger UI documentation.