fix(schemas): Fix 'metadata' JSON Schema

Found this when looking into #15030
This commit is contained in:
Ed Page 2025-01-08 10:55:47 -06:00
parent e8f3e5e0f2
commit e48257d3c8
2 changed files with 3 additions and 69 deletions

View File

@ -621,40 +621,7 @@
}
]
},
"TomlValue": {
"type": "object",
"properties": {
"string": {
"type": "string"
},
"integer": {
"type": "integer",
"format": "int64"
},
"float": {
"type": "number",
"format": "double"
},
"boolean": {
"type": "boolean"
},
"datetime": {
"type": "string"
},
"array": {
"type": "array",
"items": {
"$ref": "#/definitions/TomlValue"
}
},
"table": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/TomlValue"
}
}
}
},
"TomlValue": true,
"TomlTarget": {
"type": "object",
"properties": {

View File

@ -2,7 +2,6 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::string::String;
use toml::Value as TomlValue;
@ -16,39 +15,7 @@ impl JsonSchema for TomlValueWrapper {
}
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
use schemars::schema::*;
SchemaObject {
instance_type: Some(InstanceType::Object.into()),
object: Some(Box::new(ObjectValidation {
properties: [
(
"string".to_string(),
gen.subschema_for::<std::string::String>(),
),
("integer".to_string(), gen.subschema_for::<i64>()),
("float".to_string(), gen.subschema_for::<f64>()),
("boolean".to_string(), gen.subschema_for::<bool>()),
(
"datetime".to_string(),
gen.subschema_for::<std::string::String>(),
), // Assuming datetime is represented as a string
(
"array".to_string(),
gen.subschema_for::<Vec<TomlValueWrapper>>(),
),
(
"table".to_string(),
gen.subschema_for::<HashMap<std::string::String, TomlValueWrapper>>(),
),
]
.iter()
.cloned()
.collect(),
..Default::default()
})),
..Default::default()
}
.into()
// HACK: this is both more and less permissive than `TomlValue` but its close
gen.subschema_for::<serde_json::Value>().into()
}
}