Don't clobber other schema fields when attaching references (#15336)

This PR fixes an issue where we would clobber the other JSON Schema
fields for any field that we attached a reference to.

This resulted in these fields (e.g., `buffer_font_family`,
`ui_font_family`) losing things like their descriptions.

The approach has been adjusted that references are now added in an
additive fashion, rather than overriding the entire schema object.

Release Notes:

- Fixed an issue where font-related settings in `settings.json` were
missing their descriptions.
This commit is contained in:
Marshall Bowers 2024-07-27 11:08:13 -04:00 committed by GitHub
parent e72f33d79e
commit 8b22f09b6f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -649,30 +649,30 @@ impl settings::Settings for ThemeSettings {
("FontFallbacks".into(), font_fallback_schema.into()), ("FontFallbacks".into(), font_fallback_schema.into()),
]); ]);
root_schema // The list of properties that should reference another definition in
.schema // the schema.
.object let properties_with_references = vec![
.as_mut() ("buffer_font_family", "#/definitions/FontFamilies"),
.unwrap() ("buffer_font_fallbacks", "#/definitions/FontFallbacks"),
.properties ("ui_font_family", "#/definitions/FontFamilies"),
.extend([ ("ui_font_fallbacks", "#/definitions/FontFallbacks"),
( ];
"buffer_font_family".to_owned(),
Schema::new_ref("#/definitions/FontFamilies".into()), for (property, definition) in properties_with_references {
), let Some(schema) = root_schema.schema.object().properties.get_mut(property) else {
( log::warn!("property '{property}' not found in JSON schema");
"buffer_font_fallbacks".to_owned(), continue;
Schema::new_ref("#/definitions/FontFallbacks".into()), };
),
( match schema {
"ui_font_family".to_owned(), Schema::Object(schema) => {
Schema::new_ref("#/definitions/FontFamilies".into()), schema.reference = Some(definition.into());
), }
( Schema::Bool(_) => {
"ui_font_fallbacks".to_owned(), // Boolean schemas can't have references.
Schema::new_ref("#/definitions/FontFallbacks".into()), }
), }
]); }
root_schema root_schema
} }