How to define empty array in swagger

smftr picture smftr · Apr 14, 2015 · Viewed 12.2k times · Source

I know how to make array of string data in swagger like this:

"photoUrls" : {
    "type":"array",
    "items":{
         "type":"string"
    }
}

It will show output like this:

"photoUrls":[
    "string"
]

How to make output like this?:

"photoUrls":[]

Answer

Helen picture Helen · Jun 28, 2017

You can specify an empty array [] as an example for your array schema. This will override the default examples values generated by Swagger UI.

"photoUrls" : {
    "type":"array",
    "items":{
         "type":"string"
    },
    "example": []
}

Ron's answer is more user-friendly for your users. Consider using some real-world example values instead:

"photoUrls" : {
    "type":"array",
    "items":{
         "type":"string",
         "example": "http://example.com/images/pet.png"
    },
}