Attributes with same name as type cause name conflicts
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
Research direction
Start by reproducing the issue with the Python Pydantic schema and inspect the code-generation path that produces the shown Rust types. Trace how names are assigned to the generated struct and enum, then add regression coverage for this schema. Done means the generated Rust no longer declares conflicting types and remains valid.
Written by the indexing model from the issue text.
Description
Sample JSON schema:
{
"$defs": {
"FirstType": {
"properties": {
"first": {
"title": "First",
"type": "string"
}
},
"required": [
"first"
],
"title": "FirstType",
"type": "object"
},
"SecondType": {
"properties": {
"second": {
"title": "Second",
"type": "string"
}
},
"required": [
"second"
],
"title": "SecondType",
"type": "object"
}
},
"properties": {
"test": {
"anyOf": [
{
"$ref": "#/$defs/FirstType"
},
{
"$ref": "#/$defs/SecondType"
},
{
"type": "null"
}
],
"title": "Test"
}
},
"required": [
"test"
],
"title": "Test",
"type": "object"
}
This is the JSON schema of this simple class structure (sample code in Python):
import json
from pydantic import BaseModel
class FirstType(BaseModel):
first: str
class SecondType(BaseModel):
second: str
class Test(BaseModel):
test: FirstType | SecondType | None
test_json = Test.model_json_schema()
print(json.dumps(test_json, indent=2))
This results in the following generated schema from using typify. I have only included the important parts:
pub struct Test {
pub test: Test,
}
impl ::std::convert::From<&Test> for Test {
fn from(value: &Test) -> Self {
value.clone()
}
}
impl Test {
pub fn builder() -> builder::Test {
Default::default()
}
}
pub enum Test {
Variant0(FirstType),
Variant1(SecondType),
Variant2,
}
impl ::std::convert::From<&Self> for Test {
fn from(value: &Test) -> Self {
value.clone()
}
}
impl ::std::convert::From<FirstType> for Test {
fn from(value: FirstType) -> Self {
Self::Variant0(value)
}
}
impl ::std::convert::From<SecondType> for Test {
fn from(value: SecondType) -> Self {
Self::Variant1(value)
}
}
Obviously, you can't have an enum and a struct with the same name (enum Test and struct Test).
- Dominant language
- Rust
- Stars
- 898
- Forks
- 114
- Avg merge
- 4h 18m
- Merged PRs (30d)
- 14
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.
More from oxidecomputer/typify
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
oxidecomputer/typify#1077 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
oxidecomputer/typify#1075 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 50/100
oxidecomputer/typify#1060 ·
-
Difficulty 5/5 Over a week Newbie friendliness 48/100
oxidecomputer/typify#1059 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 65/100
oxidecomputer/typify#1022 · 1 comment ·
All issues in oxidecomputer/typify
Similar issues
-
bug github_actions
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
registrystack/registry-stack#1393 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
longbridge/gpui-kit#3223 ·
-
bug engine
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
rocky-data/rocky#2181 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
oasisprotocol/oasis-sdk#2523 ·
-
[indexer] [QA] Add a focused test for the new NonRetryableError / assertSocketAlive() behavior. Openbot:ai-assisted component:indexer QA-roadmap status:untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
midnightntwrk/midnight-indexer#1557 ·