Extending type with patternProperties panics
まだ誰も着手していません。
評価
調査の方向性
縮小したスキーマから始め、cargo typify demo.json を実行して panic を再現します。次に、1093~1097 行付近の typify-impl/src/merge.rs と、関連する merge および変換の経路を読みます。$ref と patternProperties の組み合わせで意図されている生成表現を特定し、縮小した例を対象とするリグレッションテストで、生成が panic しなくなったことを確認します。
索引モデルが issue の本文から書いたものです。
説明
I have a jsonschema that extends a type in $defs with patternProperties. It seems to be valid spec according to the jsonschema schema but trying to run in typify panics when it hits the "assert until we hit some examples in the wild" case.
The full schema is this one but a reduced example is
{
"type": "object",
"title": "demo",
"$defs": {
"Foo": {
"type": "object",
"properties": {
"names": {
"type": "array",
"items": {
"type": "string"
}
}
},
"additionalProperties": true
}
},
"properties": {
"foos": {
"patternProperties": {
"^([^.]+)$": {
"type": "string"
}
},
"additionalProperties": false,
"$ref": "#/$defs/Foo"
}
},
"additionalProperties": false
}
Trying to generate rust types for this:
$ cargo typify demo.json
The application panicked (crashed).
Message: assertion failed: object_schema.pattern_properties.is_empty()
Location: /home/tpoliaw/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/typify-impl-0.4.3/src/merge.rs:1097
Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
The full backtrace:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⋮ 7 frames hidden ⋮
8: core::panicking::panic::h239804395728b21f
at :
9: typify_impl::merge::filter_prop::hcfcdca93086e2696
at :
10: core::ops::function::impls:: for &mut F>::call_mut::h65948c7c0444d08e
at :
11: as core::iter::traits::iterator::Iterator>::try_fold::hace7ef08575e7b49
at :
12: as alloc::vec::spec_from_iter::SpecFromIter>::from_iter::h7ea76529691f2a38
at :
13: as core::iter::traits::collect::FromIterator<(K,V)>>::from_iter::h6c46cd13dbb1211f
at :
14: typify_impl::merge::merge_schema_object::h9489b2a77ecfa96f
at :
15: typify_impl::merge::try_merge_schema::hbc00f95ac2fd915b
at :
16: typify_impl::merge::try_merge_all::h4089b26e8429459d
at :
17: typify_impl::convert::::convert_schema_object::hd95336249f11be54
at :
18: typify_impl::convert::::convert_schema::h35f032f73776c3d1
at :
19: typify_impl::TypeSpace::id_for_schema::h9cfb5165927b154b
at :
20: typify_impl::structs::::struct_property::hf2ed4fd4ca71910d
at :
21: core::ops::function::impls:: for &mut F>::call_mut::hbb4ca9ea98a63834
at :
22: as core::iter::traits::iterator::Iterator>::try_fold::h3dbbd5aade776e21
at :
23: as alloc::vec::spec_from_iter::SpecFromIter>::from_iter::h650f7eeb960e78a3
at :
24: core::iter::adapters::try_process::hb44e15d357358101
at :
25: typify_impl::structs::::struct_members::h84819872195b99b8
at :
26: typify_impl::convert::::convert_object::h4647703ca96f3e93
at :
27: typify_impl::convert::::convert_schema_object::hd95336249f11be54
at :
28: typify_impl::convert::::convert_schema::h35f032f73776c3d1
at :
29: typify_impl::TypeSpace::convert_ref_type::h86911b0457188e5e
at :
30: typify_impl::TypeSpace::add_root_schema::hf55ea7f22c393dbf
at :
31: cargo_typify::convert::h42de6a2580ca5755
at :
32: cargo_typify::main::h7c7d68ad279a602e
at :
33: std::sys::backtrace::__rust_begin_short_backtrace::h794250a6be559321
at :
34: std::rt::lang_start::{{closure}}::h5a7c07a612017b6b
at :
35: std::rt::lang_start_internal::h31bbb7f936fd6b5d
at :
36: main
at :
37: __libc_start_main
at :
38: _start
at :
Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
Run with RUST_BACKTRACE=full to include source snippets.
I'm not sure what the generate type should look like, possibly something like
struct DemoFoo {
names: Vec<String>,
#[serde(flatten)]
pattern_properties: HashMap<DemoFooKey, String>,
}
where DemoFooKey uses the same approach as other uses of patternProperties with a regex in the deserialisation method.
Would this be something that is feasible to support?
- 主要言語
- Rust
- スター
- 898
- フォーク
- 114
- 平均マージ
- 4時間 18分
- マージ済み PR(30日)
- 14
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
oxidecomputer/typify のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
oxidecomputer/typify#1077 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
oxidecomputer/typify#1075 ·
-
難易度 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
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
gitbutlerapp/gitbutler#15998 · コメント 1 件 ·
-
bug triage:deciding
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
open-telemetry/otel-arrow#4132 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100