Skip to content

Commit e41b927

Browse files
committed
Add test to validate that a V2 doc with x-examples gets mapped to MediaType Examples object when upcasting to V3
1 parent 61d50b5 commit e41b927

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.OpenApi.Models;
1212
using Microsoft.OpenApi.Readers.ParseNodes;
1313
using Microsoft.OpenApi.Readers.V2;
14+
using Microsoft.OpenApi.Tests;
1415
using Xunit;
1516

1617
namespace Microsoft.OpenApi.Readers.Tests.V2Tests
@@ -434,5 +435,56 @@ public void ParseOperationWithBodyAndEmptyConsumesSetsRequestBodySchemaIfExists(
434435
// Assert
435436
operation.Should().BeEquivalentTo(_operationWithBody);
436437
}
438+
439+
[Fact]
440+
public void ParseV2ResponseWithExamplesExtensionWorks()
441+
{
442+
// Arrange
443+
MapNode node;
444+
using (var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "opWithResponseExamplesExtension.yaml")))
445+
{
446+
node = TestHelper.CreateYamlMapNode(stream);
447+
}
448+
449+
// Act
450+
var operation = OpenApiV2Deserializer.LoadOperation(node);
451+
var actual = operation.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
452+
453+
// Assert
454+
var expected = @"summary: Get all pets
455+
responses:
456+
'200':
457+
description: Successful response
458+
content:
459+
application/json:
460+
schema:
461+
type: array
462+
items:
463+
type: object
464+
properties:
465+
name:
466+
type: string
467+
age:
468+
type: integer
469+
examples:
470+
example1:
471+
summary: Example - List of Pets
472+
value:
473+
- name: Buddy
474+
age: 2
475+
- name: Whiskers
476+
age: 1
477+
example2:
478+
summary: Example - Playful Cat
479+
value:
480+
name: Whiskers
481+
age: 1";
482+
483+
// Assert
484+
actual = actual.MakeLineBreaksEnvironmentNeutral();
485+
expected = expected.MakeLineBreaksEnvironmentNeutral();
486+
actual.Should().Be(expected);
487+
//Assert.Equal(expected, actual);
488+
}
437489
}
438490
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
summary: Get all pets
2+
produces:
3+
- application/json
4+
responses:
5+
'200':
6+
description: Successful response
7+
schema:
8+
type: array
9+
items:
10+
type: object
11+
properties:
12+
name:
13+
type: string
14+
age:
15+
type: integer
16+
x-examples:
17+
example1:
18+
summary: Example - List of Pets
19+
value:
20+
- name: "Buddy"
21+
age: 2
22+
- name: "Whiskers"
23+
age: 1
24+
example2:
25+
summary: Example - Playful Cat
26+
value:
27+
name: "Whiskers"
28+
age: 1

0 commit comments

Comments
 (0)