Skip to content

Commit bc9c3d5

Browse files
PR fixed
1 parent 601ebf7 commit bc9c3d5

File tree

3 files changed

+54
-9
lines changed

3 files changed

+54
-9
lines changed

src/Microsoft.OpenApi.Readers/V2/OpenApiResponseDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private static void ProcessProduces(MapNode mapNode, OpenApiResponse response, P
7070
response.Content = new Dictionary<string, OpenApiMediaType>();
7171
}
7272

73-
if (produces != null && produces.Count > 0)
73+
if (produces != null)
7474
{
7575
foreach (var produce in produces)
7676
{

test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
<SignAssembly>true</SignAssembly>
1313
<AssemblyOriginatorKeyFile>..\..\src\Microsoft.OpenApi.snk</AssemblyOriginatorKeyFile>
1414
</PropertyGroup>
15-
<ItemGroup>
16-
<None Remove="V2Tests\Samples\multipleProduces.json" />
17-
</ItemGroup>
1815
<ItemGroup>
1916
<EmbeddedResource Include="OpenApiReaderTests\Samples\unsupported.v1.yaml">
2017
<CopyToOutputDirectory>Never</CopyToOutputDirectory>

test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,64 @@ public void ShouldAssignSchemaToAllResponses()
252252

253253
Assert.Equal(OpenApiSpecVersion.OpenApi2_0, diagnostic.SpecificationVersion);
254254

255+
var successSchema = new OpenApiSchema
256+
{
257+
Type = "array",
258+
Items = new OpenApiSchema
259+
{
260+
Properties = {
261+
{ "id", new OpenApiSchema
262+
{
263+
Type = "string",
264+
Description = "Item identifier."
265+
}
266+
}
267+
},
268+
Reference = new OpenApiReference
269+
{
270+
Id = "Item",
271+
Type = ReferenceType.Schema
272+
}
273+
}
274+
};
275+
var errorSchema = new OpenApiSchema
276+
{
277+
Properties = {
278+
{ "code", new OpenApiSchema
279+
{
280+
Type = "integer",
281+
Format = "int32"
282+
}
283+
},
284+
{ "message", new OpenApiSchema
285+
{
286+
Type = "string"
287+
}
288+
},
289+
{ "fields", new OpenApiSchema
290+
{
291+
Type = "string"
292+
}
293+
}
294+
},
295+
Reference = new OpenApiReference
296+
{
297+
Id = "Error",
298+
Type = ReferenceType.Schema
299+
}
300+
};
255301
var responses = document.Paths["/items"].Operations[OperationType.Get].Responses;
256-
foreach (var content in responses.Values.Select(r => r.Content))
302+
foreach (var response in responses)
257303
{
258-
var json = content["application/json"];
304+
var targetSchema = response.Key == "200" ? successSchema : errorSchema;
305+
306+
var json = response.Value.Content["application/json"];
259307
Assert.NotNull(json);
260-
Assert.NotNull(json.Schema);
308+
json.Schema.ShouldBeEquivalentTo(targetSchema);
261309

262-
var xml = content["application/xml"];
310+
var xml = response.Value.Content["application/xml"];
263311
Assert.NotNull(xml);
264-
Assert.NotNull(xml.Schema);
312+
xml.Schema.ShouldBeEquivalentTo(targetSchema);
265313
}
266314
}
267315
}

0 commit comments

Comments
 (0)