'Swagger OpenAPI describing string array in multipart request
I need to describe a multipart query that has an array of strings. But I ran into a problem, in the query, the array elements are combined into one string instead of being separate string items. I am using OpenApi 3.0.3
"multipart/form-data": {
"schema": {
"type": "object",
"required": ["image"],
"properties": {
"image": {
"type": "string",
"format": "base64",
"description": "Banner image `1920x90, 2mb`"
},
"name": {
"type": "string",
"example": "Docs banner",
"description": "Banner name"
},
"link": {
"type": "string",
"description": "Banner link"
},
"page[]": {
"type": "array",
"items": {
"type": "string"
},
"example": ["HOME", "LIVE", "CHANNELS"],
"enum":[
"HOME",
"LIVE",
"CHANNELS",
"ARTISTS",
"DISCOVER",
"MYLIST",
"PROGRAM",
"PLAYER"
],
"description":"Banner pages"
}
}
}
}
What I received: page: [ 'HOME,LIVE,CHANNELS' ]
What I expect: page: [ 'HOME','LIVE','CHANNELS' ]
Solution 1:[1]
It's not very clear where exactly do you receive page: [ 'HOME,LIVE,CHANNELS' ]
, but looks like in enum there are possible values for items of your array. Try this:
"multipart/form-data": {
"schema": {
"type": "object",
"required": ["image"],
"properties": {
"image": {
"type": "string",
"format": "base64",
"description": "Banner image `1920x90, 2mb`"
},
"name": {
"type": "string",
"example": "Docs banner",
"description": "Banner name"
},
"link": {
"type": "string",
"description": "Banner link"
},
"page[]": {
"type": "array",
"items": {
"type": "string",
"enum":[
"HOME",
"LIVE",
"CHANNELS",
"ARTISTS",
"DISCOVER",
"MYLIST",
"PROGRAM",
"PLAYER"
],
"example": "HOME"
},
"example": [ "HOME", "LIVE", "CHANNELS" ],
"description":"Banner pages"
}
}
}
}
You can look for more details at the specification for adding examples.
This structure allows you to send multiple string enum items for page
element, screenshot from swagger editor is below:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |