0

I have an object that looks like this (two-dimensional map of numbers):

{ 
  10: {
     12000: 10000000,
     14000: 23432423,
  },

  20: {
      35000: 6747665,
      45000: 54635454
  } 
}

What is the schema definition for this in swagger?

Thanks.

Mister_L
  • 2,469
  • 6
  • 30
  • 64

1 Answers1

0

Unfortunately, JSON only allows strings as key names (cf. Using number as "index" (JSON)), the provided example should then be like this:

{ 
  "10": {
    "12000": 10000000,
    "14000": 23432423,
  },

  "20": {
      "35000": 6747665,
      "45000": 54635454
  } 
}

And in OpenAPI (fka. Swagger) specification, you can define maps but the type of the key is implicit and is supposed to be string (just like with JSON).

When describing an object which is a <string, something> map, you have to use additionalProperties to describe something.

Here are two ways of describing a schema corresponding to a <string, <string, integer>> map:

swagger: '2.0'

info:
  version: 1.0.0
  title: Maps

paths: {}

definitions:
  # a <string, <string, integer>> map using 
  # inline definition of <string, integer> map item
  TwoDimensionMap:
    additionalProperties:
      additionalProperties:
        type: integer
        format: int64

  # a <string, integer> map
  SimpleMap:
    additionalProperties:
      type: integer
      format: int64

  # a <string, <string, integer>> map using 
  # $ref definition of <string, integer> map item
  TwoDimensionMapWithRef:
    additionalProperties:
      $ref: '#/definitions/SimpleMap'

TwoDimensionMap is a full inline definition and TwoDimensionMapWithRef describe exactly the same thing but using a reference to another definition for the inner <string, integer> map.

Community
  • 1
  • 1
Arnaud Lauret
  • 4,961
  • 1
  • 22
  • 28