Attributes with same name as type cause name conflicts
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
Línea de trabajo
Comienza reproduciendo el problema con el esquema de Python Pydantic e inspecciona la ruta de generación de código que produce los tipos de Rust mostrados. Sigue cómo se asignan los nombres al struct y al enum generados, y añade cobertura de regresión para este esquema. Se considera terminado cuando el Rust generado ya no declara tipos en conflicto y sigue siendo válido.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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).
- Lenguaje dominante
- Rust
- Estrellas
- 898
- Forks
- 114
- Merge medio
- 4 h 18 min
- PR fusionados (30 d)
- 14
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de oxidecomputer/typify
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
oxidecomputer/typify#1077 · 1 comentario ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
oxidecomputer/typify#1075 · 1 comentario ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 50/100
oxidecomputer/typify#1060 ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 48/100
oxidecomputer/typify#1059 ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 65/100
oxidecomputer/typify#1022 · 1 comentario ·
Todos los issues de oxidecomputer/typify
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
TheLarkInn/aipm#2413 ·
-
documentation
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
alexgorbatchev/simple-ptt#15 ·
-
tooling
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
todo:ticket
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
taikoxyz/taiko-mono#22168 · 1 comentario ·