Skip to main content

translate_descriptions

Function translate_descriptions 

Source
pub fn translate_descriptions(value: &mut Value)
Expand description

Translate every description of a JSON Schema document, in place.

schemars writes one for the type and one for each field, at every depth the type reaches, so the walk is the whole document rather than its root.

use majordomus_cli::capability::rustdoc::translate_descriptions;

let mut schema = serde_json::json!({
    "description": "A [`Root::Thing`].",
    "properties": { "field": { "description": "See [`Other::Field`]." } },
    "title": "Only descriptions are prose [`Kept`]."
});
translate_descriptions(&mut schema);
assert_eq!(schema["description"], "A `Root::Thing`.");
assert_eq!(schema["properties"]["field"]["description"], "See `Other::Field`.");
assert_eq!(schema["title"], "Only descriptions are prose [`Kept`].");