• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How can I generate at compile-time a separate OpenAPI Swagger.json file for each Controller in my ASP.NET project?

Resolved: How can I generate at compile-time a separate OpenAPI Swagger.json file for each Controller in my ASP.NET project?

0
By Isaac Tonny on 05/04/2023 Issue
Share
Facebook Twitter LinkedIn

In this post, we will see how to resolve How can I generate at compile-time a separate OpenAPI Swagger.json file for each Controller in my ASP.NET project?

Question:

Our ASP.NET Core web application has an ever-growing list of Controllers. At build-time of the project, I want to programmatically generate an individual separate swagger.json file for each Controller. (We need these files on disk to be picked up by another process.)
I’ve tried using NSwag and Swashbuckle. I configured them to generate a Document per Controller but their build-time CLI libraries seem to only support generating a single swagger.json file for a single specified document. I do not want to manually hard-code any specific document or Controller references.
https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/2578
https://github.com/RicoSuter/NSwag/issues/4292

Best Answer:

Here is a solution I came up with using NSWag. But it could ultimately use any library that can generate files.
Basically what happens is the msbuild step “boots” your web application after it is built and the process checks for a special flag (generate-swagger) to indicate that you just want the swagger generated and the process to exit.
Helper extension method
Call it in Program/Startup.cs and provide a directory
Add this to your web .csproj to generate on build

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com

asp.net msbuild nswag swagger swashbuckle
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to stop a thread that has a blocking function from easygui in python

05/04/2023

Resolved: Removing null keys from a json array of objects

05/04/2023

Resolved: Error No file found while converting file present in s3 using boto3

04/04/2023

Comments are closed.

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.