Swagger-editor: How to define a map in swaggger documentation using json /yaml

Created on 12 Aug 2016  路  10Comments  路  Source: swagger-api/swagger-editor

Swagger File

 # paste your swagger document here
  • Version:
  • Browser/OS:

Issue

question

Most helpful comment

MyUnknownObject:
  type: object
  properties:
    name:
      type: string
    identifier:
      type: string
    isPrimaryCategory:
      type: boolean


RelatedCategories:
  type: object
  additionalProperties:
    $ref: '#/definitions/MyUnknownObject'

All 10 comments

For Example i have to define a below schema -

Map

"relatedCategories": {
"All Accessories": [{
"name": "Luggage",
"url": "/webapp/wcs/stores/servlet/en/marksandspencer/l/men/all-accessories/luggage",
"identifier": "SubCategory_1328543",
"isPrimaryCategory": false
}],
"Luggage": [{
"name": "Hard Suitcases",
"url": "/webapp/wcs/stores/servlet/en/marksandspencer/l/men/luggage/hard-suitcases",
"identifier": "SubCategory_1318283",
"isPrimaryCategory": false
}]
}

Can someone please help me in this.. i am blocked since many days in this. I cant find out the sample of defining a map.

You really have to give details if you want help. This isn't a forensics panel

thanks for reply.

I want to document schema like below in the swagger either in json or yaml format.

"relatedCategories": {
"dynamicKey1": [{
"name": "Luggage",
"identifier": "SubCategory_1328543",
"isPrimaryCategory": false
}],
"dynamicKey2": [{
"name": "Hard Suitcases",
"identifier": "SubCategory_1318283",
"isPrimaryCategory": false
}]
}

Here - relatedCategories is the name of my map in the format of dynamic key names which will be string and its value will be a list .

MyUnknownObject:
  type: object
  properties:
    name:
      type: string
    identifier:
      type: string
    isPrimaryCategory:
      type: boolean


RelatedCategories:
  type: object
  additionalProperties:
    $ref: '#/definitions/MyUnknownObject'

Thanks.

i understood tht for map we will use the object. but this map will have key value pair. where keys will be dynamic. so still the above format of schema will work for me ???

Also with the schema i will generate the models . i think it will genearte "RelatedCategories" as an object and then type casting will be done to make it as a MAP.

@cshar7 please read up on how JSON schema works. What @webron showed defines RelatedCategories as an object, which has keys with the value MyUnknownObject. That's what additionalProperties means.

I know it's a bit late to answer, but anyone viewing this , can refer to this article:
Article Link

You should get a complete picture!

I know it's a bit late to answer, but anyone viewing this , can refer to this article:
Article Link

You should get a complete picture!

Amazing, Just looking for this and there are so many wrong answers available. Thanks a lot

Was this page helpful?
0 / 5 - 0 ratings