domaindrivendev / Swashbuckle.AspNetCore

Swagger tools for documenting API's built on ASP.NET Core
MIT License
5.26k stars 1.32k forks source link

Is it possible to generate swagger for all available versions using swashbuckle.aspnetcore.cli #1126

Open tkumark opened 5 years ago

tkumark commented 5 years ago

Hi I am using the following command to generate the swagger files. I have v1,v2,v3 etc. is it possible to create swagger for all possible versions?

dotnet %UserProfile%\.nuget\packages\swashbuckle.aspnetcore.cli\4.0.1\lib\netcoreapp2.0\dotnet-swagger.dll tofile --output D:\tempvsts\swagger\swagger2.json D:\tempvsts\testapimgmt\WebApiService\bin\Debug\netcoreapp2.1\win7-x64\WebApiService.dll v2

stevendarby commented 4 years ago

Just wanted to add that I'd really like this feature too

mbradial commented 4 years ago

@tkumark Were you able to get a swagger.json in any format besides OpenAPI 3.0 using the CLI? I have app.UseSwagger(s => { s.SerializeAsV2 = true; }); and I still get OpenAPI 3.0 when I'd like Swagger 2.0 to use for AutoREST.

stevendarby commented 4 years ago

@tkumark Were you able to get a swagger.json in any format besides OpenAPI 3.0 using the CLI? I have app.UseSwagger(s => { s.SerializeAsV2 = true; }); and I still get OpenAPI 3.0 when I'd like Swagger 2.0 to use for AutoREST.

Quick look at source suggest you may need to pass in an argument to the CLI for that: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/master/src/Swashbuckle.AspNetCore.Cli/Program.cs

Default if argument missing seems to be v2

mbradial commented 4 years ago

@tkumark Solution for you would be to run multiple CLI requests with the different versions as arguments as @snappyfoo mentioned. Example: dotnet swagger tofile --serializeasv2 --output 'swagger.json' "bin/Debug/netcoreapp3.1/ThisIsMyProject.Api.dll" v3

Solution to my problem: I didn't see that there's an option in the CLI for Swagger 2.0 via '--serializeasv2'.

amrElroumy commented 4 years ago

Hi @domaindrivendev

I can help with this enhancement if you are OK with it.

I got it working by moving the interface IDocumentProvider to Swashbuckle.AspNetCore.Swagger assembly so it is accessible by the CLI project and using IDocumentProvider::GetDocumentNames() to retrieve the registered documents.

Would this align with your design decisions or did you have another plan for this?

My other question is, do you prefer this to be a new command (e.g. tofiles), as it might be confusing to overload the tofile command with this functionality?

amrElroumy commented 3 years ago

@domaindrivendev Did you get the chance to review my suggestion above? If you agree with it, I can send a PR your way this week.

Franklin89 commented 2 years ago

@amrElroumy Any chance you have a branch or frok of this?

estranda commented 1 year ago

I see it's a long time ago, but any chance to get this PR completed @domaindrivendev / @amrElroumy ?

sttaelma commented 1 month ago

I need this feature too please! @amrElroumy @domaindrivendev

amrElroumy commented 1 month ago

I need this feature too please! @amrElroumy @domaindrivendev

Pardon me folks, I have moved away from this tech stack several years ago.

westfin commented 3 weeks ago

+1 for this feature