-
Notifications
You must be signed in to change notification settings - Fork 279
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.
zitmen
Metadata
Metadata
Assignees
Labels
No labels