Skip to content

enum & allOf #853

@jayvdb

Description

@jayvdb

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 discord/discord-api-spec#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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions