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

Client code is not generated again when definition file is replaced externally #209

Open daniol opened 3 years ago

daniol commented 3 years ago

Making any changes to the OpenAPI spec file (swagger.json) file with an external tool (outside Visual Studio) does not trigger the re-generation of the client code. Client code is only re-generated when the spec file is opened and modified inside Visual Studio.

Support Key: 2979cf3

To Reproduce Steps to reproduce the behavior:

  1. Create a new client project, using openapi-generator
  2. Update the swagger.json file outside visual studio (for example, replacing with a new version that adds methods or modifies existing ones)
  3. Build project
  4. Client code is not updated, new changes are not reflected

Expected behavior When the project is built, the plug-in should force the client to be generated again, in order to detect changes that were made outside Visual Studio.

Visual Studio Extension:

daniol commented 3 years ago

Workaround: call rapicgen tool in pre-build event

rapicgen openapi swagger.json NameSpaceName ./MyFileName.cs

christianhelle commented 3 years ago

First of all, thanks for pointing this out @daniol

Another workaround I can suggest is to right click on the OpenAPI spec file in the project and "Run Custom Tool"

run-custom-tool

You can also open the OpenAPI spec file in Visual Studio and make a trivial whitespace change and press save, then undo the change again.

Anyway, I'm not sure if its possible to handle pre-build events from Visual Studio without tampering with the project file and adding pre-build events. If the Visual Studio SDK supports such or similar events then it might be possible to implement an option to always re-generate the REST API client code before build. This would work really great especially with NSwag as the code gets generated very very quickly. Unfortunately, it would really be a bad experience with AutoRest as this takes a lot of time to generate code, OpenAPI Generator is not that slow but there is a noticeable delay until the operation is completed

If I were to build such an option it would be disabled by default as it would be very opinionated of the tool to just assume that most users want this behavior.

I'll have to investigate deeper for this