Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Duplicate definitions for types not handled

Open
#638 0 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
compilers

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

naming

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from oxidecomputer/typify

All issues in oxidecomputer/typify

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.