OpenAPI.NET
OpenAPI.NET copied to clipboard
Bug: Swagger enum Data and type mismatch found.
When I use Microsoft.OpenApi
to check my swagger json file, it throws some errors.
The errors are as follows.
Data and type mismatch found. [#/components/schemas/HttpStatusCode/enum/0]
Data and type mismatch found. [#/components/schemas/HttpStatusCode/enum/1]
Data and type mismatch found. [#/components/schemas/HttpStatusCode/enum/2]
In fact, the HttpStatusCode
is a integer enum, it uses different name to represent different value, but Microsoft.OpenApi
checks that value must be same with type, but in fact HttpStatusCode
is a integer enum, it just appears as string from swagger page.
The swagger file is here. https://lcs-pubdev-wus.azurewebsites.net/swagger/v1/swagger.json
The code that checks the swagger is here.
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.IO;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Readers;
using System.Linq;
public class Program
{
public static async Task Main()
{
Uri swaggerUri = new Uri("<link>");
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync(swaggerUri);
if (response.StatusCode != System.Net.HttpStatusCode.OK)
{
("Could not load Swagger " + swaggerUri + " Status Code:" + response.StatusCode).Dump();
return;
}
Stream stream = await response.Content.ReadAsStreamAsync();
OpenApiDocument openApiDocument = new OpenApiStreamReader().Read(stream, out OpenApiDiagnostic diagnostic);
if (diagnostic.Errors.Any())
{
String.Join(Environment.NewLine, diagnostic.Errors.Select(o => o.ToString())).Dump();
}
else
{
("Swagger " + swaggerUri + " is Conformant").Dump();
}
}
}
Is there any update on this?