Skip to content

Commit 4a1e2ea

Browse files
authored
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. -->
2 parents 33b49c9 + e48257d commit 4a1e2ea

File tree

3 files changed

+4
-70
lines changed

3 files changed

+4
-70
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ cargo-platform = { path = "crates/cargo-platform", version = "0.2.0" }
3535
cargo-test-macro = { version = "0.4.0", path = "crates/cargo-test-macro" }
3636
cargo-test-support = { version = "0.7.0", path = "crates/cargo-test-support" }
3737
cargo-util = { version = "0.2.14", path = "crates/cargo-util" }
38-
cargo-util-schemas = { version = "0.7.0", path = "crates/cargo-util-schemas" }
38+
cargo-util-schemas = { version = "0.7.3", path = "crates/cargo-util-schemas" }
3939
cargo_metadata = "0.19.0"
4040
clap = "4.5.20"
4141
clap_complete = { version = "4.5.35", features = ["unstable-dynamic"] }

crates/cargo-util-schemas/manifest.schema.json

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -621,40 +621,7 @@
621621
}
622622
]
623623
},
624-
"TomlValue": {
625-
"type": "object",
626-
"properties": {
627-
"string": {
628-
"type": "string"
629-
},
630-
"integer": {
631-
"type": "integer",
632-
"format": "int64"
633-
},
634-
"float": {
635-
"type": "number",
636-
"format": "double"
637-
},
638-
"boolean": {
639-
"type": "boolean"
640-
},
641-
"datetime": {
642-
"type": "string"
643-
},
644-
"array": {
645-
"type": "array",
646-
"items": {
647-
"$ref": "#/definitions/TomlValue"
648-
}
649-
},
650-
"table": {
651-
"type": "object",
652-
"additionalProperties": {
653-
"$ref": "#/definitions/TomlValue"
654-
}
655-
}
656-
}
657-
},
624+
"TomlValue": true,
658625
"TomlTarget": {
659626
"type": "object",
660627
"properties": {

crates/cargo-util-schemas/src/schema.rs

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use schemars::JsonSchema;
22

33
use serde::{Deserialize, Serialize};
44

5-
use std::collections::HashMap;
65
use std::string::String;
76

87
use toml::Value as TomlValue;
@@ -16,39 +15,7 @@ impl JsonSchema for TomlValueWrapper {
1615
}
1716

1817
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
19-
use schemars::schema::*;
20-
21-
SchemaObject {
22-
instance_type: Some(InstanceType::Object.into()),
23-
object: Some(Box::new(ObjectValidation {
24-
properties: [
25-
(
26-
"string".to_string(),
27-
gen.subschema_for::<std::string::String>(),
28-
),
29-
("integer".to_string(), gen.subschema_for::<i64>()),
30-
("float".to_string(), gen.subschema_for::<f64>()),
31-
("boolean".to_string(), gen.subschema_for::<bool>()),
32-
(
33-
"datetime".to_string(),
34-
gen.subschema_for::<std::string::String>(),
35-
), // Assuming datetime is represented as a string
36-
(
37-
"array".to_string(),
38-
gen.subschema_for::<Vec<TomlValueWrapper>>(),
39-
),
40-
(
41-
"table".to_string(),
42-
gen.subschema_for::<HashMap<std::string::String, TomlValueWrapper>>(),
43-
),
44-
]
45-
.iter()
46-
.cloned()
47-
.collect(),
48-
..Default::default()
49-
})),
50-
..Default::default()
51-
}
52-
.into()
18+
// HACK: this is both more and less permissive than `TomlValue` but its close
19+
gen.subschema_for::<serde_json::Value>().into()
5320
}
5421
}

0 commit comments

Comments
 (0)