0

I want to write a API that would respond with an array. My OpenAPI description looks like this:

definitions:
  DeviceArray:
    type: array
    items:
      type: string
    example:
      - {"DeviceID": 103609131103,"NetworkName": "nzp-20007-gnd-rt-01","RelativeName": "NZP-20007-GND-RT-01.PST.SYTECNMS.NET","Type": null}
      - {"DeviceID": 105621398103,"NetworkName": "nzp-20007-gnd-as-01","RelativeName": "NZP-20007-GND-AS-01.PST.SYTECNMS.NET","Type": null}
      - {"DeviceID": 122403148102,"NetworkName": null,"RelativeName": "BEAS/U_NTU_001","Type": "NTU"}
      - {"DeviceID": 165002297102,"NetworkName": null,"RelativeName": "BEAS/G_HSNS SDP_001","Type": "Alcatel MSAP"}
      - {"DeviceID": 165002320102,"NetworkName": "10.6.194.126","RelativeName": "BEAS/G_ONEA1424X_001","Type": "OneAccess IAD/Router"}
      - {"DeviceID": 160885080102,"NetworkName": null,"RelativeName": "BEAS/U_CISCO_1921_001","Type": "Cisco Packet Switch"}

But the response I get is:

[
""
]

How do I solve this problem?

Darrel Miller
  • 139,164
  • 32
  • 194
  • 243
陈怀宇
  • 1
  • 2
  • What do you mean by "response I get" - the actual response from your API, the rendered model examples, something else? Btw, you are using an old version of the editor, try http://editor.swagger.io. – Helen Nov 10 '17 at 08:17

1 Answers1

1

This is not type: string obviously, you need to set the type to type: object and either define it directly:

type: array
items:
  type: object
  properties:
    DeviceID:
      type: string
    NetWorkName:
      type: string
    RelativeName:
      type: string

or reference an object if you have already defined it:

type: array
items:
  $ref: '#/yourObjectReference'
zakaria amine
  • 3,412
  • 2
  • 20
  • 35