Skip to content

Commit 66c3e5c

Browse files
committed
Add test to verify request body schema is set when consumes is an empty array
1 parent 6a7993e commit 66c3e5c

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
<EmbeddedResource Include="V2Tests\Samples\OpenApiOperation\operationWithBody.yaml">
5252
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
5353
</EmbeddedResource>
54+
<EmbeddedResource Include="V2Tests\Samples\OpenApiOperation\operationWithBodyAndEmptyConsumes.yaml">
55+
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
56+
</EmbeddedResource>
5457
<EmbeddedResource Include="V2Tests\Samples\OpenApiOperation\operationWithFormData.yaml">
5558
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
5659
</EmbeddedResource>

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System.Collections.Generic;
@@ -417,5 +417,20 @@ public void ParseOperationWithEmptyProducesArraySetsResponseSchemaIfExists()
417417
}
418418
);
419419
}
420+
421+
[Fact]
422+
public void ParseOperationWithBodyAndEmptyConsumesSetsRequestBodySchemaIfExists()
423+
{
424+
// Arrange
425+
MapNode node;
426+
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "operationWithBodyAndEmptyConsumes.yaml"));
427+
node = TestHelper.CreateYamlMapNode(stream);
428+
429+
// Act
430+
var operation = OpenApiV2Deserializer.LoadOperation(node);
431+
432+
// Assert
433+
operation.Should().BeEquivalentTo(_operationWithBody);
434+
}
420435
}
421436
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Modified from https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#operation-object-example
2+
summary: Updates a pet in the store with request body
3+
description: ""
4+
operationId: updatePetWithBody
5+
consumes: []
6+
produces:
7+
- application/json
8+
- application/xml
9+
parameters:
10+
- name: petId
11+
in: path
12+
description: ID of pet that needs to be updated
13+
required: true
14+
type: string
15+
- name: petObject
16+
in: body
17+
description: Pet to update with
18+
required: true
19+
schema:
20+
type: object
21+
responses:
22+
'200':
23+
description: Pet updated.
24+
'405':
25+
description: Invalid input

0 commit comments

Comments
 (0)