openapi-ts icon indicating copy to clipboard operation
openapi-ts copied to clipboard

Nest plugin

Open mrlubos opened this issue 11 months ago β€’ 13 comments

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.

mrlubos avatar Dec 20 '24 01:12 mrlubos

Is this meant as a server or client generator? πŸ˜„

hougesen avatar Dec 27 '24 22:12 hougesen

@hougesen by 'this', are you referring to the Nest plugin or the openapi-ts package?

mrlubos avatar Dec 28 '24 00:12 mrlubos

The plugin/issue

hougesen avatar Dec 28 '24 00:12 hougesen

@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?

mrlubos avatar Dec 28 '24 00:12 mrlubos

Nest has it's own http module (https://docs.nestjs.com/techniques/http-module) which is what I meant by client πŸ˜„

hougesen avatar Jan 06 '25 15:01 hougesen

Can we talk on socials or email? I want to understand this/your use case further

mrlubos avatar Jan 06 '25 16:01 mrlubos

@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 πŸ‘πŸ»

gregbrowndev avatar Jan 20 '25 13:01 gregbrowndev

I would love a client generation from the nest code directly, without generating specs through swagger and then generating the client from there.

BokaTano avatar Feb 06 '25 12:02 BokaTano

@BokaTano, for this need you can try Nestia - https://nestia.io/docs/sdk/

mikhin avatar Mar 11 '25 07:03 mikhin

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/

mikhin avatar Mar 11 '25 07:03 mikhin

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

cmd-tea avatar Mar 25 '25 21:03 cmd-tea

@sudokyle exactly! As always, all a question of priorities, it's not a tiny feature as you can imagine

mrlubos avatar Mar 25 '25 22:03 mrlubos

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.

kpervin avatar Apr 28 '25 13:04 kpervin

@mrlubos generating a NestJS client that is fully-typed to send requests to external services sounds great!

  • one Module that will have a forRoot+forRootAsync function for setting up the general params (baseUrl, default headers...)
  • a Service for each controller in the openapi definition
  • exports all input and output types

can help with implementation.

idbenami avatar Aug 14 '25 17:08 idbenami

@idbenami are you on Discord? Would like to chat a bit about this

mrlubos avatar Aug 14 '25 17:08 mrlubos

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 HttpModule to 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 avatar Aug 15 '25 05:08 idbenami

@idbenami when do you plan to release it?

sergeyzwezdin avatar Sep 26 '25 11:09 sergeyzwezdin

@sergeyzwezdin I want to get it done by the end of October

idbenami avatar Sep 29 '25 20:09 idbenami