oxidecomputer / oxidecomputer/typify
`title` isn't propagated to types that need names
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 898
- Forks
- 114
- Avg merge
- 4h 18m
- Merged PRs (30d)
- 14
Description
Hello! Thanks for your work on this library, I've found it super useful so far.
I came upon some strange failures while attempting to generate types from a schema. After some debugging, I've worked out that typify fails when all of the following are true:
- a schema has a top-level
title - there exists a
oneOf -> object -> array -> objectstructure - the
objectat the bottom of this aforementioned structure hasadditionalProperties: false
Oddly, removing the schema title fixes the issue. I'm surprised at the apparent incompatibility with fine-grained details deep within the schema.
I've worked out a somewhat-minimal reproduction:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "levilutz/test",
"title": "My Title",
"oneOf": [
{
"type": "object",
"properties": {
"myArray": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false
}
}
},
"required": ["myArray"]
}
]
}
This is a valid schema according to other tools (e.g. https://www.jsonschemavalidator.net/), and validates against a simple object like:
{
"myArray": []
}
When running the most-recent version of typify (v0.4.1) against this schema, however, I get the following error response:
The application panicked (crashed).
Message: called `Option::unwrap()` on a `None` value
Location: /usr/local/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/typify-impl-0.4.1/src/type_entry.rs:365
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⋮ 7 frames hidden ⋮
8: core::panicking::panic::h7b600627f80950c0
at <unknown source file>:<unknown line>
9: core::option::unwrap_failed::ha26b4e83b98d2d13
at <unknown source file>:<unknown line>
10: typify_impl::type_entry::TypeEntryStruct::from_metadata::hcf544dd3f0cc8c8e
at <unknown source file>:<unknown line>
11: typify_impl::convert::<impl typify_impl::TypeSpace>::convert_object::h2a7082577a772472
at <unknown source file>:<unknown line>
12: typify_impl::convert::<impl typify_impl::TypeSpace>::convert_schema_object::h7e4ec5c054bed7e9
at <unknown source file>:<unknown line>
13: typify_impl::convert::<impl typify_impl::TypeSpace>::convert_schema::h7957d2868a66153d
at <unknown source file>:<unknown line>
14: typify_impl::TypeSpace::id_for_schema::h19fa02d922234d32
at <unknown source file>:<unknown line>
15: typify_impl::convert::<impl typify_impl::TypeSpace>::convert_array::h5868e01754fabf21
at <unknown source file>:<unknown line>
16: typify_impl::convert::<impl typify_impl::TypeSpace>::convert_schema_object::h7e4ec5c054bed7e9
at <unknown source file>:<unknown line>
17: typify_impl::convert::<impl typify_impl::TypeSpace>::convert_schema::h7957d2868a66153d
at <unknown source file>:<unknown line>
18: typify_impl::enums::<impl typify_impl::TypeSpace>::external_variant::h48afeda86a50f916
at <unknown source file>:<unknown line>
19: <alloc::vec::into_iter::IntoIter<T,A> as core::iter::traits::iterator::Iterator>::try_fold::he04ab46ccb067b2f
at <unknown source file>:<unknown line>
20: alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter::hac2897b80f5d20cc
at <unknown source file>:<unknown line>
21: typify_impl::convert::<impl typify_impl::TypeSpace>::convert_one_of::h9f45cecdc21c52ca
at <unknown source file>:<unknown line>
22: typify_impl::convert::<impl typify_impl::TypeSpace>::convert_schema_object::h7e4ec5c054bed7e9
at <unknown source file>:<unknown line>
23: typify_impl::convert::<impl typify_impl::TypeSpace>::convert_schema::h7957d2868a66153d
at <unknown source file>:<unknown line>
24: typify_impl::TypeSpace::convert_ref_type::h819ae33afdabc3eb
at <unknown source file>:<unknown line>
25: typify_impl::TypeSpace::add_root_schema::h195960e39adc4593
at <unknown source file>:<unknown line>
26: cargo_typify::convert::hf58d8a5d11ae4f78
at <unknown source file>:<unknown line>
27: cargo_typify::main::hbde4a261aea08d14
at <unknown source file>:<unknown line>
28: std::sys::backtrace::__rust_begin_short_backtrace::h6346c08723a6acad
at <unknown source file>:<unknown line>
29: std::rt::lang_start::{{closure}}::h36c770c741882814
at <unknown source file>:<unknown line>
30: std::rt::lang_start_internal::h5e621041f01a4c14
at <unknown source file>:<unknown line>
31: main<unknown>
at <unknown source file>:<unknown line>
32: __libc_start_main<unknown>
at <unknown source file>:<unknown line>
33: _start<unknown>
at <unknown source file>:<unknown line>
Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
I noticed this same exact LOC was referenced in #816 recently, but I do not see any parallels between the two failure cases.
Please let me know if there are any additional details I can provide. Thanks again for your work on this tool!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the crash with the minimal schema from the issue, then inspect typify-impl/src/type_entry.rs at line 365 and follow the convert_one_of, convert_array, and convert_object paths shown in the backtrace. Add coverage for the titled oneOf/object/array/object schema and confirm generation completes without an unwrap panic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100