pub fn repair_yaml(yaml_content: &str, schema: &Value) -> RepairResultExpand description
Apply the 6-stage YAML repair pipeline to yaml_content guided by schema.
Stages:
- Normalize — strip surrounding whitespace, normalise CRLF → LF.
- Parse —
serde_yaml→serde_json::Value; returns early on parse failure. - Fill defaults — inject
"default"values fromschemafor absent fields. - Collect errors — walk
schemarecursively and gather violations. - Categorize — split into deterministic (auto-fixable) vs ambiguous errors.
- Fix — apply type coercion and extra-key removal; ambiguous errors become
RepairResult::llm_fieldsfor human or LLM review.
The function never panics — even an entirely unparseable input returns a
RepairResult with valid = false and the original YAML unchanged.
§Arguments
yaml_content— raw YAML string (may be invalid).schema— JSON Schema object used to guide repair (e.g. fromcrate::schema::SchemaRegistry).
§Example
use devops_validate::repair::repair_yaml;
use serde_json::json;
let schema = json!({
"type": "object",
"properties": {
"replicas": { "type": "integer", "default": 1 },
"name": { "type": "string" }
}
});
// "replicas" is a string "3" — should be coerced to integer 3
let result = repair_yaml("replicas: \"3\"\nname: my-app", &schema);
assert!(result.valid);
assert!(result.repaired_yaml.contains("replicas: 3"));
assert!(result.warnings.iter().any(|w| w.contains("Coerced")));