Skip to content

Commit

Permalink
fix: Don't render nested titles for schemas. (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored Feb 15, 2024
1 parent 736bcb2 commit 28d67a2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 15 additions & 3 deletions crates/schematic/src/schema/renderers/json_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ impl SchemaRenderer<Schema> 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()
Expand Down Expand Up @@ -327,7 +331,11 @@ impl SchemaRenderer<Schema> 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()
Expand Down Expand Up @@ -371,7 +379,11 @@ impl SchemaRenderer<Schema> 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -211,7 +210,6 @@ expression: "fs::read_to_string(file).unwrap()"
"additionalProperties": false,
"definitions": {
"AnotherConfig": {
"title": "AnotherConfig",
"description": "Some comment.",
"type": "object",
"required": [
Expand Down Expand Up @@ -248,7 +246,6 @@ expression: "fs::read_to_string(file).unwrap()"
"additionalProperties": false
},
"BasicEnum": {
"title": "BasicEnum",
"type": "string",
"enum": [
"foo",
Expand Down

0 comments on commit 28d67a2

Please sign in to comment.