File tree 3 files changed +51
-6
lines changed
test/Microsoft.OpenApi.Tests/Models
3 files changed +51
-6
lines changed Original file line number Diff line number Diff line change 11
11
<Company >Microsoft</Company >
12
12
<Title >Microsoft.OpenApi</Title >
13
13
<PackageId >Microsoft.OpenApi</PackageId >
14
- <Version >1.4.0 </Version >
14
+ <Version >1.4.1 </Version >
15
15
<Description >.NET models with JSON and YAML writers for OpenAPI specification</Description >
16
16
<Copyright >© Microsoft Corporation. All rights reserved.</Copyright >
17
17
<PackageTags >OpenAPI .NET</PackageTags >
Original file line number Diff line number Diff line change 1
- // Copyright (c) Microsoft Corporation. All rights reserved.
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT license.
3
3
4
4
using System . Collections . Generic ;
@@ -566,6 +566,13 @@ internal void WriteAsItemsProperties(IOpenApiWriter writer)
566
566
writer . WriteProperty ( OpenApiConstants . Type , Type ) ;
567
567
568
568
// format
569
+ if ( string . IsNullOrEmpty ( Format ) )
570
+ {
571
+ Format = AllOf ? . FirstOrDefault ( static x => ! string . IsNullOrEmpty ( x . Format ) ) ? . Format ??
572
+ AnyOf ? . FirstOrDefault ( static x => ! string . IsNullOrEmpty ( x . Format ) ) ? . Format ??
573
+ OneOf ? . FirstOrDefault ( static x => ! string . IsNullOrEmpty ( x . Format ) ) ? . Format ;
574
+ }
575
+
569
576
writer . WriteProperty ( OpenApiConstants . Format , Format ) ;
570
577
571
578
// items
@@ -630,9 +637,12 @@ internal void WriteAsSchemaProperties(
630
637
}
631
638
632
639
// format
633
- Format ??= AllOf ? . FirstOrDefault ( static x => x . Format != null ) ? . Format ??
634
- AnyOf ? . FirstOrDefault ( static x => x . Format != null ) ? . Format ??
635
- OneOf ? . FirstOrDefault ( static x => x . Format != null ) ? . Format ;
640
+ if ( string . IsNullOrEmpty ( Format ) )
641
+ {
642
+ Format = AllOf ? . FirstOrDefault ( static x => ! string . IsNullOrEmpty ( x . Format ) ) ? . Format ??
643
+ AnyOf ? . FirstOrDefault ( static x => ! string . IsNullOrEmpty ( x . Format ) ) ? . Format ??
644
+ OneOf ? . FirstOrDefault ( static x => ! string . IsNullOrEmpty ( x . Format ) ) ? . Format ;
645
+ }
636
646
637
647
writer . WriteProperty ( OpenApiConstants . Format , Format ) ;
638
648
Original file line number Diff line number Diff line change @@ -50,7 +50,12 @@ public class OpenApiParameterTests
50
50
Schema = new OpenApiSchema
51
51
{
52
52
Title = "title2" ,
53
- Description = "description2"
53
+ Description = "description2" ,
54
+ OneOf = new List < OpenApiSchema >
55
+ {
56
+ new OpenApiSchema { Type = "number" , Format = "double" } ,
57
+ new OpenApiSchema { Type = "string" }
58
+ }
54
59
} ,
55
60
Examples = new Dictionary < string , OpenApiExample >
56
61
{
@@ -234,6 +239,15 @@ public void SerializeAdvancedParameterAsV3JsonWorks()
234
239
""explode"": true,
235
240
""schema"": {
236
241
""title"": ""title2"",
242
+ ""oneOf"": [
243
+ {
244
+ ""type"": ""number"",
245
+ ""format"": ""double""
246
+ },
247
+ {
248
+ ""type"": ""string""
249
+ }
250
+ ],
237
251
""description"": ""description2""
238
252
},
239
253
""examples"": {
@@ -253,6 +267,27 @@ public void SerializeAdvancedParameterAsV3JsonWorks()
253
267
actual . Should ( ) . Be ( expected ) ;
254
268
}
255
269
270
+ [ Fact ]
271
+ public void SerializeAdvancedParameterAsV2JsonWorks ( )
272
+ {
273
+ // Arrange
274
+ var expected = @"{
275
+ ""in"": ""path"",
276
+ ""name"": ""name1"",
277
+ ""description"": ""description1"",
278
+ ""required"": true,
279
+ ""format"": ""double""
280
+ }" ;
281
+
282
+ // Act
283
+ var actual = AdvancedPathParameterWithSchema . SerializeAsJson ( OpenApiSpecVersion . OpenApi2_0 ) ;
284
+
285
+ // Assert
286
+ actual = actual . MakeLineBreaksEnvironmentNeutral ( ) ;
287
+ expected = expected . MakeLineBreaksEnvironmentNeutral ( ) ;
288
+ actual . Should ( ) . Be ( expected ) ;
289
+ }
290
+
256
291
[ Theory ]
257
292
[ InlineData ( true ) ]
258
293
[ InlineData ( false ) ]
You can’t perform that action at this time.
0 commit comments