From d80ab63fb2c8c57703efeddf258a645ca1034feb Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Wed, 14 Feb 2024 19:11:47 -0800 Subject: [PATCH 1/2] Remove title. --- .../src/schema/renderers/json_schema.rs | 18 +++++++++++++++--- ...nerator_test__json_schema__with_titles.snap | 3 --- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/crates/schematic/src/schema/renderers/json_schema.rs b/crates/schematic/src/schema/renderers/json_schema.rs index c0a37178..a33136af 100644 --- a/crates/schematic/src/schema/renderers/json_schema.rs +++ b/crates/schematic/src/schema/renderers/json_schema.rs @@ -185,7 +185,11 @@ impl SchemaRenderer for JsonSchemaRenderer { } let metadata = Metadata { - title: enu.name.clone(), + title: if self.options.set_field_name_as_title { + None + } else { + enu.name.clone() + }, description: enu .description .clone() @@ -327,7 +331,11 @@ impl SchemaRenderer for JsonSchemaRenderer { let data = SchemaObject { instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::Object))), metadata: Some(Box::new(Metadata { - title: structure.name.clone(), + title: if self.options.set_field_name_as_title { + None + } else { + structure.name.clone() + }, description: structure .description .clone() @@ -371,7 +379,11 @@ impl SchemaRenderer for JsonSchemaRenderer { let mut items = vec![]; let mut metadata = Metadata { - title: uni.name.clone(), + title: if self.options.set_field_name_as_title { + None + } else { + uni.name.clone() + }, description: uni .description .clone() diff --git a/crates/schematic/tests/snapshots/generator_test__json_schema__with_titles.snap b/crates/schematic/tests/snapshots/generator_test__json_schema__with_titles.snap index 88d1b286..01153196 100644 --- a/crates/schematic/tests/snapshots/generator_test__json_schema__with_titles.snap +++ b/crates/schematic/tests/snapshots/generator_test__json_schema__with_titles.snap @@ -4,7 +4,6 @@ expression: "fs::read_to_string(file).unwrap()" --- { "$schema": "http://json-schema.org/draft-07/schema#", - "title": "GenConfig", "type": "object", "required": [ "boolean", @@ -211,7 +210,6 @@ expression: "fs::read_to_string(file).unwrap()" "additionalProperties": false, "definitions": { "AnotherConfig": { - "title": "AnotherConfig", "description": "Some comment.", "type": "object", "required": [ @@ -248,7 +246,6 @@ expression: "fs::read_to_string(file).unwrap()" "additionalProperties": false }, "BasicEnum": { - "title": "BasicEnum", "type": "string", "enum": [ "foo", From ac61a08d87f67ed896729faef41c3f237454953f Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Wed, 14 Feb 2024 19:12:17 -0800 Subject: [PATCH 2/2] Update changelog. --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7ceaf97..db2e71dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,16 @@ # Changelog +## Unreleased + +#### 🐞 Fixes + +- Fixed some issues around JSON Schema `title` generation. + ## 0.14.1 #### 🚀 Updates -- Added new JSONSchema renderer options: +- Added new JSON Schema renderer options: - `allow_newlines_in_description` - Allows newlines in descriptions, otherwise strips them. Defaults to `false`. - `mark_struct_fields_required` - Mark all non-option struct fields as required. Defaults to