openapi-ts
openapi-ts copied to clipboard
Nest plugin
Please vote on this issue if you're interested in Nest plugin.
This issue will serve as a to-do list during development. To help us release this feature as quickly as possible, feel free to share the minimum requirements for your use case.
Is this meant as a server or client generator? π
@hougesen by 'this', are you referring to the Nest plugin or the openapi-ts package?
The plugin/issue
@hougesen the original idea was to offer a similar plugin as we have for Fastify, where you start with the spec and make sure that your server code matches the specification (spec-first). What would be the client generator approach? If you're doing code-first and generating a spec from Nest, you can already use that to generate the clients. Would there be any difference to what you're thinking?
Nest has it's own http module (https://docs.nestjs.com/techniques/http-module) which is what I meant by client π
Can we talk on socials or email? I want to understand this/your use case further
@mrlubos sounds like what I'm looking for is what you intended: server-code generation (schema-first or code-first) so your API server routes and schema stay in sync.
I'm specifically using NextJS (not NestJS to be clear) and the tooling seems to be pretty poor. It would be great if the [xyz server framework] plugin were able to generate the JSON schema from the code (or visa versa) for frameworks that don't have great tooling around this already.
Once you've got the JSON Schema, I've found openapi-ts works great for client-side SDK generation ππ»
I would love a client generation from the nest code directly, without generating specs through swagger and then generating the client from there.
@BokaTano, for this need you can try Nestia - https://nestia.io/docs/sdk/
I have a hypothesis that we could also use Nestia and its entities (TypedRoute, TypedBody, TypedParam, TypedQuery) as an intermediate βglueβ to link NestJS with derivatives from the hey-api plugin
https://nestia.io/docs/core/TypedRoute/
Nest seems to have a good backend ecosystem; I would love to see a server generator (especially seeing as there are next to no TS server generators) for open api.
It would be cool if it generated a Controller file along with the dto models and then a controller delegate interface that the controller used for the bodies of its endpoint handler functions. The developer could then implement the interface of the controller delegate and then import the controller into their module along with their concrete implementation of the controller delegate and then Nest js would handle the injection of the controller delegate on the instance of the API Controller it creates
@sudokyle exactly! As always, all a question of priorities, it's not a tiny feature as you can imagine
As much as a server generator would be great, it would be nice to also have a NestJS module generator for querying external APIs. Given that NestJS uses Axios for their built-in HTTP module, I can't imagine it would be a huge lift as there's already an Axios plugin.
@mrlubos generating a NestJS client that is fully-typed to send requests to external services sounds great!
- one
Modulethat will have aforRoot+forRootAsyncfunction for setting up the general params (baseUrl, default headers...) - a
Servicefor each controller in theopenapidefinition - exports all input and output types
can help with implementation.
@idbenami are you on Discord? Would like to chat a bit about this
Hey everyone π
Following a conversation with @mrlubos, Iβm planning to work on a NestJS client generator for openapi-ts.
The idea is to genrate NestJS module and services that will allow developers to easily consume OpenAPI endpoints in a NestJS application.
Approach:
- Generate a NestJS module that encapsulates the OpenAPI client.
- Create services for each OpenAPI tag (controller), allowing developers to interact with the API endpoints.
- Keep the actual request generation logic close to the existing Axios client generator.
- Align API usage patterns with Nestβs
HttpModuleto feel familiar for NestJS developers.
If you have thoughts on config design, naming conventions, or common NestJS patterns that should be supported - Iβd love to hear them!
@idbenami when do you plan to release it?
@sergeyzwezdin I want to get it done by the end of October