Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent use of oneOf (from OpenAPI 3) in OpenAPI 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
like image 768
David Meu Avatar asked Dec 10 '25 07:12

David Meu


1 Answers

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.

like image 163
Helen Avatar answered Dec 12 '25 09:12

Helen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!