How to define an empty array in swagger

I know how to make an array of string data in swagger as follows:

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

It will display the output as follows:

 "photoUrls":[ "string" ] 

How to conclude as follows:

 "photoUrls":[] 
+5
source share
2 answers

Not. The idea is that

 "photoUrls":[ "string" ] 

shows your users that photoUrls is an array of strings. Otherwise, they will not be able to find out what type of data the array is using.

+4
source

You can specify an empty array [] as an example for your array scheme. This will override the default sample values ​​created by the Swagger user interface.

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

But Ron answer is more user friendly. Consider using some real example values:

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

All Articles