christianhelle / apiclientcodegen

A collection of Visual Studio custom tool code generators for Swagger / OpenAPI specification files
http://bit.ly/restapicodegen
GNU General Public License v3.0
177 stars 24 forks source link

Preview of generated output #51

Open hardtourvela opened 5 years ago

hardtourvela commented 5 years ago

Hi First of all thanks a lot for this tool, it has really saved me a lot of time!. I have the following use case. I would like to have a little bit more control over specific Swagger files, as an example, i have a specification in which i require to generate only 1 out of 3 DTO's this is because most of my DTOs exist within the same solution already. So i was thinking, (I haven't read your code so I'm just assuming) at the time you first read the swagger file you already know what you're going to create, so maybe show a little "Preview Window" in which you are able to check/uncheck what's about to be generated. BTW do you have any contribution guidelines? I was thinking maybe i can help with this Thanks!

christianhelle commented 5 years ago

Hi!

Thank you for your kind words! I'm glad you find it useful

Regarding having control over Swaagger files, you should consider generating code using NSwag Studio. I have a "right click" based solution for generating a NSwag Studio configuration file and you can customise that file quite extensively, by hand or by using NSwag Studio.

I haven't tried your exact use case but in our case we have a frontend-to-backend gateway used by our frontend applications to interact with our microservices. This gateway will call several microservices using several code generated swagger clients. We use NSwag Studio to use an existing Exception class instead of generating multiple copies of exactly the same class, split by namespace. We always generate our DTO's because this is the contract between the gateway and the microservices, but we write the contracts returned by the gateway endpoints by hand as these describes the resources exposed by the frontend-to-backend gateway and not what the microservices return, even though there are a few scenarios where they are exactly the same

Anyway, implementing a "Preview Window" sounds like a great idea but currently I rely on the IVsSingleFileGenerator interface to implement the Custom Tool and this interface doesn't offer any previewing infrastructure, but we could implement this interface in a way that before we return the generated code to Visual Studio we can show a preview window with an OK/Cancel button and give the user a chance to modify the output by hand. This interface is a UI blocking one that is unfortunately some legacy thing in Visual Studio so the experience might be a bit ugly. We can also create some option pages so we can enable/disable the Preview Window

All in all, I really like this idea! I have no contribution guidelines as I honestly didn't expect to have the number of users I have now. You are more than welcome to come with any contributions and lets take all discussions at the pull request level

Thanks again!