Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public static JsonElement CreateJsonSchema(
/// <summary>Validates the provided JSON schema document.</summary>
internal static void ValidateSchemaDocument(JsonElement document, [CallerArgumentExpression("document")] string? paramName = null)
{
if (document.ValueKind is not JsonValueKind.Object or JsonValueKind.False or JsonValueKind.True)
if (document.ValueKind is not (JsonValueKind.Object or JsonValueKind.False or JsonValueKind.True))
{
Throw.ArgumentException(paramName ?? "schema", "The schema document must be an object or a boolean value.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,34 @@ public static void TransformJsonSchema_InvalidInput_ThrowsArgumentException(stri
Assert.Throws<ArgumentException>("schema", () => AIJsonUtilities.TransformSchema(schema, transformOptions));
}

[Theory]
[InlineData("true")]
[InlineData("false")]
public static void TransformJsonSchema_BooleanSchemas_Success(string booleanSchema)
{
// Boolean schemas (true/false) are valid JSON schemas per the spec.
// This test verifies they are accepted by TransformSchema.
JsonElement schema = JsonDocument.Parse(booleanSchema).RootElement;
AIJsonSchemaTransformOptions transformOptions = new() { ConvertBooleanSchemas = true };

// Should not throw - boolean schemas are valid
JsonElement result = AIJsonUtilities.TransformSchema(schema, transformOptions);

// Verify the transformation happened correctly
if (booleanSchema == "true")
{
// 'true' schema should be converted to empty object
Assert.Equal(JsonValueKind.Object, result.ValueKind);
}
else
{
// 'false' schema should be converted to {"not": true}
Assert.Equal(JsonValueKind.Object, result.ValueKind);
Assert.True(result.TryGetProperty("not", out JsonElement notValue));
Assert.Equal(JsonValueKind.True, notValue.ValueKind);
}
}

private class DerivedAIContent : AIContent
{
public int DerivedValue { get; set; }
Expand Down
Loading