Skip to content

Accept an array of types in Schema.type #660

Description

@madjar

Currently, when the decoder encounters a schema whose type is an array (such as ["string", "null"]) is ignores the object and leave it entirely as is.


Continuing on my streak of implementing the bits of OpenAPI 3.1.0 that I encounter on the schema I'm working with, I'd like to handle cases where the Schema.type is an array of types. In my case, it's exclusively [something, "null"], but if can be anything. According to some sources, it looks like the expected behaviour is that the schema object can contain any restriction field that would make sense for any of the types in the array. The expected behaviour is similar to a corresponding anyOf.

I've only been looking at the decoding so far, and I got it working by merging all the various clauses that deal with various possibilities into one big function that convert any field it finds. This works well, except for one piece of logic which depends on the actual type: properties should be %{} instead of nil if the type is/contains object.

This solution isn't very satisfying, so I'll sleep on it, see if I can figure a nicer way. The current progress lives at #659.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions