Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Codegen issues with string enums

Abierto
#862 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
rust
Área
compilers

Línea de trabajo

Comienza con xtask/src/generate_structs.rs en la línea 68 y el punto de entrada de generación en xtask/src/main.rs en la línea 28, y reproduce el fallo del esquema glTF. Traza cómo se representan las entradas anyOf que contienen valores const de tipo string y un string general. Se considera terminado cuando la generación se completa correctamente y produce un enum con las variantes con nombre documentadas, además de una variante string de fallback, en lugar de campos de subtipo.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

fancy types

First up, thank you for your work on typify, great crate. Helped me a few times already.

Right now I'm attempting to build a system to handle glTF files, and apparently typify has some issues with their string enum definitions.

Their definitions look as follows (this is one example, there are multiple of those in their schemas):

[...]
"interpolation": {
            "description": "Interpolation algorithm.",
            "default": "LINEAR",
            "gltf_detailedDescription": "Interpolation algorithm.",
            "anyOf": [
                {
                    "const": "LINEAR",
                    "description": "The animated values are linearly interpolated between keyframes. When targeting a rotation, spherical linear interpolation (slerp) **SHOULD** be used to interpolate quaternions. The number of output elements **MUST** equal the number of input elements."
                },
                {
                    "const": "STEP",
                    "description": "The animated values remain constant to the output of the first keyframe, until the next keyframe. The number of output elements **MUST** equal the number of input elements."
                },
                {
                    "const": "CUBICSPLINE",
                    "description": "The animation's interpolation is computed using a cubic spline with specified tangents. The number of output elements **MUST** equal three times the number of input elements. For each input element, the output stores three elements, an in-tangent, a spline vertex, and an out-tangent. There **MUST** be at least two keyframes when using this interpolation."
                },
                {
                    "type": "string"
                }
            ]
        }
[...]

where I'd expect a codegen such as:

#[derive(Deserialize, Serialize, Default)]
pub enum Interpolation {
  #[default]
  #[serde(rename = "LINEAR")]
  #[doc = "The animated values are linearly interpolated between keyframes. When targeting a rotation, spherical linear interpolation (slerp) **SHOULD** be used to interpolate quaternions. The number of output elements **MUST** equal the number of input elements."]
  Linear,
  #[serde(rename = "STEP")]
  #[doc = "BLAH"]
  Step,
  #[serde(rename = "CUBICSPLINE")]
  #[doc = "BLAH x2"]
  Cubicspline,
  #[serde(other)]
  Other(String),
}

In its current state, typify just errors out (which is better than producing faulty definitions, I guess).

Backtrace
Error: value does not conform to the given schema

Stack backtrace:
   0: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from
             at /home/aumetra/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anyhow-1.0.98/src/backtrace.rs:27:14
   1: <core::result::Result<T,F> as core::ops::try_trait::FromResidual<core::result::Result<core::convert::Infallible,E>>>::from_residual
             at /home/aumetra/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:2050:27
   2: xtask::generate_structs::do_it
             at ./xtask/src/generate_structs.rs:68:5
   3: xtask::main
             at ./xtask/src/main.rs:28:44
   4: core::ops::function::FnOnce::call_once
             at /home/aumetra/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
   5: std::sys::backtrace::__rust_begin_short_backtrace
             at /home/aumetra/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:152:18
   6: std::rt::lang_start::{{closure}}
             at /home/aumetra/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:199:18
   7: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/ops/function.rs:284:13
   8: std::panicking::try::do_call
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:589:40
   9: std::panicking::try
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:552:19
  10: std::panic::catch_unwind
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panic.rs:359:14
  11: std::rt::lang_start_internal::{{closure}}
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/rt.rs:168:24
  12: std::panicking::try::do_call
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:589:40
  13: std::panicking::try
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:552:19
  14: std::panic::catch_unwind
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panic.rs:359:14
  15: std::rt::lang_start_internal
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/rt.rs:164:5
  16: std::rt::lang_start
             at /home/aumetra/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:198:5
  17: main
  18: <unknown>
  19: __libc_start_main
  20: _start

By patching out some of the sanity checks, I got it to emit some definitions, and the definitions look like this:

#[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug)]
pub struct AnimationSamplerInterpolation {
    #[serde(
        flatten,
        default,
        skip_serializing_if = "::std::option::Option::is_none"
    )]
    pub subtype_0: ::std::option::Option<::serde_json::Value>,
    #[serde(
        flatten,
        default,
        skip_serializing_if = "::std::option::Option::is_none"
    )]
    pub subtype_1: ::std::option::Option<::serde_json::Value>,
    #[serde(
        flatten,
        default,
        skip_serializing_if = "::std::option::Option::is_none"
    )]
    pub subtype_2: ::std::option::Option<::serde_json::Value>,
    #[serde(
        flatten,
        default,
        skip_serializing_if = "::std::option::Option::is_none"
    )]
    pub subtype_3: ::std::option::Option<::std::string::String>,
}

Where I can sorta get where the generator is coming from when it generated it.


Unfortunately I don't have too much knowledge about the internals to be able to come up with a solution that generates correct types in this scenario.

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

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de oxidecomputer/typify

Todos los issues de oxidecomputer/typify

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.