Skip to content

Commit fefec09

Browse files
committed
test: adds tests for 30 deserialization of path items with extra ops
Signed-off-by: Vincent Biret <[email protected]>
1 parent 30227ef commit fefec09

File tree

2 files changed

+81
-34
lines changed

2 files changed

+81
-34
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System.Collections.Generic;
5+
using System.Net.Http;
6+
using System.Text.Json.Nodes;
7+
using System.Threading.Tasks;
8+
using Xunit;
9+
10+
namespace Microsoft.OpenApi.Readers.Tests.V3Tests;
11+
12+
public class OpenApiPathItemDeserializerTests
13+
{
14+
private const string SampleFolderPath = "V3Tests/Samples/OpenApiPathItem/";
15+
16+
[Fact]
17+
public async Task ExtraneousOperationsAreParsedAsExtensionsIn30()
18+
{
19+
// Arrange & Act
20+
var result = await OpenApiDocument.LoadAsync($"{SampleFolderPath}pathItemWithQueryAndAdditionalOperations.yaml", SettingsFixture.ReaderSettings);
21+
var pathItem = result.Document.Paths["/pets"];
22+
23+
// Assert
24+
Assert.Equal("Pet operations", pathItem.Summary);
25+
Assert.Equal("Operations available for pets", pathItem.Description);
26+
27+
// Regular operations
28+
var getOp = Assert.Contains(HttpMethod.Get, pathItem.Operations);
29+
Assert.Equal("getPets", getOp.OperationId);
30+
31+
var postOp = Assert.Contains(HttpMethod.Post, pathItem.Operations);
32+
Assert.Equal("createPet", postOp.OperationId);
33+
34+
// Query operation should now be on one of the operations
35+
// Since the YAML structure changed, we need to check which operation has the query
36+
Assert.DoesNotContain(new HttpMethod("Query"), pathItem.Operations);
37+
Assert.DoesNotContain(new HttpMethod("notify"), pathItem.Operations);
38+
Assert.DoesNotContain(new HttpMethod("subscribe"), pathItem.Operations);
39+
40+
var additionalPathsExt = Assert.IsType<JsonNodeExtension>(Assert.Contains("x-oai-additionalOperations", pathItem.Extensions));
41+
42+
var additionalOpsNode = Assert.IsType<JsonObject>(additionalPathsExt.Node);
43+
Assert.Contains("query", additionalOpsNode);
44+
Assert.Contains("notify", additionalOpsNode);
45+
Assert.Contains("subscribe", additionalOpsNode);
46+
}
47+
}

test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiPathItem/pathItemWithQueryAndAdditionalOperations.yaml

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ paths:
1212
responses:
1313
'200':
1414
description: List of pets
15-
x-oai-additionalOperations:
16-
query:
15+
x-oai-additionalOperations:
16+
query:
1717
summary: Query pets with complex filters
1818
operationId: queryPets
1919
parameters:
@@ -31,44 +31,44 @@ paths:
3131
type: array
3232
items:
3333
type: object
34-
notify:
35-
summary: Notify about pet updates
36-
operationId: notifyPetUpdates
37-
requestBody:
38-
required: true
34+
notify:
35+
summary: Notify about pet updates
36+
operationId: notifyPetUpdates
37+
requestBody:
38+
required: true
39+
content:
40+
application/json:
41+
schema:
42+
type: object
43+
properties:
44+
petId:
45+
type: string
46+
event:
47+
type: string
48+
responses:
49+
'200':
50+
description: Notification sent
51+
subscribe:
52+
summary: Subscribe to pet events
53+
operationId: subscribePetEvents
54+
parameters:
55+
- name: events
56+
in: query
57+
description: Event types to subscribe to
58+
schema:
59+
type: array
60+
items:
61+
type: string
62+
responses:
63+
'200':
64+
description: Subscription created
3965
content:
4066
application/json:
4167
schema:
4268
type: object
4369
properties:
44-
petId:
70+
subscriptionId:
4571
type: string
46-
event:
47-
type: string
48-
responses:
49-
'200':
50-
description: Notification sent
51-
subscribe:
52-
summary: Subscribe to pet events
53-
operationId: subscribePetEvents
54-
parameters:
55-
- name: events
56-
in: query
57-
description: Event types to subscribe to
58-
schema:
59-
type: array
60-
items:
61-
type: string
62-
responses:
63-
'200':
64-
description: Subscription created
65-
content:
66-
application/json:
67-
schema:
68-
type: object
69-
properties:
70-
subscriptionId:
71-
type: string
7272
post:
7373
summary: Create pet
7474
operationId: createPet

0 commit comments

Comments
 (0)