简体   繁体   English

图像数组是通过参数而不是 formData 发送的,如何更改?

[英]An array of images is being sent through the parameters instead of formData, how to change this?

When I execute a call in the OpenAPI specification it puts an array of files in the parameters section instead of the formData.当我在 OpenAPI 规范中执行调用时,它会在参数部分而不是 formData 中放置一个文件数组。 This way it gets read as a string instead of an array.这样它就被读取为字符串而不是数组。

I've tried to do the same request in Postman.我试图在 Postman 中做同样的请求。 In Postman the call works, but in swagger it gets put in the parameter section as follows: "[object File]" .在 Postman 中,调用有效,但在 swagger 中,它按如下方式放入参数部分: "[object File]" In the browser console I've tried to see what it sends, but that is just the array.在浏览器控制台中,我试图查看它发送的内容,但这只是数组。 So I don't know why it gets converted to a string or why it gets put in parameters instead of formData.所以我不知道为什么它会被转换为字符串,或者为什么它会被放入参数而不是 formData。

This is the openapi yaml:这是 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 as you can see in this picture, the parameter section contains the images.参数如您在此图片中所见,参数部分包含图像。

File/formData the images should be in here. File/formData图像应该在这里。

Your annotations look correct.您的注释看起来正确。

Make sure you are using Swagger UI v. 3.26.0 or later.确保您使用的是 Swagger UI v. 3.26.0 或更高版本。 Earlier versions did not support uploading arrays of files.早期版本不支持上传文件数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM