@@ -87,19 +87,19 @@ public static JsonSchemaType ToJsonSchemaType(this string identifier)
8787 [ typeof ( char ) ] = ( ) => new ( ) { Type = JsonSchemaType . String } ,
8888
8989 // Nullable types
90- [ typeof ( bool ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . Boolean , Nullable = true } ,
91- [ typeof ( byte ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . String , Format = "byte" , Nullable = true } ,
92- [ typeof ( int ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . Integer , Format = "int32" , Nullable = true } ,
93- [ typeof ( uint ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . Integer , Format = "int32" , Nullable = true } ,
94- [ typeof ( long ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . Integer , Format = "int64" , Nullable = true } ,
95- [ typeof ( ulong ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . Integer , Format = "int64" , Nullable = true } ,
96- [ typeof ( float ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . Number , Format = "float" , Nullable = true } ,
97- [ typeof ( double ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . Number , Format = "double" , Nullable = true } ,
98- [ typeof ( decimal ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . Number , Format = "double" , Nullable = true } ,
99- [ typeof ( DateTime ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . String , Format = "date-time" , Nullable = true } ,
100- [ typeof ( DateTimeOffset ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . String , Format = "date-time" , Nullable = true } ,
101- [ typeof ( Guid ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . String , Format = "uuid" , Nullable = true } ,
102- [ typeof ( char ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . String , Nullable = true } ,
90+ [ typeof ( bool ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . Boolean | JsonSchemaType . Null } ,
91+ [ typeof ( byte ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . String | JsonSchemaType . Null , Format = "byte" } ,
92+ [ typeof ( int ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . Integer | JsonSchemaType . Null , Format = "int32" } ,
93+ [ typeof ( uint ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . Integer | JsonSchemaType . Null , Format = "int32" } ,
94+ [ typeof ( long ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . Integer | JsonSchemaType . Null , Format = "int64" } ,
95+ [ typeof ( ulong ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . Integer | JsonSchemaType . Null , Format = "int64" } ,
96+ [ typeof ( float ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . Number | JsonSchemaType . Null , Format = "float" } ,
97+ [ typeof ( double ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . Number | JsonSchemaType . Null , Format = "double" } ,
98+ [ typeof ( decimal ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . Number | JsonSchemaType . Null , Format = "double" } ,
99+ [ typeof ( DateTime ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . String | JsonSchemaType . Null , Format = "date-time" } ,
100+ [ typeof ( DateTimeOffset ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . String | JsonSchemaType . Null , Format = "date-time" } ,
101+ [ typeof ( Guid ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . String | JsonSchemaType . Null , Format = "uuid" } ,
102+ [ typeof ( char ? ) ] = ( ) => new ( ) { Type = JsonSchemaType . String | JsonSchemaType . Null } ,
103103
104104 [ typeof ( Uri ) ] = ( ) => new ( ) { Type = JsonSchemaType . String , Format = "uri" } , // Uri is treated as simple string
105105 [ typeof ( string ) ] = ( ) => new ( ) { Type = JsonSchemaType . String } ,
@@ -153,37 +153,37 @@ public static Type MapOpenApiPrimitiveTypeToSimpleType(this OpenApiSchema schema
153153 throw new ArgumentNullException ( nameof ( schema ) ) ;
154154 }
155155
156- var type = ( schema . Type . ToIdentifier ( ) , schema . Format ? . ToLowerInvariant ( ) , schema . Nullable ) switch
156+ var type = ( ( schema . Type . Value ^ JsonSchemaType . Null ) . ToIdentifier ( ) , schema . Format ? . ToLowerInvariant ( ) , schema . Type . Value & JsonSchemaType . Null ) switch
157157 {
158- ( "boolean" , null , false ) => typeof ( bool ) ,
158+ ( "integer" or "number" , "int32" , JsonSchemaType . Null ) => typeof ( int ? ) ,
159+ ( "integer" or "number" , "int64" , JsonSchemaType . Null ) => typeof ( long ? ) ,
160+ ( "integer" , null , JsonSchemaType . Null ) => typeof ( long ? ) ,
161+ ( "number" , "float" , JsonSchemaType . Null ) => typeof ( float ? ) ,
162+ ( "number" , "double" , JsonSchemaType . Null ) => typeof ( double ? ) ,
163+ ( "number" , null , JsonSchemaType . Null ) => typeof ( double ? ) ,
164+ ( "number" , "decimal" , JsonSchemaType . Null ) => typeof ( decimal ? ) ,
165+ ( "string" , "byte" , JsonSchemaType . Null ) => typeof ( byte ? ) ,
166+ ( "string" , "date-time" , JsonSchemaType . Null ) => typeof ( DateTimeOffset ? ) ,
167+ ( "string" , "uuid" , JsonSchemaType . Null ) => typeof ( Guid ? ) ,
168+ ( "string" , "char" , JsonSchemaType . Null ) => typeof ( char ? ) ,
169+ ( "boolean" , null , JsonSchemaType . Null ) => typeof ( bool ? ) ,
170+ ( "boolean" , null , _ ) => typeof ( bool ) ,
159171 // integer is technically not valid with format, but we must provide some compatibility
160- ( "integer" or "number" , "int32" , false ) => typeof ( int ) ,
161- ( "integer" or "number" , "int64" , false ) => typeof ( long ) ,
162- ( "integer" , null , false ) => typeof ( long ) ,
163- ( "number" , "float" , false ) => typeof ( float ) ,
164- ( "number" , "double" , false ) => typeof ( double ) ,
165- ( "number" , "decimal" , false ) => typeof ( decimal ) ,
166- ( "number" , null , false ) => typeof ( double ) ,
167- ( "string" , "byte" , false ) => typeof ( byte ) ,
168- ( "string" , "date-time" , false ) => typeof ( DateTimeOffset ) ,
169- ( "string" , "uuid" , false ) => typeof ( Guid ) ,
170- ( "string" , "duration" , false ) => typeof ( TimeSpan ) ,
171- ( "string" , "char" , false ) => typeof ( char ) ,
172- ( "string" , null , false ) => typeof ( string ) ,
173- ( "object" , null , false ) => typeof ( object ) ,
174- ( "string" , "uri" , false ) => typeof ( Uri ) ,
175- ( "integer" or "number" , "int32" , true ) => typeof ( int ? ) ,
176- ( "integer" or "number" , "int64" , true ) => typeof ( long ? ) ,
177- ( "integer" , null , true ) => typeof ( long ? ) ,
178- ( "number" , "float" , true ) => typeof ( float ? ) ,
179- ( "number" , "double" , true ) => typeof ( double ? ) ,
180- ( "number" , null , true ) => typeof ( double ? ) ,
181- ( "number" , "decimal" , true ) => typeof ( decimal ? ) ,
182- ( "string" , "byte" , true ) => typeof ( byte ? ) ,
183- ( "string" , "date-time" , true ) => typeof ( DateTimeOffset ? ) ,
184- ( "string" , "uuid" , true ) => typeof ( Guid ? ) ,
185- ( "string" , "char" , true ) => typeof ( char ? ) ,
186- ( "boolean" , null , true ) => typeof ( bool ? ) ,
172+ ( "integer" or "number" , "int32" , _) => typeof ( int ) ,
173+ ( "integer" or "number" , "int64" , _) => typeof ( long ) ,
174+ ( "integer" , null , _ ) => typeof ( long ) ,
175+ ( "number" , "float" , _ ) => typeof ( float ) ,
176+ ( "number" , "double" , _ ) => typeof ( double ) ,
177+ ( "number" , "decimal" , _ ) => typeof ( decimal ) ,
178+ ( "number" , null , _ ) => typeof ( double ) ,
179+ ( "string" , "byte" , _ ) => typeof ( byte ) ,
180+ ( "string" , "date-time" , _ ) => typeof ( DateTimeOffset ) ,
181+ ( "string" , "uuid" , _ ) => typeof ( Guid ) ,
182+ ( "string" , "duration" , _ ) => typeof ( TimeSpan ) ,
183+ ( "string" , "char" , _ ) => typeof ( char ) ,
184+ ( "string" , null , _ ) => typeof ( string ) ,
185+ ( "object" , null , _ ) => typeof ( object ) ,
186+ ( "string" , "uri" , _ ) => typeof ( Uri ) ,
187187 _ => typeof ( string ) ,
188188 } ;
189189
0 commit comments