Ask a Question

How to document an array that is a sequence of specific data types?

SOLVED
nneul
New Member

How to document an array that is a sequence of specific data types?

Note - I've seen the various examples covering alternative data types, such as this discussion:

    https://community.smartbear.com/t5/Swagger-Open-Source-Tools/How-to-document-multiple-data-types-arr...

 

That's not what I'm looking for. I'm wanting to be able to document an existing API (if I could change it, it would be much easier and this would not be an issue, but that's not scope) that has a response of this form:

 

   [  statuscode_integer, statusmsg_string, zero_or_more_strings ]

 

i.e. 

 

  [ 0, "ok", "user1", "user2", "userN" ]

  [ 1, "failed to look up" ]

 

I'm looking for something like a "sequence" type:

 

  type: sequence
    items:
      - oneOf: 
           description: status code
           type: integer
      - oneOf:
          description: status message
          type: string
      - zeroOrMoreOf:
          description: list of matching users
          type: string

 

That obviously isn't valid - but is there any way to represent this without just resorting to a typeless array with an unstructured example?

 

Note - this is just one example for a particular API function. There are others that would be [int,string,{object}] or [int, string, [array]] etc - key is that the response is a sequence of explicit types.

 

1 REPLY 1
HKosova
SmartBear Alumni (Retired)

Hi @nneul,

This should answer your question:

How to define a JSON array with concrete item definition for every index (i.e. a tuple) in OpenAPI?


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
cancel
Showing results for 
Search instead for 
Did you mean: