From ef0cc252cb7ef50c3021c806e5617ec120d3f96a Mon Sep 17 00:00:00 2001 From: Afloat <132809511+Afloat16@users.noreply.github.com> Date: Tue, 20 Oct 2026 21:22:27 +0800 Subject: [PATCH] Accept references and nested unions inside strict anyOf schemas --- deepseek-recipe/src/protocol/json_schema.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/deepseek-recipe/src/protocol/json_schema.rs b/deepseek-recipe/src/protocol/json_schema.rs index f00a97d..d7d3827 100644 --- a/deepseek-recipe/src/protocol/json_schema.rs +++ b/deepseek-recipe/src/protocol/json_schema.rs @@ -28,7 +28,7 @@ pub(crate) enum JsonSchema { #[serde(rename_all = "camelCase")] #[untagged_deserialize(field = "anyOf")] AnyOf { - any_of: Vec, + any_of: Vec, #[serde(skip_serializing_if = "Option::is_none")] description: Option, }, @@ -364,3 +364,19 @@ mod tests { ); } } + +#[cfg(test)] +mod contribution_regression { + use super::*; + + #[test] + fn anyof_accepts_references_and_nested_unions() { + let input = serde_json::json!({"type":"object","properties":{"value":{"anyOf":[{"$ref":"#/properties/base"},{"anyOf":[{"type":"string"},{"type":"null"}]}]},"base":{"type":"integer"}}}); + let result = normalize_strict_schema(input, true, |e| e.to_string(), "root").unwrap(); + assert_eq!( + result["properties"]["value"]["anyOf"][0]["$ref"], + "#/properties/base" + ); + assert!(validate_schema(&result).is_ok()); + } +}