Search code examples
swaggerasp.net-core-webapiopenapiautorest

Autorest error - swagger.json' is not a valid OpenAPI 2.0 definition (expected 'swagger: 2.0')


My api is running net core 3.0 with Swashbuckle.AspNetCore 5.0.0-rc5

When I run autorest on my generated swagger.json file I get:

swagger.json is not a valid OpenAPI 2.0 definition (expected 'swagger: 2.0')

My swagger.json file does indeed say "openapi": "3.0.1". It used to be v2.0 but since I upgraded to net core 3.0 I had to upgrade Swashbuckle which now creates the json file with v3.0.1

I ran "choco install autorest" so I should be running the latest version

If autorest doesn't support openapi3.0 there must still surely be a way to generate an openapi2.0 json file?


Solution

  • Followed this thread, auto rest doesn’t support latest open api yet but there are workarounds

    https://github.com/Azure/autorest/issues/2680

    You can do this:

    app.UseSwagger(o => o.SerializeAsV2 = true);