Parse error and missing valid Swagger or OpenAPI version field

See original GitHub issue

I am using the following packages:

  • Swashbuckle.AspNetCore 5.0.0-rc2
  • Microsoft.AspNetCore 2.2,
  • Microsoft.AspNetCore.Authentication.AzureAD.UI 2.2.0
  • Microsoft.AspNetCore.Mvc 2.2.0
  • Microsoft.AspNetCore.Mvc.Versioning 3.1.2
  • Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer 3.2.0

I have set everything up to use OpenAPI. When adding swagger generation with the code below I get:

  • “Parser error on line 201 missed comma between flow collection entries” and “missing valid Swagger or OpenApi version field”.
  • “Unable to render this definition The provided definition does not specify a valid version field. Please indicate a valid Swagger or OpenAPI version field. Supported version fields are swagger: “2.0” and those that match openapi: 3.0.n (for example, openapi: 3.0.0).”
services.AddSwaggerGen(options =>
            {
                options.AddSecurityDefinition("bearer", new OpenApiSecurityScheme
                {
                    Type = SecuritySchemeType.Http,
                    Scheme = "bearer",
                    BearerFormat = "JWT",
                    Description = "JWT Authorization header using the Bearer scheme. Example: \"Bearer {token}\"",
                    Name = "Authorization",
                    In = ParameterLocation.Header,
                    Flows = new OpenApiOAuthFlows
                    {
                        Implicit = new OpenApiOAuthFlow
                        {
                            AuthorizationUrl = new Uri($"https://login.microsoftonline.com/{configuration["AzureAD:TenantId"]}/oauth2/authorize", UriKind.RelativeOrAbsolute),
                            Scopes = new Dictionary<string, string>
                            {
                                {
                                    "user_impersonation", "Access api"
                                }
                            }
                        }
                    }
                });

                options.AddSecurityRequirement(new OpenApiSecurityRequirement
                {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference = new OpenApiReference { Type = ReferenceType.Header, Id = "Authorization" }
                        },
                        new[] { "user_impersonation" }
                    }
                });

I may be doing things wrong, but I have tried to find ways to do this and it seems to me that there are settings/properties missing. Please enlighten me, is this is a bug or not. Kind regards Thomas

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

10reactions
vanillajonathancommented, Apr 15, 2019

Thanks, that worked.

Here is my configuration if anyone wonders.

// Register the Swagger generator, defining one or more Swagger documents
services.AddSwaggerGen(c =>
{
    c.SwaggerDoc("v1", new OpenApiInfo { Title = "Acme API", Version = "v1" });
    c.AddSecurityDefinition("bearerAuth", new OpenApiSecurityScheme
    {
        Type = SecuritySchemeType.Http,
        Scheme = "bearer",
        BearerFormat = "JWT",
        Description = "JWT Authorization header using the Bearer scheme."
    });
    c.AddSecurityRequirement(new OpenApiSecurityRequirement
    {
        {
            new OpenApiSecurityScheme
            {
                Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "bearerAuth" }
            },
            new string[] {}
        }
    });
});
4reactions
Kedi1997commented, Sep 7, 2020

I’m running into this issue with v5.0.0.

  <PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0" />
    <PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.0.0" />

Works locally, but once I deploy it shows the error.

Having same problem here. With Swashbukle.AspNetCore version 5.5.1, runs fine locally but get the error when deploying to Azure.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swagger..Unable to render this definition The provided ...
Your API definition is missing the OpenAPI/Swagger version number, in this case "swagger": "2.0" . Add it at the beginning, like so:
Read more >
Integrated Swagger UI throws error on valid OpenAPI spec ...
Summary When opening a valid OpenAPI JSON file from the Repository / Files section, an error message is displayed saying:
Read more >
OpenAPI Specification - Version 2.0
Specifies the Swagger Specification version being used. It can be used by the Swagger UI and other clients to interpret the API listing....
Read more >
Parsing error(s): The input OpenAPI file is not valid for the ...
When we are validating the schema with OpenAPI specification getting the below error . One or more fields contain incorrect values: Parsing ......
Read more >
Failed to update API in Azure - Microsoft Q&A
I tried to generate the swagger.json file by running the 'dotnet swagger tofile' command. If I run it without the '--serializeasv2' argument the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found