oxidecomputer / oxidecomputer/typify
Duplicate definitions for types not handled
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 898
- Forks
- 114
- Avg merge
- 4h 18m
- Merged PRs (30d)
- 14
Description
Overview:
I have a big schema (https://www.omg.org/spec/SysML/20230201/SysML.json) that seems to refine types a lot, causing quite some warnings by typify. Please note that the schema uses https references to itself, so for it to work with this crate I processed it a little, changing all https $refs into local $refs. Find the edited json file attached below.
Cause:
The cause is code like this:
#[serde(rename = "@type")]
type_: String,
#[serde(rename = "type")]
type_: Vec<Identified>,
Error:
This yields the following three errors (in many many instances):
--> /work/sysml-v2-sql/target/debug/build/sysml-v2-sql-fe9e4667a4b133c5/out/codegen.rs:13108:9
|
13108 | type_: Vec<Identified>,
| ^^^^^ used in a pattern more than once
error[E0124]: field `type_` is already declared
--> /work/sysml-v2-sql/target/debug/build/sysml-v2-sql-fe9e4667a4b133c5/out/codegen.rs:1315:5
|
1313 | pub type_: String,
| ----------------- `type_` first declared here
1314 | #[serde(rename = "type")]
1315 | pub type_: Vec<Identified>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ field already declared
error[E0592]: duplicate definitions with name `type_`
--> /work/sysml-v2-sql/target/debug/build/sysml-v2-sql-fe9e4667a4b133c5/out/codegen.rs:182906:9
|
182894 | / pub fn type_<T>(mut self, value: T) -> Self
182895 | | where
182896 | | T: std::convert::TryInto<String>,
182897 | | T::Error: std::fmt::Display,
| |________________________________________- other definition for `type_`
...
182906 | / pub fn type_<T>(mut self, value: T) -> Self
182907 | | where
182908 | | T: std::convert::TryInto<Vec<super::Identified>>,
182909 | | T::Error: std::fmt::Display,
| |________________________________________^ duplicate definitions for `type_`
Files for reproduction:
use std::{env, fs, path::Path};
use typify::{TypeSpace, TypeSpaceSettings};
fn main() {
let content = std::fs::read_to_string("SysML-processed.json").unwrap();
let schema = serde_json::from_str::<schemars::schema::RootSchema>(&content).unwrap();
let mut type_space = TypeSpace::new(TypeSpaceSettings::default().with_struct_builder(true));
type_space.add_root_schema(schema).unwrap();
let contents = format!(
"{}\n{}",
"use serde::{Deserialize, Serialize};",
prettyplease::unparse(&syn::parse2::<syn::File>(type_space.to_stream()).unwrap())
);
let mut out_file = Path::new(&env::var("OUT_DIR").unwrap()).to_path_buf();
out_file.push("codegen.rs");
fs::write(out_file, contents).unwrap();
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with SysML-processed.json and the provided Rust program, then inspect the output from TypeSpace::add_root_schema and TypeSpace::to_stream alongside cargo-build.log. The generated code should no longer contain duplicate fields, pattern bindings, or builder methods for refined properties, and the reproduction should compile successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100