2

How can I adjust this snippet with oneOf to the equivalent OpenAPI 2.0 version?

  formats:
    type: array
    description: Possible parameter format.
    items:
      oneOf:
      - type: string
      - type: object
        description: Matched alias formats
        properties:
          representation:
            type: array
            description: Alias format representations
            items:
              type: string
          match_multiple:
            type: boolean
            optional: true
          display:
            type: string
            description: Display string of alias format
Helen
  • 87,344
  • 17
  • 243
  • 314
David Meu
  • 1,527
  • 9
  • 14
  • Related: [How to define a mixed-type array (with different element types) in OpenAPI 2.0?](https://stackoverflow.com/q/38690802/113116), [Swagger 2.0 anyOf](https://stackoverflow.com/q/34863160/113116) – Helen Nov 25 '21 at 16:00

1 Answers1

2

In OpenAPI 2.0, the most you can do is to use a typeless schema {} for items, which means the items can be anything except null – numbers, objects, strings, etc. You cannot specify the exact types for items, but you can add an example of an array with different item types.

formats:
  type: array
  items: {}  # <--- means "any type" (except null)

  example:
    # example of a string item
    - test

    # example of an object item
    - representation: [one, two]
      match_multiple: false
      display: something

Note: Typeless schema {} can only be used in OAS2 body parameters and response schemas. Path, header and form parameters require a primitive type for array items.

Helen
  • 87,344
  • 17
  • 243
  • 314