Codegen issues with string enums
まだ誰も着手していません。
評価
調査の方向性
xtask/src/generate_structs.rs の 68 行目と、xtask/src/main.rs の 28 行目にある生成エントリポイントから始め、glTF スキーマの失敗を再現します。string の const 値と一般的な string を含む anyOf エントリがどのように表現されるかを追跡します。生成が成功し、サブタイプフィールドではなく、ドキュメント化された名前付きバリアントとフォールバックの string バリアントを持つ enum が生成されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Rust
- スター
- 898
- フォーク
- 114
- 平均マージ
- 4時間 18分
- マージ済み PR(30日)
- 14
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
oxidecomputer/typify のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
oxidecomputer/typify#1077 · コメント 1 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
oxidecomputer/typify#1075 · コメント 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 50/100
oxidecomputer/typify#1060 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 48/100
oxidecomputer/typify#1059 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
oxidecomputer/typify#1022 · コメント 1 件 ·
oxidecomputer/typify の issue をすべて見る
似ている issue
-
bug github_actions
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
registrystack/registry-stack#1393 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
longbridge/gpui-kit#3223 ·
-
bug engine
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
rocky-data/rocky#2181 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
oasisprotocol/oasis-sdk#2523 ·
-
[indexer] [QA] Add a focused test for the new NonRetryableError / assertSocketAlive() behavior. オープンbot:ai-assisted component:indexer QA-roadmap status:untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
midnightntwrk/midnight-indexer#1557 ·