简体   繁体   中英

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. This way it gets read as a string instead of an array.

I've tried to do the same request in Postman. In Postman the call works, but in swagger it gets put in the parameter section as follows: "[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.

This is the 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.

Your annotations look correct.

Make sure you are using Swagger UI v. 3.26.0 or later. Earlier versions did not support uploading arrays of files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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