99using FluentAssertions ;
1010using FluentAssertions . Equivalency ;
1111using Microsoft . OpenApi . Models ;
12+ using Microsoft . OpenApi . Extensions ;
1213using Microsoft . OpenApi . Models . Interfaces ;
1314using Microsoft . OpenApi . Reader ;
1415using Microsoft . OpenApi . Tests ;
@@ -31,7 +32,7 @@ public static MemoryStream GetMemoryStream(string fileName)
3132
3233 public OpenApiSchemaTests ( )
3334 {
34- OpenApiReaderRegistry . RegisterReader ( "yaml" , new OpenApiYamlReader ( ) ) ;
35+ OpenApiReaderRegistry . RegisterReader ( "yaml" , new OpenApiYamlReader ( ) ) ;
3536 }
3637
3738 [ Fact ]
@@ -298,8 +299,8 @@ public void CloningSchemaWithExamplesAndEnumsShouldSucceed()
298299 clone . Default = 6 ;
299300
300301 // Assert
301- Assert . Equivalent ( new int [ ] { 1 , 2 , 3 , 4 } , clone . Enum . Select ( static x => x . GetValue < int > ( ) ) . ToArray ( ) ) ;
302- Assert . Equivalent ( new int [ ] { 2 , 3 , 4 } , clone . Examples . Select ( static x => x . GetValue < int > ( ) ) . ToArray ( ) ) ;
302+ Assert . Equivalent ( new int [ ] { 1 , 2 , 3 , 4 } , clone . Enum . Select ( static x => x . GetValue < int > ( ) ) . ToArray ( ) ) ;
303+ Assert . Equivalent ( new int [ ] { 2 , 3 , 4 } , clone . Examples . Select ( static x => x . GetValue < int > ( ) ) . ToArray ( ) ) ;
303304 Assert . Equivalent ( 6 , clone . Default . GetValue < int > ( ) ) ;
304305 }
305306
@@ -398,7 +399,7 @@ public void SerializeSchemaWithTypeArrayAndNullableDoesntEmitType()
398399 schema . SerializeAsV2 ( new OpenApiYamlWriter ( writer ) ) ;
399400 var schemaString = writer . ToString ( ) ;
400401
401- Assert . Equal ( expected . MakeLineBreaksEnvironmentNeutral ( ) , schemaString . MakeLineBreaksEnvironmentNeutral ( ) ) ;
402+ Assert . Equal ( expected . MakeLineBreaksEnvironmentNeutral ( ) , schemaString . MakeLineBreaksEnvironmentNeutral ( ) ) ;
402403 }
403404
404405 [ Theory ]
@@ -506,7 +507,7 @@ public async Task ParseSchemaWithConstWorks()
506507 }
507508
508509 [ Fact ]
509- public void ParseSchemaWithUnrecognizedKeywordsWorks ( )
510+ public void ParseSchemaWithUnrecognizedKeywordsWorks ( )
510511 {
511512 var input = @"{
512513 ""type"": ""string"",
@@ -520,5 +521,36 @@ public void ParseSchemaWithUnrecognizedKeywordsWorks()
520521 Assert . Equal ( 2 , schema . UnrecognizedKeywords . Count ) ;
521522 }
522523
524+ [ Theory ]
525+ [ InlineData ( JsonSchemaType . Integer | JsonSchemaType . String , new [ ] { "integer" , "string" } ) ]
526+ [ InlineData ( JsonSchemaType . Integer | JsonSchemaType . Null , new [ ] { "integer" , "null" } ) ]
527+ [ InlineData ( JsonSchemaType . Integer , new [ ] { "integer" } ) ]
528+ public void NormalizeFlaggableJsonSchemaTypeEnumWorks ( JsonSchemaType type , string [ ] expected )
529+ {
530+ var schema = new OpenApiSchema
531+ {
532+ Type = type
533+ } ;
534+
535+ var actual = schema . Type . ToIdentifier ( ) ;
536+ Assert . Equal ( expected , actual ) ;
537+ }
538+
539+ [ Theory ]
540+ [ InlineData ( new [ ] { "integer" , "string" } , JsonSchemaType . Integer | JsonSchemaType . String ) ]
541+ [ InlineData ( new [ ] { "integer" , "null" } , JsonSchemaType . Integer | JsonSchemaType . Null ) ]
542+ [ InlineData ( new [ ] { "integer" } , JsonSchemaType . Integer ) ]
543+ public void ArrayIdentifierToEnumConversionWorks ( string [ ] type , JsonSchemaType expected )
544+ {
545+ var actual = type . ToJsonSchemaType ( ) ;
546+ Assert . Equal ( expected , actual ) ;
547+ }
548+
549+ [ Fact ]
550+ public void StringIdentifierToEnumConversionWorks ( )
551+ {
552+ var actual = "integer" . ToJsonSchemaType ( ) ;
553+ Assert . Equal ( JsonSchemaType . Integer , actual ) ;
554+ }
523555 }
524556}
0 commit comments