Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Attributes with same name as type cause name conflicts

Aperta
#801 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python, rust
Ambito
compilers

Direzione di ricerca

Inizia riproducendo il problema con lo schema Python Pydantic e ispeziona il percorso di generazione del codice che produce i tipi Rust mostrati. Traccia il modo in cui vengono assegnati i nomi alla struct e all'enum generati, quindi aggiungi una copertura di regressione per questo schema. Il lavoro è completo quando il Rust generato non dichiara più tipi in conflitto e rimane valido.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

naming

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).

Lingua principale
Rust
Stelle
898
Fork
114
Merge medio
4h 18m
PR unite (30g)
14

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di oxidecomputer/typify

Tutte le issue di oxidecomputer/typify

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.