RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.69k stars 1.23k forks source link

Versions in YAML written without quotes #1278

Open EricKeij opened 6 years ago

EricKeij commented 6 years ago

The WebApiToSwaggerGenerator writes versions in a YAML without quotes causing it to give parse errors in swagger editor.

Actual swagger: 2.0 Expected: swagger: "2.0"

The same applies to the info.version element.

RicoSuter commented 6 years ago

I think it's this issue: https://github.com/aaubry/YamlDotNet/issues/33

csgulyas commented 8 months ago

I think I found a workaround for this, at least for the Info Version.

If you give a MAJOR.MINOR.PATCH format for the info version, validators won't think it's a number. The format probably doesn't matter, as long as it doesn't resemble a number. The swagger/openapi verson problem probably has been resolved, as it generates openapi: 3.0.0 for me already in 2024.

builder.Services.AddOpenApiDocument(settings => { settings.Title = "MyWebApi"; settings.DocumentName = "MyWebApi"; settings.Version = "1.0.0"; // instead of "1.0" });

Since 1.0.0 can't possibly be a valid number, it will be assumed it's a string.

Then I generate the YAML in my dotnet6 with the following command: dotnet nswag aspnetcore2openapi /configuration:Release /noBuild:True /project:MyWebApi\MyWebApi.csproj /documentName:MyWebApi /output:MyWebApi\bin\Release\net6.0\openapi.yaml