@@ -306,6 +306,69 @@ public void When_using_MultipleClientsFromOperationId_then_ensure_that_underscor
306
306
Assert . Equal ( expectedClientName , clientName ) ;
307
307
}
308
308
309
+ [ Fact ]
310
+ public void When_Success_Response_contains_multiple_content_types_prioritizes_wildcard ( )
311
+ {
312
+ // Arrange
313
+ var document = CreateDocument ( ) ;
314
+ var operation = document . Paths [ "/Person" ] [ OpenApiOperationMethod . Get ] ;
315
+
316
+ operation . Responses [ "200" ] . Content . Clear ( ) ;
317
+
318
+ operation . Responses [ "200" ] . Content . Add ( "application/xml" , new OpenApiMediaType
319
+ {
320
+ Schema = new JsonSchema { Type = JsonObjectType . Object }
321
+ } ) ;
322
+
323
+ operation . Responses [ "200" ] . Content . Add ( "application/json" , new OpenApiMediaType
324
+ {
325
+ Schema = new JsonSchema { Type = JsonObjectType . Object }
326
+ } ) ;
327
+
328
+ operation . Responses [ "200" ] . Content . Add ( "*/*" , new OpenApiMediaType
329
+ {
330
+ Schema = new JsonSchema { Type = JsonObjectType . Object }
331
+ } ) ;
332
+
333
+ // Act
334
+ var settings = new CSharpClientGeneratorSettings ( ) ;
335
+ settings . CSharpGeneratorSettings . JsonLibrary = NJsonSchema . CodeGeneration . CSharp . CSharpJsonLibrary . SystemTextJson ;
336
+ var generator = new CSharpClientGenerator ( document , settings ) ;
337
+ var code = generator . GenerateFile ( ) ;
338
+
339
+ // Assert
340
+ Assert . Contains ( "Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse(\" */*\" ));" , code ) ;
341
+ }
342
+
343
+ [ Fact ]
344
+ public void When_Success_Response_contains_multiple_content_types_prioritizes_json ( )
345
+ {
346
+ // Arrange
347
+ var document = CreateDocument ( ) ;
348
+ var operation = document . Paths [ "/Person" ] [ OpenApiOperationMethod . Get ] ;
349
+
350
+ operation . Responses [ "200" ] . Content . Clear ( ) ;
351
+
352
+ operation . Responses [ "200" ] . Content . Add ( "application/xml" , new OpenApiMediaType
353
+ {
354
+ Schema = new JsonSchema { Type = JsonObjectType . Object }
355
+ } ) ;
356
+
357
+ operation . Responses [ "200" ] . Content . Add ( "application/json" , new OpenApiMediaType
358
+ {
359
+ Schema = new JsonSchema { Type = JsonObjectType . Object }
360
+ } ) ;
361
+
362
+ // Act
363
+ var settings = new CSharpClientGeneratorSettings ( ) ;
364
+ settings . CSharpGeneratorSettings . JsonLibrary = NJsonSchema . CodeGeneration . CSharp . CSharpJsonLibrary . SystemTextJson ;
365
+ var generator = new CSharpClientGenerator ( document , settings ) ;
366
+ var code = generator . GenerateFile ( ) ;
367
+
368
+ // Assert
369
+ Assert . Contains ( "Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse(\" application/json\" ));" , code ) ;
370
+ }
371
+
309
372
private static OpenApiDocument CreateDocument ( )
310
373
{
311
374
var document = new OpenApiDocument ( ) ;
0 commit comments