seriousme / fastify-openapi-glue

A plugin for the Fastify webserver to autogenerate a Fastify configuration based on a OpenApi(v2/v3) specification.
MIT License
196 stars 33 forks source link

TypeScript template for fastify-openapi-glue cli? #581

Closed hongkongkiwi closed 1 month ago

hongkongkiwi commented 2 months ago

Hi there,

Thanks for the great project! It's great to be able to make the OpenAPI specs the source of truth.

Is it possible to add a typescript template to the fastify-openapi-glue generator?

seriousme commented 2 months ago

Hi,

last time I checked (few years ago) there was no stable way to generate Typescript types from OpenApi types. The generator itself allows for extra templating (see https://github.com/seriousme/fastify-openapi-glue/tree/master/lib/templates). If you have ideas on how to template the types (without resorting to too much magic) then I'm happy to look into that.

There are plans to add Type annotations to Javascript (https://github.com/tc39/proposal-type-annotations), so I was hoping to piggyback on that one.

Kind regards, Hans

github-actions[bot] commented 1 month ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days'

jcx0 commented 4 days ago

Hello, +1 thanks for this project. I also like the schema-first approach.

A while ago I was able to hack this project https://github.com/hey-api/openapi-ts to generate types for the routes. I've being using it with great success it so far for my personal project. https://github.com/jcx0/fastify-ts if anyone want to take a look, I've included an example server. Seems to support 2.0, 3.0, and 3.1 specifications, but I've only used it for 3.1. Wildcard status codes (e.g. 4XX) don't work, but I'm sure it wouldn't be too hard to implement.

Screenshot 2024-07-22 at 10 44 47 PM