OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.85k stars 6.59k forks source link

[REQ] Add New Language Support for Typescript Nestjs #3336

Closed vfrank66 closed 3 years ago

vfrank66 commented 5 years ago

Is your feature request related to a problem? Please describe.

There is already support for angular but we have been using typescript nestjs for our backend and frontend work. I would like to add support for nestjs.

Describe the solution you'd like

I would like this to be okay and I will work on the PR.

Describe alternatives you've considered

Additional context

macjohnny commented 5 years ago

sure, any contribution is welcome. Please keep in mind https://github.com/OpenAPITools/openapi-generator/issues/802 cc @TiFu

vfrank66 commented 5 years ago

@macjohnny can do!

macjohnny commented 5 years ago

If you want to help the typescript refactoring, this would be very nice

TiFu commented 5 years ago

Unfortunately, I currently don't have the capacity to actively work on the refactoring due to some other stuff going on in my life. However, the most basic features are supported in the new code base and kinda documented. If @vfrank66 decides to implement nestjs support in the refactored code base, I'd be happy to provide some guidance on that.

Otherwise, I think it would also be possible to just implement nestjs support by cloning one of the other generators and working from there. Integrating this new generator later in the refactored code base is not a big issue imo as most of the code generators require only either a) adapting the http request library and/or b) generating some boilerplate code.

vfrank66 commented 5 years ago

Alright I'll help out, I see #802 and a lot of different issues. I will help get this converted in order to then add nestjs. Any contribution? Or what would you like completed first or what filter to use on the issues? @TiFu @macjohnny

macjohnny commented 5 years ago

Alright I'll help out

that's excellent, thank you!

TiFu commented 5 years ago

@vfrank66 Thanks a lot! The code for the rework is currently on the typescript-refactor branch and follows the structure outlined in #802. So far I have added support for ts-fetch and I think jquery is almost done.

I think you could either try to add other generators (angular, rxjs, axios, node request module) support or just try to include nestjs in this new structure. My understanding so far is that nestjs significantly differs from the two generators I already implemented (the main difference between fetch & jquery being that the HTTP library is different - everything else is basically the same).

I think simply adding nestjs based on what's already there might be a good idea, so that we see if our structure is general enough to work with a variety of different frameworks. To better understand the structure, I would probably advise you to have a look at the ts-fetch generator first and try to adapt its approach. If there is specific code needed for nestjs, wrapping the API clients in another class (which would be located in the framework specific code layer in the svg in #802) would be the right approach. If I can help you in any way, let me know and we can either discuss it on github or maybe even have a short skype call if that's easier.

I believe you don't have commit access to OpenAPITools, so if your changes are ready, you can just PR against typescript-refactor, tag me and then I'll have a look.

vfrank66 commented 5 years ago

@TiFu okay I started looking at the code and the changes between master and typescript-refactor. Is this project still current https://github.com/OpenAPITools/openapi-generator/projects/4? It seems TODO's match up with what you responded with.

We can take this conversation outside of here if you would like, just let me know.

TiFu commented 5 years ago

Yeah it is up-to-date. I will have a look at the TODO items tomorrow and see if I can make their titles a little bit clearer and add some more context.

We can take this conversation outside of here if you would like, just let me know. I don't have any preference, whatever helps you most.

quezak commented 5 years ago

This is a nice idea! @vfrank66 out of curiosity, what are your plans for the NestJS generated clients? I mean: how will they differ from the regular typescript-node clients? Do you want to generate full services ready to be injected using Nest's DI?

macjohnny commented 5 years ago

@vfrank66 would you want to implement this in the current master, too? so it could be made available soon.

vfrank66 commented 5 years ago

Sorry started this and then fell asleep on it, will complete this week.

@quezak - nestjs will be most similar to typescript-angular with small exceptions like token injection, and decorator naming convention. With regards to these library similarities it will be injectable into the nestjs DI container as a nestjs service, or in nestjs terms module just as angular codegen is injectable into angular DI. I have the code written and issue open with the swagger-openapi for reference if you would like to see it complete.

@macjohnny i am currently off typescript-refactor or you asking me to switch that to master and PR against master?

macjohnny commented 5 years ago

If you want to have your feature published in an official release soon I suggest you to file your PR against master. I don‘t know how long it will take for the typescript refactoring to land

vfrank66 commented 5 years ago

@macjohnny thank you sorry work got in the way, so I have the code which I know works with the other swagger codegen setup. I seem to be having a problem getting the class loader to recognize the new generator. I followed the directions online just in case and no luck. So I am stuck but pushed what I have to my fork. I was hoping someone could explain to me what else besides adding a line to org.openapitools.codegen.CodegenConfig I need to do.

macjohnny commented 5 years ago

@wing328 can you help here?

arrigod commented 4 years ago

Hello, I would also be interested in this feature. What is the current status?

wing328 commented 4 years ago

@vfrank66 please file a PR to start with. We'll review and let you know what else needs to be done to get it merged into master.

vfrank66 commented 4 years ago

@wing328 okay I can do that

vfrank66 commented 4 years ago

@wing328 PR, sorry for the delay

wing328 commented 4 years ago

@vfrank66 no need to apologize and we all appreciate your contributions to this project 👍

macjohnny commented 3 years ago

closed with #8522

dimatomp commented 3 years ago

@wing328 Sorry for a rather basic question, but is it only about a NestJS-compatible client generator, with server stub left out of scope?

pguso commented 3 years ago

@wing328 i was very surprised that with this new generator only client services can be generated. Nestjs is primarily used as server, will there be a server implemented also?

TiFu commented 3 years ago

I haven't seen anyone working on a nest-specific server. However, we are always happy to review contributions, so if you have the capacity we would certainly welcome a nest server generator.

Happy to also point you in the right direction to get started if you are interested.

pguso commented 3 years ago

@TiFu I would love to do that, but I don’t have much Java knowledge. Please point out how I could start and I will see if I can find a way to develop that generator.

TiFu commented 3 years ago

@pguso Couple pointers below:

Initial starting point should probably be:

From there, the NodeJS Express Server generator is probably a good starting point. The relevant files can be found in:

In my mind, the ideal case for server generators would be similar to what we are trying to do with the consolidated typescript client generator:

This has the advantage, that bug fixes in the underlay then automatically apply across all server generators and there is little to no code duplication.

michaeljauk commented 2 years ago

@pguso Is there any update on this? Have you started working on a nest.js server implemenation?

0bach0 commented 2 years ago

@pguso @michaeljauk @TiFu

do you guys have any update on nestjs server generator? I wanna contribute to the implementation.

C0retek commented 2 years ago

Hi guys, @pguso @michaeljauk @TiFu has anybody started work on the NestJS Server Generator? Just checking as I want to use that Framework for a new project, but having finished my OpenAPI definitions I was wondering if I can use them to generate the Server Stubs. For now I only see the Node/Express in the Docs...

macjohnny commented 2 years ago

looking at https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages, there currently is a NestJsClient generator, so a server generator can be contributed

C0retek commented 2 years ago

Should this be a new Request as this one is Closed?

macjohnny commented 2 years ago

@C0retek I think a new issue is good

C0retek commented 2 years ago

Done ! here

Kalliser commented 2 years ago

Hello, Is there a chance to see nestjs support v9 of nestJS as HttpModule and HttpService are now imported from @nestjs/axios package ?

macjohnny commented 2 years ago

@Kalliser you can send a PR to implement this