Duplicate definitions for types not handled
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
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.
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();
}
- Dominant language
- Rust
- Stars
- 905
- Forks
- 116
- Avg merge
- 13h 19m
- Merged PRs (30d)
- 16
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
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.
More from oxidecomputer/typify
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
oxidecomputer/typify#1077 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
oxidecomputer/typify#1075 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 50/100
oxidecomputer/typify#1060 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 48/100
oxidecomputer/typify#1059 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 65/100
oxidecomputer/typify#1022 · 1 comment ·
Maintainers usually reply within 1 day
All issues in oxidecomputer/typify
Similar issues
-
tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
documentation
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
discover: `sudo RTK_DISABLED=$VAR …` is not detected as a bypass when `sudo` is a transparent prefixOpenarea:cli bug good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
skill:code-review
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
component:sight
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
agentic-os-org/ANOLISA#4115 · 1 comment ·
Maintainers usually reply within 1 day