Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Microsoft.OpenApi/Models/OpenApiResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ public virtual void SerializeAsV3(IOpenApiWriter writer)
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_0, (writer, element) => element.SerializeAsV3(writer));
}

private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version,
private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version,
Action<IOpenApiWriter, IOpenApiSerializable> callback)
{
Utils.CheckArgumentNull(writer);

writer.WriteStartObject();

// description
writer.WriteRequiredProperty(OpenApiConstants.Description, Description);
writer.WriteProperty(OpenApiConstants.Description, Description);

// headers
writer.WriteOptionalMap(OpenApiConstants.Headers, Headers, callback);
Expand All @@ -96,7 +96,7 @@ public virtual void SerializeAsV2(IOpenApiWriter writer)
writer.WriteStartObject();

// description
writer.WriteRequiredProperty(OpenApiConstants.Description, Description);
writer.WriteProperty(OpenApiConstants.Description, Description);

var extensionsClone = Extensions is not null ? new Dictionary<string, IOpenApiExtension>(Extensions) : null;

Expand Down Expand Up @@ -153,7 +153,7 @@ public virtual void SerializeAsV2(IOpenApiWriter writer)
// so remove it from the cloned collection so we don't write it again.
extensionsClone?.Remove(key);
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.IO;
using System.Net.Http;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Moq;
using Xunit;

Expand Down Expand Up @@ -61,5 +63,24 @@ public void SerializeAsV3_DoesNotCallV31OrV2Serialization()
_linkMock.Verify(l => l.SerializeAsV31(It.IsAny<IOpenApiWriter>()), Times.Never);
_linkMock.Verify(l => l.SerializeAsV2(It.IsAny<IOpenApiWriter>()), Times.Never);
}

[Theory]
[InlineData(OpenApiSpecVersion.OpenApi2_0)]
[InlineData(OpenApiSpecVersion.OpenApi3_0)]
[InlineData(OpenApiSpecVersion.OpenApi3_1)]
public async Task SerializeResponseWithoutDescriptionAsJsonDoesNotWriteNullDescription(OpenApiSpecVersion specVersion)
{
// Arrange
var response = new OpenApiResponse();

// Act
var actual = await response.SerializeAsJsonAsync(specVersion, TestContext.Current.CancellationToken);

// Assert
var node = JsonNode.Parse(actual);
Assert.NotNull(node);
var responseObject = Assert.IsType<JsonObject>(node);
Assert.False(responseObject.ContainsKey(OpenApiConstants.Description));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ public async Task SerializeOperationWithBodyAsV3JsonWorks()
"$ref": "#/components/responses/response1"
},
"400": {
"description": null,
"content": {
"application/json": {
"schema": {
Expand Down Expand Up @@ -416,7 +415,6 @@ public async Task SerializeAdvancedOperationWithTagAndSecurityAsV3JsonWorks()
"$ref": "#/components/responses/response1"
},
"400": {
"description": null,
"content": {
"application/json": {
"schema": {
Expand Down Expand Up @@ -648,7 +646,6 @@ public async Task SerializeOperationWithBodyAsV2JsonWorks()
"$ref": "#/responses/response1"
},
"400": {
"description": null,
"schema": {
"type": "number",
"maximum": 10,
Expand Down Expand Up @@ -718,7 +715,6 @@ public async Task SerializeAdvancedOperationWithTagAndSecurityAsV2JsonWorks()
"$ref": "#/responses/response1"
},
"400": {
"description": null,
"schema": {
"type": "number",
"maximum": 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ public async Task SerializeBasicResponseWorks(
string format)
{
// Arrange
var expected = format == OpenApiConstants.Json ? @"{
""description"": null
}" : @"description: null";
var expected = @"{ }";

// Act
var actual = await BasicResponse.SerializeAsync(version, format, TestContext.Current.CancellationToken);
Expand Down
Loading