3 ms·
I'm also curious about the reverse direction -- can I generate an openAPI spec from my typescript Api? I'd rather write code than schemas.
by igor47 4y ago
I'm also curious about the reverse direction -- can I generate an openAPI spec from my typescript Api? I'd rather write code than schemas.
- jayp 4y agoThis is the best project I’ve found to that for that - https://github.com/lukeautry/tsoa https://github.com/lukeautry/tsoa. Uses decorators mainly. If there are other such projects, please share.
- NonNefarious 4y ago
- aserafini 4y agoThis is exactly how FastAPI/Pydantic in the Python ecosystem works (and also in Django-ninja for Django). You compose types representing your request and response shape. Those types validate the API request and it’s response, and also generate the OpenAPI. Even slight drift between API spec, docs and actual behaviour is impossible in this setup, I couldn’t go back to working any other way!
- twelve40 4y agocan only speak for python on the backend, but have been using auto-generated schema from Django, and an auto-generated typescript client for it on the front end for years now.
- remoquete 4y agoSure, though that goes against the API first design principles that OpenAPI seeks to enable. It also results in poorly documented, often garbled OpenAPI specs. Code-generated specs simply cease to be effective as contracts. https://swagger.io/resources/articles/adopting-an-api-first-approach/ https://swagger.io/resources/articles/adopting-an-api-first-...
- rattray 4y agoThis is something we hope to build relatively soon at Stainless, inspired by Stripe's in-house Ruby API DSL. I think what you're asking for is the right approach.