mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
fix(schemas): Fix 'metadata' JSON Schema (#15033)
Instead of allowing any type in metadata, we were specifying fields like `"string": "<any string>"`. Found this when looking into #15030 <!-- Thanks for submitting a pull request 🎉! Here are some tips for you: * If this is your first contribution, read "Cargo Contribution Guide" first: https://doc.crates.io/contrib/ * Run `cargo fmt --all` to format your code changes. * Small commits and pull requests are always preferable and easy to review. * If your idea is large and needs feedback from the community, read how: https://doc.crates.io/contrib/process/#working-on-large-features * Cargo takes care of compatibility. Read our design principles: https://doc.crates.io/contrib/design.html * When changing help text of cargo commands, follow the steps to generate docs: https://github.com/rust-lang/cargo/tree/master/src/doc#building-the-man-pages * If your PR is not finished, set it as "draft" PR or add "WIP" in its title. * It's ok to use the CI resources to test your PR, but please don't abuse them. ### What does this PR try to resolve? Explain the motivation behind this change. A clear overview along with an in-depth explanation are helpful. You can use `Fixes #<issue number>` to associate this PR to an existing issue. ### How should we test and review this PR? Demonstrate how you test this change and guide reviewers through your PR. With a smooth review process, a pull request usually gets reviewed quicker. If you don't know how to write and run your tests, please read the guide: https://doc.crates.io/contrib/tests ### Additional information Other information you want to mention in this PR, such as prior arts, future extensions, an unresolved problem, or a TODO list. -->
This commit is contained in:
commit
4a1e2ea539
@ -35,7 +35,7 @@ cargo-platform = { path = "crates/cargo-platform", version = "0.2.0" }
|
||||
cargo-test-macro = { version = "0.4.0", path = "crates/cargo-test-macro" }
|
||||
cargo-test-support = { version = "0.7.0", path = "crates/cargo-test-support" }
|
||||
cargo-util = { version = "0.2.14", path = "crates/cargo-util" }
|
||||
cargo-util-schemas = { version = "0.7.0", path = "crates/cargo-util-schemas" }
|
||||
cargo-util-schemas = { version = "0.7.3", path = "crates/cargo-util-schemas" }
|
||||
cargo_metadata = "0.19.0"
|
||||
clap = "4.5.20"
|
||||
clap_complete = { version = "4.5.35", features = ["unstable-dynamic"] }
|
||||
|
@ -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": {
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user