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":[]
Firstly, we start by specifying the array of strings in Swagger using YAML notation. In the schema section, we include type: array with items String.
OpenAPI Specification (formerly Swagger Specification) is an API description format for REST APIs. An OpenAPI file allows you to describe your entire API, including: Available endpoints ( /users ) and operations on each endpoint ( GET /users , POST /users ) Operation parameters Input and output for each operation.
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"
},
}
You don't. The idea is that
"photoUrls":[
"string"
]
shows your users that photoUrls
is an array of strings. Otherwise, they will have no way of knowing which datatype is used by the array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With