OpenAPI.NET icon indicating copy to clipboard operation
OpenAPI.NET copied to clipboard

Bug: Swagger enum Data and type mismatch found.

Open chi-qin opened this issue 3 years ago • 1 comments

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();	
		}
	}
}

chi-qin avatar Aug 31 '21 15:08 chi-qin

Is there any update on this?

gdodd1977 avatar Mar 28 '24 12:03 gdodd1977