File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
src/Libraries/Microsoft.Extensions.AI.Abstractions/Utilities
test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -193,7 +193,7 @@ public static JsonElement CreateJsonSchema(
193193 /// <summary>Validates the provided JSON schema document.</summary>
194194 internal static void ValidateSchemaDocument ( JsonElement document , [ CallerArgumentExpression ( "document" ) ] string ? paramName = null )
195195 {
196- if ( document . ValueKind is not JsonValueKind . Object or JsonValueKind . False or JsonValueKind . True )
196+ if ( document . ValueKind is not ( JsonValueKind . Object or JsonValueKind . False or JsonValueKind . True ) )
197197 {
198198 Throw . ArgumentException ( paramName ?? "schema" , "The schema document must be an object or a boolean value." ) ;
199199 }
Original file line number Diff line number Diff line change @@ -1416,6 +1416,34 @@ public static void TransformJsonSchema_InvalidInput_ThrowsArgumentException(stri
14161416 Assert . Throws < ArgumentException > ( "schema" , ( ) => AIJsonUtilities . TransformSchema ( schema , transformOptions ) ) ;
14171417 }
14181418
1419+ [ Theory ]
1420+ [ InlineData ( "true" ) ]
1421+ [ InlineData ( "false" ) ]
1422+ public static void TransformJsonSchema_BooleanSchemas_Success ( string booleanSchema )
1423+ {
1424+ // Boolean schemas (true/false) are valid JSON schemas per the spec.
1425+ // This test verifies they are accepted by TransformSchema.
1426+ JsonElement schema = JsonDocument . Parse ( booleanSchema ) . RootElement ;
1427+ AIJsonSchemaTransformOptions transformOptions = new ( ) { ConvertBooleanSchemas = true } ;
1428+
1429+ // Should not throw - boolean schemas are valid
1430+ JsonElement result = AIJsonUtilities . TransformSchema ( schema , transformOptions ) ;
1431+
1432+ // Verify the transformation happened correctly
1433+ if ( booleanSchema == "true" )
1434+ {
1435+ // 'true' schema should be converted to empty object
1436+ Assert . Equal ( JsonValueKind . Object , result . ValueKind ) ;
1437+ }
1438+ else
1439+ {
1440+ // 'false' schema should be converted to {"not": true}
1441+ Assert . Equal ( JsonValueKind . Object , result . ValueKind ) ;
1442+ Assert . True ( result . TryGetProperty ( "not" , out JsonElement notValue ) ) ;
1443+ Assert . Equal ( JsonValueKind . True , notValue . ValueKind ) ;
1444+ }
1445+ }
1446+
14191447 private class DerivedAIContent : AIContent
14201448 {
14211449 public int DerivedValue { get ; set ; }
You can’t perform that action at this time.
0 commit comments