Attributes with same name as type cause name conflicts
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
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
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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di oxidecomputer/typify
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
oxidecomputer/typify#1077 · 1 commento ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
oxidecomputer/typify#1075 · 1 commento ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 50/100
oxidecomputer/typify#1060 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 48/100
oxidecomputer/typify#1059 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 65/100
oxidecomputer/typify#1022 · 1 commento ·
Tutte le issue di oxidecomputer/typify
Issue simili
-
bug github_actions
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
registrystack/registry-stack#1393 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
longbridge/gpui-kit#3223 ·
-
bug engine
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
rocky-data/rocky#2181 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
oasisprotocol/oasis-sdk#2523 ·
-
[indexer] [QA] Add a focused test for the new NonRetryableError / assertSocketAlive() behavior. Apertabot:ai-assisted component:indexer QA-roadmap status:untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
midnightntwrk/midnight-indexer#1557 ·