Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
daniol opened this issue May 5, 2021 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@daniol
Copy link

daniol commented May 5, 2021

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:

  • Visual Studio: 2019 (Community)
  • Extension Version 1.2.6685
@daniol
Copy link
Author

daniol commented May 5, 2021

Workaround:
call rapicgen tool in pre-build event

rapicgen openapi swagger.json NameSpaceName ./MyFileName.cs

@christianhelle christianhelle self-assigned this May 5, 2021
@christianhelle
Copy link
Owner

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

@christianhelle christianhelle added the enhancement New feature or request label May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants