Parse error and missing valid Swagger or OpenAPI version field
See original GitHub issueI 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:
- Created 4 years ago
- Comments:13 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks, that worked.
Here is my configuration if anyone wonders.
Having same problem here. With Swashbukle.AspNetCore version 5.5.1, runs fine locally but get the error when deploying to Azure.