Forum Discussion

Nidhin's avatar
Nidhin
New Contributor
2 years ago

Not sending req to server when using multipart/form-data: in swaagger UI

I am using swagger ui to make documentation of API. I am trying to post some data to the server and the server is not getting any requests from swagger. I tried to remove the content part and its working but when I add the content part it does not send the request. its keeps on loading

```

/admin/product:
post:
tags:
- Admin
summary: If admin, Add a product
parameters:
requestBody:
content:
multipart/form-data:
schema:
type: object
required:
- name
- price
- description
- collectionId
- stock
- brand
- photos
properties:
name:
type: string
required: true
price:
type: number
required: true
description:
type: string
required: true
collectionId:
type: string
required: true
stock:
type: number
required: true
brand:
type: string
required: true
photos:
in: formData
description: The uploaded photos
type: file
format: binary
 
responses:
200:
description: All good success
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
product:
type: object
properties:
_id:
type: string
name:
type: string
price:
type: number
description:
type: string
collectionId:
type: string
brand:
type: string
ratings:
type: number
numberOfReviews:
type: number
user:
type: string
photos:
type: array
items:
type: object
properties:
id:
type: string
secure_url:
type: string
reviews:
type: array
items:
type: object
properties:
id:
type: string
comment:
type: string
user:
type: string
name:
type: string
rating:
type: number
400:
description: Bad request
500:
description: internal server error
 

```

  • Hi Nidhin ,

     

    It's a little hard to read your definition as the format came out a bit wonky.

    But it does look like you're adding `requestyBody` underneath `parameters`? 

     

    OpenAPI 3.0+ has moved request bodies into their own field, and not in parameters (like it was in Swagger 2.0). 

    Take a look at https://swagger.io/docs/specification/describing-request-body/ for further docs around that. 

     

  • HI ponelat , 

        Thank you so much  for your replai . I removed the parameter field and its working fine . Thank you for your help

  • Hi Nidhin ,

     

    It's a little hard to read your definition as the format came out a bit wonky.

    But it does look like you're adding `requestyBody` underneath `parameters`? 

     

    OpenAPI 3.0+ has moved request bodies into their own field, and not in parameters (like it was in Swagger 2.0). 

    Take a look at https://swagger.io/docs/specification/describing-request-body/ for further docs around that. 

     

    • Nidhin's avatar
      Nidhin
      New Contributor

      HI ponelat , 

          Thank you so much  for your replai . I removed the parameter field and its working fine . Thank you for your help