Repository navigation
Closed
Milestone
Description
Simple Read and Write results in different documents. What is even more alarming is that after write the document is invalid (tested here and also openapi-diff crashes on it. Original is valid) Following simplified example demonstrates it:
public static void Test()
{
var input =
@"{
""openapi"": ""3.0.1"",
""paths"": {
""/api/v2/test"": {
""post"": {
""operationId"": ""Test"",
""requestBody"": {
""content"": {
""application/x-www-form-urlencoded"": {
""schema"": {
""type"": ""object"",
""properties"": {
""Username"": {
""type"": ""string"",
""nullable"": true
}
}
},
""encoding"": {
""Username"": {
""style"": ""form""
}
}
}
}
},
""responses"": {
""200"": {
""description"": ""Success"",
""content"": {
""application/json"": {}
}
}
}
}
}
}
}";
var apiDocument = new OpenApiStringReader().Read(input, out var _);
var stringBuilder = new StringBuilder();
using var stringWriter = new StringWriter(stringBuilder);
apiDocument.SerializeAsV3(new OpenApiJsonWriter(stringWriter));
stringWriter.Flush();
var output = stringBuilder.ToString();
var actualOutput =
@"{
""openapi"": ""3.0.1"",
""info"": { },
""paths"": {
""/api/v2/test"": {
""post"": {
""operationId"": ""Test"",
""requestBody"": {
""content"": {
""application/x-www-form-urlencoded"": {
""schema"": {
""type"": ""object"",
""properties"": {
""Username"": {
""type"": ""string"",
""nullable"": true
}
}
},
""encoding"": {
""Username"": { }
}
}
}
},
""responses"": {
""200"": {
""description"": ""Success"",
""content"": {
""application/json"": null
}
}
}
}
}
}
}";
}
Notice "application/json": null (=this is why it is invalid) vs "application/json": {} and encoding.
Reacted by Martin Ovesny
Metadata
Metadata
Assignees
Labels
No labels
Activity
darrelmiller commentedon Jan 23, 2022
Thank you for reporting this. Roundtripping empty media type objects should work. However, it is an interesting question to ask if null is functionally equivalent to an empty object in this case. I've raised this on the OpenAPI slack. In the meanwhile I have made the fix.
I also have fixed the issue with the encoding style. There's not many people that use that feature so it had a bug that was simple to fix. This should go out in the next preview release of 1.3.0.
janRucka commentedon Jan 27, 2022
Thank you as well!