Swagger Editor :: Model Empty Array in Response Object

1,564 views
Skip to first unread message

Dave

unread,
Jan 10, 2016, 10:15:59 PM1/10/16
to Swagger
Hi Group,

I'm working on modeling an existing API at my company.

A long time ago, the decision was made to provide a JSON response similar to the following:

{
    "a": true,
    "b": "",
    "c": 0,
    "userid": "d012345234",
    "timestamp": 1452481936,
    "request": "store-data-in-cloud",
    "datatype": "json",
    "data": []
}

I can't figure out how to model the "data" array in the Swagger Editor.

The closest I've come is:

data:
        type: array
        description: lorem
        items:
          type: object
          minimum: 0
          maximum: 0

Which of course results in:

{
  "a": true,
  "b": "string",
  "c": 0,
  "userid": "string",
  "timestamp": 0,
  "request": "string",
  "datatype": "string",
  "data": [
    {}
  ]
}

Am I trying to do something that's not currently possible?

Michael P

unread,
Jan 11, 2016, 10:23:08 AM1/11/16
to Swagger
Dave,

An object is represented as '{..}'. Is your data field supposed to take objects of type String?

Dave

unread,
Jan 11, 2016, 11:31:45 AM1/11/16
to Swagger
Hi Michael,

Thanks for the help!

The data field (for this particular response) will be an empty array. There are other endpoints in the solution that do populate the data field with strings.

We tried modeling in the editor as:

data:
        type: array
        description: lorem ipsum dolor sit
        items:

The editor would not accept this though.

It seems maybe the editor doesn't allow modeling an array that will always be empty?

tony tam

unread,
Jan 11, 2016, 11:38:04 AM1/11/16
to swagger-sw...@googlegroups.com
The array with type `object` and minimum/maximum of 0 doesn’t make sense.  If you’re using a primitive (ie. string, etc.) then use this:

type: array
  items:
    type: string

If it’s an object, you can use

type: array
  items:
    type: object

but the data will look like an object {…}

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages