Files
codex/codex-rs/tools/src/json_schema/compaction_tests.rs
T
Celia Chen 8971fc25a9 Split tool JSON Schema code into focused modules (#42161)
## 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
2026-09-02 00:45:00 +00:00

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" }
]
}
}
})
);
}