mirror of
https://git.proxmox.com/git/proxmox-backup
synced 2025-11-02 15:18:42 +00:00
docgen: add oneOf case to dump_schema
Since we additonally also support delcaring a "type" property for
`oneOf` schemas (to use with serde's *internally* tagged enum
representation, this contains an additional `typeProperty` and
`typeSchema` value.
It dumps as follows:
{
"type": "object",
"description": ...,
"typeProperty": "name-of-type-property",
"typeSchema": {
"type": "string",
"enum": [ ... ], // technically not enforced by the code
},
"oneOf": [
{
"title": "<value from the above 'enum' array>",
<schema>,
},
{
"title": "<value from the above 'enum' array>",
<schema>,
},
... <one for each 'enum' above>
// ^ exact match is not technically enforced by code
}
}
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
3f9bf340cb
commit
5d28a9ebab
@ -185,6 +185,25 @@ pub fn dump_schema(schema: &Schema) -> Value {
|
|||||||
data = dump_property_schema(alloff_schema);
|
data = dump_property_schema(alloff_schema);
|
||||||
data["type"] = "object".into();
|
data["type"] = "object".into();
|
||||||
}
|
}
|
||||||
|
Schema::OneOf(schema) => {
|
||||||
|
let mut type_schema = dump_schema(schema.type_schema());
|
||||||
|
if schema.type_property_entry.1 {
|
||||||
|
type_schema["optional"] = true.into();
|
||||||
|
}
|
||||||
|
data = json!({
|
||||||
|
"type": "object",
|
||||||
|
"description": schema.description,
|
||||||
|
"typeProperty": schema.type_property(),
|
||||||
|
"typeSchema": type_schema,
|
||||||
|
});
|
||||||
|
let mut variants = Vec::with_capacity(schema.list.len());
|
||||||
|
for (title, variant) in schema.list {
|
||||||
|
let mut entry = dump_schema(variant);
|
||||||
|
entry["title"] = (*title).into();
|
||||||
|
variants.push(entry);
|
||||||
|
}
|
||||||
|
data["oneOf"] = variants.into();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
data
|
data
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user