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 ;
@@ -810,18 +810,21 @@ private void SerializeTypeProperty(JsonSchemaType? type, IOpenApiWriter writer,
810
810
}
811
811
else
812
812
{
813
- var list = new List < JsonSchemaType > ( ) ;
814
- foreach ( JsonSchemaType flag in System . Enum . GetValues ( typeof ( JsonSchemaType ) ) )
813
+ if ( type is not null )
815
814
{
816
- if ( ( type & flag ) == flag )
815
+ var list = new List < JsonSchemaType ? > ( ) ;
816
+ foreach ( JsonSchemaType flag in System . Enum . GetValues ( typeof ( JsonSchemaType ) ) )
817
817
{
818
- list . Add ( flag ) ;
818
+ if ( type . Value . HasFlag ( flag ) )
819
+ {
820
+ list . Add ( flag ) ;
821
+ }
819
822
}
820
- }
821
-
822
- writer . WriteOptionalCollection ( OpenApiConstants . Type , list , ( w , s ) => w . WriteValue ( OpenApiTypeMapper . ToIdentifier ( s ) ) ) ;
823
+
824
+ writer . WriteOptionalCollection ( OpenApiConstants . Type , list , ( w , s ) => w . WriteValue ( s . ToIdentifier ( ) ) ) ;
825
+ }
823
826
}
824
- }
827
+ }
825
828
}
826
829
827
830
private static int CountEnumSetFlags ( JsonSchemaType ? schemaType )
@@ -834,7 +837,7 @@ private static int CountEnumSetFlags(JsonSchemaType? schemaType)
834
837
foreach ( JsonSchemaType value in System . Enum . GetValues ( typeof ( JsonSchemaType ) ) )
835
838
{
836
839
// Ignore the None flag and check if the flag is set
837
- if ( ( schemaType . Value . HasFlag ( value ) )
840
+ if ( schemaType . Value . HasFlag ( value ) )
838
841
{
839
842
count ++ ;
840
843
}
@@ -849,12 +852,12 @@ private void UpCastSchemaTypeToV31(JsonSchemaType? type, IOpenApiWriter writer)
849
852
// create a new array and insert the type and "null" as values
850
853
Type = type | JsonSchemaType . Null ;
851
854
var list = new List < string > ( ) ;
852
- foreach ( JsonSchemaType flag in System . Enum . GetValues ( typeof ( JsonSchemaType ) ) )
855
+ foreach ( JsonSchemaType ? flag in System . Enum . GetValues ( typeof ( JsonSchemaType ) ) )
853
856
{
854
857
// Check if the flag is set in 'type' using a bitwise AND operation
855
- if ( ( Type & flag ) == flag )
858
+ if ( Type . Value . HasFlag ( flag ) )
856
859
{
857
- list . Add ( OpenApiTypeMapper . ToIdentifier ( flag ) ) ;
860
+ list . Add ( flag . ToIdentifier ( ) ) ;
858
861
}
859
862
}
860
863
@@ -881,18 +884,18 @@ private void DowncastTypeArrayToV2OrV3(JsonSchemaType? schemaType, IOpenApiWrite
881
884
}
882
885
else
883
886
{
884
- writer . WriteProperty ( OpenApiConstants . Type , OpenApiTypeMapper . ToIdentifier ( schemaType ) ) ;
887
+ writer . WriteProperty ( OpenApiConstants . Type , schemaType . ToIdentifier ( ) ) ;
885
888
}
886
889
}
887
890
else if ( flagsCount is 2 && ( schemaType & JsonSchemaType . Null ) == JsonSchemaType . Null ) // checks for two values and one is null
888
891
{
889
- foreach ( JsonSchemaType flag in System . Enum . GetValues ( typeof ( JsonSchemaType ) ) )
892
+ foreach ( JsonSchemaType ? flag in System . Enum . GetValues ( typeof ( JsonSchemaType ) ) )
890
893
{
891
894
// Skip if the flag is not set or if it's the Null flag
892
- if ( ( schemaType & flag ) == flag && flag != JsonSchemaType . Null )
895
+ if ( schemaType . Value . HasFlag ( flag ) && flag != JsonSchemaType . Null )
893
896
{
894
897
// Write the non-null flag value to the writer
895
- writer . WriteProperty ( OpenApiConstants . Type , OpenApiTypeMapper . ToIdentifier ( flag ) ) ;
898
+ writer . WriteProperty ( OpenApiConstants . Type , flag . ToIdentifier ( ) ) ;
896
899
}
897
900
}
898
901
if ( ! Nullable )
0 commit comments