Skip to content

Commit d4eef1b

Browse files
committed
Add test
1 parent 78b65b5 commit d4eef1b

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
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
@@ -131,6 +131,9 @@
131131
<EmbeddedResource Include="V31Tests\Samples\OpenApiDocument\documentWithSummaryAndDescriptionInReference.yaml">
132132
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
133133
</EmbeddedResource>
134+
<EmbeddedResource Include="V31Tests\Samples\OpenApiDocument\docWithExample.yaml">
135+
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
136+
</EmbeddedResource>
134137
<EmbeddedResource Include="V3Tests\Samples\OpenApiDiscriminator\basicDiscriminator.yaml">
135138
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
136139
</EmbeddedResource>

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,5 +342,20 @@ public void ParseDocumentWithDescriptionInDollarRefsShouldSucceed()
342342
Assert.Equal(SchemaValueType.Object, schema.GetJsonType());
343343
Assert.Equal("A pet in a petstore", schema.GetDescription()); /*The reference object's description overrides that of the referenced component*/
344344
}
345+
346+
[Fact]
347+
public void ParseDocumentWithExampleInSchemaShouldSucceed()
348+
{
349+
// Arrange
350+
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "docWithExample.yaml"));
351+
var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture);
352+
var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = false });
353+
// Act
354+
var actual = new OpenApiStreamReader().Read(stream, out var diagnostic);
355+
actual.SerializeAsV31(writer);
356+
357+
// Assert
358+
Assert.NotNull(actual);
359+
}
345360
}
346361
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
openapi: 3.1.0 # The version of the OpenAPI Specification
2+
info: # Metadata about the API
3+
title: A simple OpenAPI 3.1 example
4+
version: 1.0.0
5+
license:
6+
name: Apache 2.0
7+
identifier: Apache-2.0 # The SPDX license identifier
8+
paths: # The available paths and operations for the API
9+
/echo: # A path for echoing messages using WebSockets
10+
get: # An operation using the GET method
11+
summary: Echo a message
12+
description: Send a message to the server and receive the same message back
13+
responses:
14+
'101':
15+
description: Switching Protocols
16+
headers:
17+
Upgrade:
18+
schema:
19+
type: string
20+
enum:
21+
- websocket
22+
Connection:
23+
schema:
24+
type: string
25+
enum:
26+
- Upgrade
27+
Sec-WebSocket-Accept:
28+
schema:
29+
type: string
30+
content: {} # No content is returned for this response
31+
servers:
32+
- url: ws://example.com # The WebSocket server URL
33+
/upload: # A path for uploading files using multipart/form-data
34+
post: # An operation using the POST method
35+
summary: Upload a file
36+
description: Upload a file to the server and receive a confirmation message
37+
requestBody:
38+
required: true
39+
content:
40+
multipart/form-data: # The media type for sending multiple parts of data
41+
schema:
42+
type: object
43+
properties:
44+
file: # A property for the file data
45+
type: string
46+
format: binary
47+
comment: # A property for the file comment
48+
type: string
49+
encoding: # The encoding for each part of data
50+
file:
51+
contentType: application/octet-stream # The media type for the file data
52+
comment:
53+
contentType: text/plain # The media type for the file comment
54+
responses:
55+
'200':
56+
description: File uploaded successfully
57+
content:
58+
application/json: # The media type for the response body
59+
schema:
60+
type: object
61+
properties:
62+
message: # A property for the confirmation message
63+
type: string
64+
example: File uploaded successfully
65+
components: # Reusable components for the API
66+
schemas: # JSON Schema definitions for the API
67+
User: # A schema for a user object
68+
$id: http://example.com/schemas/user # The identifier for the schema
69+
type: object
70+
properties:
71+
name: # A property for the user name
72+
type: string
73+
default: "John Doe" # The default value for the user name
74+
age: # A property for the user age
75+
type: integer
76+
minimum: 0
77+
default: 18 # The default value for the user age
78+
unevaluatedProperties: false # No additional properties are allowed
79+
Pet: # A schema for a pet object
80+
type: object
81+
required:
82+
- petType
83+
properties:
84+
petType: # A property for the pet type
85+
type: string
86+
discriminator: # The discriminator for resolving the concrete schema type
87+
propertyName: petType
88+
mapping:
89+
cat: '#/components/schemas/Cat'
90+
dog: '#/components/schemas/Dog'
91+
Cat: # A schema for a cat object
92+
allOf:
93+
- $ref: '#/components/schemas/Pet'
94+
- type: object
95+
properties:
96+
name: # A property for the cat name
97+
type: string
98+
default: "Fluffy" # The default value for the cat name
99+
Dog: # A schema for a dog object
100+
allOf:
101+
- $ref: '#/components/schemas/Pet'
102+
- type: object
103+
properties:
104+
bark: # A property for the dog bark
105+
type: string
106+
default: "Woof" # The default value for the dog bark

0 commit comments

Comments
 (0)