@ztrehagem/openapi-to-fastify-schema
v0.1.1
Published
Generate schema objects for Fastify from OpenAPI documents
Downloads
2
Readme
@ztrehagem/openapi-to-fastify-schema
Usage
- Prepare with generating schema objects and type definitions.
npm install -g @ztrehagem/openapi-to-fastify-schema
# or
npm install -D @ztrehagem/openapi-to-fastify-schema
# then
openapi-to-fastify-schema ./path/to/your/openapi.yaml
- Use schema object in Fastify instance.
import type { FastifyInstance } from "fastify";
import type { JsonSchemaToTsProvider } from "@fastify/type-provider-json-schema-to-ts";
import operations from "@ztrehagem/openapi-to-fastify-schema/generated";
declare const app: FastifyInstance;
const { method, url, schema } = operations.getUser;
app.withTypeProvider<JsonSchemaToTsProvider>().route({
method,
url,
schema,
handler: async (req, reply) => {
// Typed!
req.params.userHandle;
await reply.status(200).send({
// Typed!
user: {
handle: "foo",
name: "bar",
},
});
},
});