File tree Expand file tree Collapse file tree 3 files changed +51
-6
lines changed
test/Microsoft.OpenApi.Tests/Models Expand file tree Collapse file tree 3 files changed +51
-6
lines changed Original file line number Diff line number Diff line change 1111 <Company >Microsoft</Company >
1212 <Title >Microsoft.OpenApi</Title >
1313 <PackageId >Microsoft.OpenApi</PackageId >
14- <Version >1.4.0 </Version >
14+ <Version >1.4.1 </Version >
1515 <Description >.NET models with JSON and YAML writers for OpenAPI specification</Description >
1616 <Copyright >© Microsoft Corporation. All rights reserved.</Copyright >
1717 <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.
22// Licensed under the MIT license.
33
44using System . Collections . Generic ;
@@ -566,6 +566,13 @@ internal void WriteAsItemsProperties(IOpenApiWriter writer)
566566 writer . WriteProperty ( OpenApiConstants . Type , Type ) ;
567567
568568 // 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+
569576 writer . WriteProperty ( OpenApiConstants . Format , Format ) ;
570577
571578 // items
@@ -630,9 +637,12 @@ internal void WriteAsSchemaProperties(
630637 }
631638
632639 // 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+ }
636646
637647 writer . WriteProperty ( OpenApiConstants . Format , Format ) ;
638648
Original file line number Diff line number Diff line change @@ -50,7 +50,12 @@ public class OpenApiParameterTests
5050 Schema = new OpenApiSchema
5151 {
5252 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+ }
5459 } ,
5560 Examples = new Dictionary < string , OpenApiExample >
5661 {
@@ -234,6 +239,15 @@ public void SerializeAdvancedParameterAsV3JsonWorks()
234239 ""explode"": true,
235240 ""schema"": {
236241 ""title"": ""title2"",
242+ ""oneOf"": [
243+ {
244+ ""type"": ""number"",
245+ ""format"": ""double""
246+ },
247+ {
248+ ""type"": ""string""
249+ }
250+ ],
237251 ""description"": ""description2""
238252 },
239253 ""examples"": {
@@ -253,6 +267,27 @@ public void SerializeAdvancedParameterAsV3JsonWorks()
253267 actual . Should ( ) . Be ( expected ) ;
254268 }
255269
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+
256291 [ Theory ]
257292 [ InlineData ( true ) ]
258293 [ InlineData ( false ) ]
You can’t perform that action at this time.
0 commit comments