Skip to content

Commit

Permalink
fix(schemas): Fix 'metadata' JSON Schema
Browse files Browse the repository at this point in the history
Found this when looking into #15030
  • Loading branch information
epage committed Jan 8, 2025
1 parent e8f3e5e commit e48257d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 69 deletions.
35 changes: 1 addition & 34 deletions crates/cargo-util-schemas/manifest.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
37 changes: 2 additions & 35 deletions crates/cargo-util-schemas/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use schemars::JsonSchema;

use serde::{Deserialize, Serialize};

use std::collections::HashMap;
use std::string::String;

use toml::Value as TomlValue;
Expand All @@ -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()
}
}

0 comments on commit e48257d

Please sign in to comment.