mirror of
https://github.com/openai/codex.git
synced 2026-12-03 00:41:03 +00:00
## What changed - Move schema types, traversal helpers, and large-schema compaction into dedicated `json_schema` submodules. - Keep the public schema types re-exported from the existing module and colocate focused unit tests with their implementations. GitOrigin-RevId: 953b96c28ae3880f601b588eb016fa126c438852
128 lines
3.9 KiB
Rust
128 lines
3.9 KiB
Rust
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn collapse_deep_schema_objects_traverses_schema_children() {
|
|
let mut schema = serde_json::json!({
|
|
"type": "object",
|
|
"properties": {
|
|
"object_parent": {
|
|
"type": "object",
|
|
"properties": {
|
|
"complex": {
|
|
"type": "object",
|
|
"properties": {
|
|
"nested": {
|
|
"type": "object",
|
|
"properties": {
|
|
"leaf": { "type": "string" }
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"scalar": {
|
|
"type": "string"
|
|
}
|
|
}
|
|
},
|
|
"array_parent": {
|
|
"type": "array",
|
|
"items": {
|
|
"type": "object",
|
|
"properties": {
|
|
"nested": {
|
|
"type": "object",
|
|
"properties": {
|
|
"leaf": { "type": "string" }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"map_parent": {
|
|
"type": "object",
|
|
"additionalProperties": {
|
|
"type": "object",
|
|
"properties": {
|
|
"nested": {
|
|
"type": "object",
|
|
"properties": {
|
|
"leaf": { "type": "string" }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"union_parent": {
|
|
"anyOf": [
|
|
{
|
|
"type": "object",
|
|
"properties": {
|
|
"nested": {
|
|
"type": "object",
|
|
"properties": {
|
|
"leaf": { "type": "string" }
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{ "type": "string" }
|
|
]
|
|
}
|
|
}
|
|
});
|
|
|
|
super::collapse_deep_schema_objects(&mut schema, /*depth*/ 0);
|
|
|
|
assert_eq!(
|
|
schema,
|
|
serde_json::json!({
|
|
"type": "object",
|
|
"properties": {
|
|
"object_parent": {
|
|
"type": "object",
|
|
"properties": {
|
|
"complex": {
|
|
"type": "object",
|
|
"properties": {
|
|
"nested": {}
|
|
}
|
|
},
|
|
"scalar": {
|
|
"type": "string"
|
|
}
|
|
}
|
|
},
|
|
"array_parent": {
|
|
"type": "array",
|
|
"items": {
|
|
"type": "object",
|
|
"properties": {
|
|
"nested": {}
|
|
}
|
|
}
|
|
},
|
|
"map_parent": {
|
|
"type": "object",
|
|
"additionalProperties": {
|
|
"type": "object",
|
|
"properties": {
|
|
"nested": {}
|
|
}
|
|
}
|
|
},
|
|
"union_parent": {
|
|
"anyOf": [
|
|
{
|
|
"type": "object",
|
|
"properties": {
|
|
"nested": {}
|
|
}
|
|
},
|
|
{ "type": "string" }
|
|
]
|
|
}
|
|
}
|
|
})
|
|
);
|
|
}
|