1

I have a return type which is an array of two elements. The first element is an integer and the second element is an array of dictionary with keys of sql_ident and name. The sql_ident value is an integer and the name value is a string.

I can't figure out how to model this in my response object. So it'd be like:

[
   12,
   [
      {
        "sql_ident" : 17,
        "name" : "Billy Bob"
      },
      {
        "sql_ident" : 935,
        "name" : "Tina Turner"
      } 
   ]
] 
1

1 Answer 1

0

In OpenAPI/Swagger 2.0, array items must be of the same type, so there is no way to precisely model your response. The most you can do is to use a typeless schema for items, which means the items can be anything - numbers, objects, strings, etc. - but you can't specify the exact types for items.

definitions:
  MyResponse:
    type: array
    items: {}

In OpenAPI 3.0, multi-type arrays can be described using oneOf and anyOf:

components:
  schemas:
    MyResponse:
      type: array
      items:
        oneOf:
          - type: integer
          - type: array
            items:
              $ref: "#/components/schemas/MyDictionary"

    MyDictionary:
      type: object
      properties:
        sql_ident:
          type: string
        name:
          type: string
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.