通过参数而不是 formData 发送图像数组,如何更改它?
An array of images is being sent through the parameters instead of formData, how to change this?
当我执行 OpenAPI 规范中的调用时,它会在参数部分而不是 formData 中放置一个文件数组。这样它就被读取为字符串而不是数组。
我尝试在 Postman 中执行相同的请求。在 Postman 中,调用有效,但在 swagger 中,它被放入参数部分,如下所示:"[object File]"
。
在浏览器控制台中,我试图查看它发送的内容,但那只是数组。所以我不知道为什么它被转换为字符串或者为什么它被放入参数而不是 formData。
这是 openapi yaml:
/**
* @openapi
* /routes:
* post:
* summary: Create a route
* tags:
* - Routes
* security:
* - CustomToken: []
* requestBody:
* content:
* multipart/form-data:
* schema:
* type: object
* required:
* - images
* - track
* properties:
* images:
* type: array
* minItems: 1
* maxItems: 3
* items:
* type: string
* format: binary
* track:
* type: string
* format: binary
* parameters:
* - name: name
* description: Name of the route.
* in: query
* required: true
* schema:
* type: string
* example: Utrecht naar Den Bosch
* - name: description
* description: Description of the route.
* in: query
* required: true
* schema:
* type: string
* example: Een route die langs de prachtigste punten gaat op de route van utrecht naar Den Bosch.
* - name: price
* description: The price of the route using the purchasable coins as the currency.
* in: query
* required: true
* schema:
* type: integer
* minimum: 0
* example: 1
* - name: rating
* description: The rating the route has been given.
* in: query
* required: false
* schema:
* type: integer
* minimum: 1
* maximum: 5
* example: 5
* - name: tags
* description: The tags that define if the route contains dikes, forests, mountains or cities. To select multiple values hold ctrl and click on the values you want.
* in: query
* required: true
* schema:
* type: array
* minItems: 1
* maxItems: 4
* uniqueItems: true
* items:
* type: string
* enum:
* - Dike
* - Forest
* - Mountain
* - City
* example:
* - Dike
* - Forest
* responses:
* 200:
* description: succesfully created a route
*/
Parameters 正如您在这张图片中看到的,参数部分包含图像。
File/formData 图片应该在这里。
您的注释看起来是正确的。
确保您使用的是 Swagger UI v. 3.26.0 或更高版本。早期版本 did not support 正在上传文件数组。
当我执行 OpenAPI 规范中的调用时,它会在参数部分而不是 formData 中放置一个文件数组。这样它就被读取为字符串而不是数组。
我尝试在 Postman 中执行相同的请求。在 Postman 中,调用有效,但在 swagger 中,它被放入参数部分,如下所示:"[object File]"
。
在浏览器控制台中,我试图查看它发送的内容,但那只是数组。所以我不知道为什么它被转换为字符串或者为什么它被放入参数而不是 formData。
这是 openapi yaml:
/**
* @openapi
* /routes:
* post:
* summary: Create a route
* tags:
* - Routes
* security:
* - CustomToken: []
* requestBody:
* content:
* multipart/form-data:
* schema:
* type: object
* required:
* - images
* - track
* properties:
* images:
* type: array
* minItems: 1
* maxItems: 3
* items:
* type: string
* format: binary
* track:
* type: string
* format: binary
* parameters:
* - name: name
* description: Name of the route.
* in: query
* required: true
* schema:
* type: string
* example: Utrecht naar Den Bosch
* - name: description
* description: Description of the route.
* in: query
* required: true
* schema:
* type: string
* example: Een route die langs de prachtigste punten gaat op de route van utrecht naar Den Bosch.
* - name: price
* description: The price of the route using the purchasable coins as the currency.
* in: query
* required: true
* schema:
* type: integer
* minimum: 0
* example: 1
* - name: rating
* description: The rating the route has been given.
* in: query
* required: false
* schema:
* type: integer
* minimum: 1
* maximum: 5
* example: 5
* - name: tags
* description: The tags that define if the route contains dikes, forests, mountains or cities. To select multiple values hold ctrl and click on the values you want.
* in: query
* required: true
* schema:
* type: array
* minItems: 1
* maxItems: 4
* uniqueItems: true
* items:
* type: string
* enum:
* - Dike
* - Forest
* - Mountain
* - City
* example:
* - Dike
* - Forest
* responses:
* 200:
* description: succesfully created a route
*/
Parameters 正如您在这张图片中看到的,参数部分包含图像。
File/formData 图片应该在这里。
您的注释看起来是正确的。
确保您使用的是 Swagger UI v. 3.26.0 或更高版本。早期版本 did not support 正在上传文件数组。