5

I wish to POST an array containing a variable number of strings, such as

["string1", "string2", ... "stringN"]

My present OpenAPI document defines it this way:

schema:
  type: array
    items:
      description: networkIds
      type: string

Is this the correct way to code to the OpenAPi v3 spec, or is there a more precise way to indicate one or more strings within the array?

Mike
  • 676
  • 1
  • 8
  • 17

1 Answers1

16

The indentation is wrong – type and items must be on the same level.

If the array cannot be empty and always has at least 1 item, you can add minItems: 1 as an additional constraint. If all items must be unique, add uniqueItems: true.

schema:
  type: array
  items:
    description: networkIds
    type: string
  minItems: 1
Helen
  • 87,344
  • 17
  • 243
  • 314
  • Thank you, Helen. That answers my question. And, yes, I should have caught the indentation problem before submitting the question. – Mike Dec 20 '17 at 22:14
  • This is also a blog I referred to: https://www.baeldung.com/swagger-body-array-of-strings – Aniket Apr 08 '22 at 11:36