You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a global consumes/produces is set after paths then the schema is not loaded when calling OpenApiStreamReader.Read. The code below replicates that issue. The original json has the consumes/produces at the end. It then produces openApiDocument3 with the missing schema. The code then moves the 'produces' before 'paths' and produces openApiDocument4. In this case the schema is not missing. The different results are shown in the attachment. Note that some tools produce json descriptions with global consumes/produces after paths so this is not just a matter of "why don't you just move it to the front".
string jsonDescription = "{"swagger":"2.0","info":{"description":"consumes/produces issue","version":"2.0.0","title":"Swagger Petstore"},"host":"petstore.swagger.io","basePath":"/v2","paths":{"/pet/{petId}":{"get":{"tags":["pet"],"summary":"Find pet by ID","operationId":"getPetById","parameters":[{"name":"petId","in":"path","description":"ID of pet to return","required":true,"type":"integer","format":"int64"}],"responses":{"200":{"description":"successful operation","schema":{"$ref":"#/definitions/Pet"}}}}}},"definitions":{"Pet":{"type":"object","required":["name","photoUrls"],"properties":{"id":{"type":"integer","format":"int64"},"name":{"type":"string","example":"doggie"}},"xml":{"name":"Pet"}}},"produces":["application/json"]}";
byte[] byteArray3 = Encoding.ASCII.GetBytes(jsonDescription);
MemoryStream stream3 = new MemoryStream(byteArray3);
OpenApiDocument openApiDocument3 = new OpenApiStreamReader().Read(stream3, out var diagnostic3);
//Re-arrange produces.
Newtonsoft.Json.Linq.JObject jObject3 = Newtonsoft.Json.Linq.JObject.Parse(jsonDescription);
Newtonsoft.Json.Linq.JProperty producesProperty = jObject3.Property("produces");
Newtonsoft.Json.Linq.JProperty paths = jObject3.Property("paths");
jObject3.Property("produces").Remove();
paths.AddBeforeSelf(producesProperty);
jsonDescription = jObject3.ToString();
byteArray3 = Encoding.ASCII.GetBytes(jsonDescription);
stream3 = new MemoryStream(byteArray3);
OpenApiDocument openApiDocument4 = new OpenApiStreamReader().Read(stream3, out var diagnostic4);
The title sounds like the problem I'm having though i'm not sure it's the exact same.
Using Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer 3,1 on our API, the schema field appears to not get parsed correctly (Or the JSON is malformed). Either way I've attached a repro project with sample json that should demonstrate the issue. Kindly refer me elsewhere if you don't think it's a problem with the reader, however this worked in version 2.2.0 of the API explorer.
EDIT: On further inspection it looks like the new Reader version 1.1.2 exhibits the problem but not 1.1.1.
I think #368 alone is not a fix to your problem but it should have solved a regression that was introduced earlier.
That said, the latest version containing fix in #368 hasn't been released as a NuGet package yet. I can release it soon, and will notify this thread. After that, could you give it a try and let us know if you are still seeing the problem?
If that still doesn't work, I'll investigate this more.
I'm having the same issue and have verified that #368 does resolve my issue. I would like to see this released as a NuGet package so I can consume the fix on our build server.
Reacted by Darrel, Alex Perovich and Mikhail Yartsev
It looks like the issue should have been solved by #368 and the NuGet package has been published. I'll close this issue - please feel free to open if the bug is still not fixed.
Activity
darrelmiller commentedon Dec 23, 2018
I believe this PR #368 should fix your issue.
jaredgermano commentedon Jan 4, 2019
SchemaRepro.zip
The title sounds like the problem I'm having though i'm not sure it's the exact same.
Using Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer 3,1 on our API, the schema field appears to not get parsed correctly (Or the JSON is malformed). Either way I've attached a repro project with sample json that should demonstrate the issue. Kindly refer me elsewhere if you don't think it's a problem with the reader, however this worked in version 2.2.0 of the API explorer.
EDIT: On further inspection it looks like the new Reader version 1.1.2 exhibits the problem but not 1.1.1.
PerthCharern commentedon Jan 8, 2019
jaredgermano
I think #368 alone is not a fix to your problem but it should have solved a regression that was introduced earlier.
That said, the latest version containing fix in #368 hasn't been released as a NuGet package yet. I can release it soon, and will notify this thread. After that, could you give it a try and let us know if you are still seeing the problem?
If that still doesn't work, I'll investigate this more.
tsieberg commentedon Feb 7, 2019
I'm having the same issue and have verified that #368 does resolve my issue. I would like to see this released as a NuGet package so I can consume the fix on our build server.
PerthCharern commentedon Apr 28, 2019
It looks like the issue should have been solved by #368 and the NuGet package has been published. I'll close this issue - please feel free to open if the bug is still not fixed.