Skip to content

Commit e24247e

Browse files
committed
rust: set serde to deny unknown fields, reorder fields
This makes JSON validation more strict. We should always track the latest JSON schema version.
1 parent a4ce031 commit e24247e

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/json.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use {
99
};
1010

1111
#[derive(Debug, Deserialize)]
12+
#[serde(deny_unknown_fields)]
1213
pub struct LinkEntry {
1314
pub name: String,
1415
pub path_static: Option<String>,
@@ -18,6 +19,7 @@ pub struct LinkEntry {
1819
}
1920

2021
#[derive(Debug, Deserialize)]
22+
#[serde(deny_unknown_fields)]
2123
pub struct PythonBuildExtensionInfo {
2224
pub in_core: bool,
2325
pub init_fn: String,
@@ -33,6 +35,7 @@ pub struct PythonBuildExtensionInfo {
3335
}
3436

3537
#[derive(Debug, Deserialize)]
38+
#[serde(deny_unknown_fields)]
3639
pub struct PythonBuildCoreInfo {
3740
pub objs: Vec<String>,
3841
pub links: Vec<LinkEntry>,
@@ -41,6 +44,7 @@ pub struct PythonBuildCoreInfo {
4144
}
4245

4346
#[derive(Debug, Deserialize)]
47+
#[serde(deny_unknown_fields)]
4448
pub struct PythonBuildInfo {
4549
pub core: PythonBuildCoreInfo,
4650
pub extensions: BTreeMap<String, Vec<PythonBuildExtensionInfo>>,
@@ -51,36 +55,38 @@ pub struct PythonBuildInfo {
5155
}
5256

5357
#[derive(Debug, Deserialize)]
58+
#[serde(deny_unknown_fields)]
5459
pub struct PythonJsonMain {
55-
pub version: String,
56-
pub target_triple: String,
60+
pub build_info: PythonBuildInfo,
61+
pub crt_features: Vec<String>,
62+
pub libpython_link_mode: String,
63+
pub licenses: Option<Vec<String>>,
64+
pub license_path: Option<String>,
5765
pub optimizations: String,
58-
pub python_tag: String,
5966
pub python_abi_tag: Option<String>,
67+
pub python_bytecode_magic_number: String,
6068
pub python_config_vars: HashMap<String, String>,
61-
pub python_platform_tag: String,
69+
pub python_exe: String,
70+
pub python_extension_module_loading: Vec<String>,
6271
pub python_implementation_cache_tag: String,
6372
pub python_implementation_hex_version: u64,
6473
pub python_implementation_name: String,
6574
pub python_implementation_version: Vec<String>,
66-
pub python_version: String,
6775
pub python_major_minor_version: String,
68-
pub python_paths: HashMap<String, String>,
6976
pub python_paths_abstract: HashMap<String, String>,
70-
pub python_exe: String,
77+
pub python_paths: HashMap<String, String>,
78+
pub python_platform_tag: String,
79+
pub python_stdlib_platform_config: Option<String>,
7180
pub python_stdlib_test_packages: Vec<String>,
7281
pub python_suffixes: HashMap<String, Vec<String>>,
73-
pub python_bytecode_magic_number: String,
7482
pub python_symbol_visibility: String,
75-
pub python_extension_module_loading: Vec<String>,
76-
pub libpython_link_mode: String,
77-
pub crt_features: Vec<String>,
83+
pub python_tag: String,
84+
pub python_version: String,
85+
pub target_triple: String,
7886
pub run_tests: String,
79-
pub build_info: PythonBuildInfo,
80-
pub licenses: Option<Vec<String>>,
81-
pub license_path: Option<String>,
8287
pub tcl_library_path: Option<String>,
8388
pub tcl_library_paths: Option<Vec<String>>,
89+
pub version: String,
8490
}
8591

8692
pub fn parse_python_json(json_data: &[u8]) -> Result<PythonJsonMain> {

0 commit comments

Comments
 (0)