44using System . Collections . Generic ;
55using System . Globalization ;
66using System . IO ;
7- using System . Linq ;
87using System . Threading ;
98using FluentAssertions ;
109using 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 } ) ;
0 commit comments