Skip to content

Commit 3dbe5d8

Browse files
committed
Fixed reading v2 with path parameter that is a body
1 parent ddee0b2 commit 3dbe5d8

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
</PropertyGroup>
1515
<ItemGroup>
1616
<None Remove="V2Tests\Samples\ComponentRootReference.json" />
17+
<None Remove="V2Tests\Samples\OpenApiPathItem\pathItemWithBodyPathParameter.yaml" />
1718
<None Remove="V2Tests\Samples\OpenApiPathItem\pathItemWithFormDataPathParameter.yaml" />
1819
<None Remove="V3Tests\Samples\OpenApiWorkspace\TodoComponents.yaml" />
1920
<None Remove="V3Tests\Samples\OpenApiWorkspace\TodoMain.yaml" />
@@ -89,6 +90,9 @@
8990
<EmbeddedResource Include="V2Tests\Samples\OpenApiPathItem\pathItemWithFormDataPathParameter.yaml">
9091
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
9192
</EmbeddedResource>
93+
<EmbeddedResource Include="V2Tests\Samples\OpenApiPathItem\pathItemWithBodyPathParameter.yaml">
94+
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
95+
</EmbeddedResource>
9296
<EmbeddedResource Include="V2Tests\Samples\OpenApiPathItem\basicPathItemWithFormData.yaml">
9397
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
9498
</EmbeddedResource>

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,29 @@ public void ParsePathItemWithFormDataPathParameterShouldSucceed()
275275

276276
// Assert
277277
// FormData parameters at in the path level are pushed into Operation request bodies.
278-
Assert.True(pathItem.Operations.All(o => o.Value.RequestBody != null));
278+
Assert.True(pathItem.Operations[OperationType.Put].RequestBody != null);
279+
Assert.True(pathItem.Operations[OperationType.Post].RequestBody != null);
280+
Assert.Equal(2, pathItem.Operations.Count(o => o.Value.RequestBody != null));
279281
}
282+
[Fact]
283+
public void ParsePathItemBodyDataPathParameterShouldSucceed()
284+
{
285+
// Arrange
286+
MapNode node;
287+
using (var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "pathItemWithBodyPathParameter.yaml")))
288+
{
289+
node = TestHelper.CreateYamlMapNode(stream);
290+
}
291+
292+
// Act
293+
var pathItem = OpenApiV2Deserializer.LoadPathItem(node);
294+
295+
// Assert
296+
// FormData parameters at in the path level are pushed into Operation request bodies.
297+
Assert.True(pathItem.Operations[OperationType.Put].RequestBody != null);
298+
Assert.True(pathItem.Operations[OperationType.Post].RequestBody != null);
299+
Assert.Equal(2, pathItem.Operations.Count(o => o.Value.RequestBody != null));
300+
}
301+
280302
}
281303
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
put:
2+
summary: Puts a pet in the store with form data
3+
description: ""
4+
responses:
5+
'200':
6+
description: Pet updated.
7+
'405':
8+
description: Invalid input
9+
post:
10+
summary: Posts a pet in the store with form data
11+
description: ""
12+
responses:
13+
'200':
14+
description: Pet updated.
15+
parameters:
16+
- name: petId
17+
in: path
18+
description: ID of pet that needs to be updated
19+
required: true
20+
schema:
21+
type: string
22+
- name: name
23+
in: body
24+
description: Updated pet body
25+
required: true
26+
type: object
27+
properties:
28+
name:
29+
type: string
30+
status:
31+
type: string

0 commit comments

Comments
 (0)