Swagger OpenAPI 在多部分请求中描述字符串数组
Swagger OpenAPI describing string array in multipart request
我需要描述一个包含字符串数组的多部分查询。但是我运行陷入了一个问题,在查询中,数组元素被组合成一个字符串而不是单独的字符串项。我正在使用 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"
}
}
}
}
我收到了什么:page: [ 'HOME,LIVE,CHANNELS' ]
我期望的是:page: [ 'HOME','LIVE','CHANNELS' ]
不是很清楚您从哪里接收到 page: [ 'HOME,LIVE,CHANNELS' ]
,但在枚举中看起来您的数组项可能有值。试试这个:
"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"
}
}
}
}
您可以在 adding examples 的规范中查找更多详细信息。
此结构允许您为 page
元素发送多个字符串枚举项,swagger editor 的屏幕截图如下:
我需要描述一个包含字符串数组的多部分查询。但是我运行陷入了一个问题,在查询中,数组元素被组合成一个字符串而不是单独的字符串项。我正在使用 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"
}
}
}
}
我收到了什么:page: [ 'HOME,LIVE,CHANNELS' ]
我期望的是:page: [ 'HOME','LIVE','CHANNELS' ]
不是很清楚您从哪里接收到 page: [ 'HOME,LIVE,CHANNELS' ]
,但在枚举中看起来您的数组项可能有值。试试这个:
"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"
}
}
}
}
您可以在 adding examples 的规范中查找更多详细信息。
此结构允许您为 page
元素发送多个字符串枚举项,swagger editor 的屏幕截图如下: