oxidecomputer / oxidecomputer/typify

enum & allOf

Open
#853 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
898
Forks
114
Avg merge
4h 18m
Merged PRs (30d)
14

Description

https://github.com/discord/discord-api-spec/blob/main/specs/openapi.json contains a lot of schemas like this.

    RoleSelectDefaultValueResponse:
      type: object
      properties:
        type:
          type: string
          enum:
          - role
          allOf:
          - $ref: '#/components/schemas/SnowflakeSelectDefaultValueTypes'
        id:
          $ref: '#/components/schemas/SnowflakeType'
      required:
      - type
      - id
...
    SnowflakeSelectDefaultValueTypes:
      type: string
      oneOf:
      - title: USER
        const: user
      - title: ROLE
        const: role
      - title: CHANNEL
        const: channel

Note I am using https://github.com/sciguy16/openapi31to30 to make it compatible with progenitor/typify

I checked the openapi doc using https://github.com/daveshanley/vacuum , and while there were a lot of warnings, they didnt appear to relate to the above https://github.com/discord/discord-api-spec/issues/41

I don't see any prohibition on using enum & allOf in this way...?
As I understand it, the addition of allOf SnowflakeSelectDefaultValueTypes is redundant, as SnowflakeSelectDefaultValueTypes is a superset of the enum, and could be simply discarded.

typify on main fails at https://github.com/oxidecomputer/typify/blob/7d61436/typify-impl/src/defaults.rs#L320

  thread 'main' panicked at /Users/jayvdb/rust/typify/typify-impl/src/defaults.rs:320:47:
  internal error: entered unreachable code
  stack backtrace:
     0: __rustc::rust_begin_unwind
               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:697:5
     1: core::panicking::panic_fmt
               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/panicking.rs:75:14
     2: core::panicking::panic
               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/panicking.rs:145:5
     3: typify_impl::defaults::<impl typify_impl::type_entry::TypeEntry>::validate_value
     4: typify_impl::convert::<impl typify_impl::TypeSpace>::convert_typed_enum::{{closure}}
     5: core::iter::traits::iterator::Iterator::try_for_each::call::{{closure}}
     6: core::iter::traits::iterator::Iterator::try_fold
     7: core::iter::traits::iterator::Iterator::try_for_each
     8: typify_impl::convert::<impl typify_impl::TypeSpace>::convert_typed_enum
     9: typify_impl::convert::<impl typify_impl::TypeSpace>::convert_schema_object
    10: typify_impl::convert::<impl typify_impl::TypeSpace>::convert_schema
    11: typify_impl::TypeSpace::id_for_schema
    12: typify_impl::structs::<impl typify_impl::TypeSpace>::struct_property
    13: typify_impl::structs::<impl typify_impl::TypeSpace>::struct_members::{{closure}}
    14: core::iter::adapters::filter_map::filter_map_try_fold::{{closure}}
    15: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
    16: core::iter::traits::iterator::Iterator::try_fold
    17: <core::iter::adapters::chain::Chain<A,B> as core::iter::traits::iterator::Iterator>::try_fold
    18: <core::iter::adapters::filter_map::FilterMap<I,F> as core::iter::traits::iterator::Iterator>::try_fold
    19: <core::iter::adapters::GenericShunt<I,R> as core::iter::traits::iterator::Iterator>::try_fold
    20: <core::iter::adapters::GenericShunt<I,R> as core::iter::traits::iterator::Iterator>::next
    21: alloc::vec::Vec<T,A>::extend_desugared
    22: <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend
    23: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter
    24: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
    25: <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter
    26: core::iter::traits::iterator::Iterator::collect
    27: <core::result::Result<V,E> as core::iter::traits::collect::FromIterator<core::result::Result<A,E>>>::from_iter::{{closure}}
    28: core::iter::adapters::try_process
    29: <core::result::Result<V,E> as core::iter::traits::collect::FromIterator<core::result::Result<A,E>>>::from_iter
    30: core::iter::traits::iterator::Iterator::collect
    31: typify_impl::structs::<impl typify_impl::TypeSpace>::struct_members
    32: typify_impl::convert::<impl typify_impl::TypeSpace>::convert_object
    33: typify_impl::convert::<impl typify_impl::TypeSpace>::convert_schema_object
    34: typify_impl::convert::<impl typify_impl::TypeSpace>::convert_schema
    35: typify_impl::TypeSpace::convert_ref_type
    36: typify_impl::TypeSpace::add_ref_types_impl
    37: typify_impl::TypeSpace::add_ref_types
    38: progenitor_impl::Generator::generate_tokens

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with typify-impl/src/defaults.rs around line 320, then follow the convert_typed_enum and convert_schema_object frames in the reported backtrace. Reproduce generation using the linked Discord OpenAPI schema and the sciguy16/openapi31to30 conversion. Done means enum combined with allOf no longer reaches the unreachable panic and the schema is handled consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, rust
Domain
compilers, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.