Skip to content

Commit f0a2eb0

Browse files
two responses test extended
1 parent bc9c3d5 commit f0a2eb0

File tree

2 files changed

+62
-50
lines changed

2 files changed

+62
-50
lines changed

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

Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Collections.Generic;
55
using System.Globalization;
66
using System.IO;
7-
using System.Linq;
87
using System.Threading;
98
using FluentAssertions;
109
using Microsoft.OpenApi.Any;
@@ -159,25 +158,12 @@ public void ShouldParseProducesInAnyOrder()
159158
Assert.NotNull(doc.Paths["/items"]);
160159
Assert.Equal(3, doc.Paths["/items"].Operations.Count);
161160

162-
foreach (var operation in doc.Paths["/items"].Operations)
161+
var successSchema = new OpenApiSchema()
163162
{
164-
Assert.Equal(2, operation.Value.Responses.Count);
165-
166-
var okResponse = operation.Value.Responses["200"];
167-
okResponse.ShouldBeEquivalentTo(
168-
new OpenApiResponse()
169-
{
170-
Description = "An OK response",
171-
Content =
172-
{
173-
["application/json"] = new OpenApiMediaType()
174-
{
175-
Schema = new OpenApiSchema()
176-
{
177-
Type = "array",
178-
Items = new OpenApiSchema()
179-
{
180-
Properties = new Dictionary<string, OpenApiSchema>()
163+
Type = "array",
164+
Items = new OpenApiSchema()
165+
{
166+
Properties = new Dictionary<string, OpenApiSchema>()
181167
{
182168
{ "id", new OpenApiSchema()
183169
{
@@ -186,29 +172,16 @@ public void ShouldParseProducesInAnyOrder()
186172
}
187173
}
188174
},
189-
Reference = new OpenApiReference()
190-
{
191-
Type = ReferenceType.Schema,
192-
Id = "Item"
193-
}
194-
}
195-
},
196-
}
197-
}
198-
});
199-
200-
var errorResponse = operation.Value.Responses["default"];
201-
errorResponse.ShouldBeEquivalentTo(
202-
new OpenApiResponse()
175+
Reference = new OpenApiReference()
203176
{
204-
Description = "An error response",
205-
Content =
206-
{
207-
["application/json"] = new OpenApiMediaType()
208-
{
209-
Schema = new OpenApiSchema()
210-
{
211-
Properties = new Dictionary<string, OpenApiSchema>()
177+
Type = ReferenceType.Schema,
178+
Id = "Item"
179+
}
180+
}
181+
};
182+
var errorSchema = new OpenApiSchema()
183+
{
184+
Properties = new Dictionary<string, OpenApiSchema>()
212185
{
213186
{ "code", new OpenApiSchema()
214187
{
@@ -227,12 +200,48 @@ public void ShouldParseProducesInAnyOrder()
227200
}
228201
}
229202
},
230-
Reference = new OpenApiReference()
231-
{
232-
Type = ReferenceType.Schema,
233-
Id = "Error"
234-
}
235-
},
203+
Reference = new OpenApiReference()
204+
{
205+
Type = ReferenceType.Schema,
206+
Id = "Error"
207+
}
208+
};
209+
foreach (var operation in doc.Paths["/items"].Operations)
210+
{
211+
Assert.Equal(2, operation.Value.Responses.Count);
212+
213+
var okResponse = operation.Value.Responses["200"];
214+
okResponse.ShouldBeEquivalentTo(
215+
new OpenApiResponse()
216+
{
217+
Description = "An OK response",
218+
Content =
219+
{
220+
["application/json"] = new OpenApiMediaType()
221+
{
222+
Schema = successSchema,
223+
},
224+
["application/xml"] = new OpenApiMediaType()
225+
{
226+
Schema = successSchema,
227+
}
228+
}
229+
});
230+
231+
var errorResponse = operation.Value.Responses["default"];
232+
errorResponse.ShouldBeEquivalentTo(
233+
new OpenApiResponse()
234+
{
235+
Description = "An error response",
236+
Content =
237+
{
238+
["application/json"] = new OpenApiMediaType()
239+
{
240+
Schema = errorSchema,
241+
},
242+
["application/xml"] = new OpenApiMediaType()
243+
{
244+
Schema = errorSchema,
236245
}
237246
}
238247
});

test/Microsoft.OpenApi.Readers.Tests/V2Tests/Samples/twoResponses.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"/items": {
1313
"get": {
1414
"produces": [
15-
"application/json"
15+
"application/json",
16+
"application/xml"
1617
],
1718
"responses": {
1819
"200": {
@@ -70,13 +71,15 @@
7071
}
7172
},
7273
"produces": [
73-
"application/json"
74+
"application/json",
75+
"application/xml"
7476
]
7577
}
7678
}
7779
},
7880
"produces": [
79-
"application/json"
81+
"application/json",
82+
"application/xml"
8083
],
8184
"definitions": {
8285
"Item": {

0 commit comments

Comments
 (0)