How to define an object with arbitrary keys, but fixed key and value types?

691 Views Asked by At

How would you define an object in OpenAPI 3.x when the keys can be any value, but always a specific format, with a similar requirement for values?

For example the following structure

keyValues: {"a": ["1", "2"], "b": ["3"]}

might be defined as

properties:
  keyValues:
    type: object
    keys:
      type: string
    values:
      type: array
      items:
        type: string
1

There are 1 best solutions below

0
On

I was able to solve this using additionalProperties. The string type of the object keys seems to be implicit since JSON only supports strings for keys.

keyValues:
  description: "A `string:[string]` object of key-values."
  type: object
  additionalProperties:
    type: array
    items:
      type: string