From 5d28a9ebabe7bff57b30b1dc614751c6c9b13e54 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Fri, 14 Jul 2023 13:18:11 +0200 Subject: [PATCH] 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": "", , }, { "title": "", , }, ... // ^ exact match is not technically enforced by code } } Signed-off-by: Wolfgang Bumiller --- src/bin/docgen.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/bin/docgen.rs b/src/bin/docgen.rs index 2480e5e3..7ee991a0 100644 --- a/src/bin/docgen.rs +++ b/src/bin/docgen.rs @@ -185,6 +185,25 @@ pub fn dump_schema(schema: &Schema) -> Value { data = dump_property_schema(alloff_schema); 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