Search code examples
jsonnode.jsformsswagger-editor

Swagger Editor - declare request json body fields as formData, but send these as json


I'm using latest Swagger Editor, and my server api accepted just json body requests, but if you declare parameter with formData docs will be clearly for developer. My question: How to I can declare parameter as formData but when try it send json body request. I tried Swagger Editor oldest version 2.9.6 and declare parameter as formData and declare "produces" and "consumes" as "application/json" then if i try it on the editor works, but if I generate nodejs-server and try it will send content-type is form-url-encoding, look to following screenshots:

enter image description here enter image description here

If I generate nodejs-server, not works:

enter image description here


Solution

  • How to I can declare parameter as formData but when try it send json body request.

    You can't. The API specification is a contract between the client and server and is supposed to precisely define the server behavior. If the server expects JSON, the specification must use in: body parameters and not in: formData. If the server works in one way and the spec states another way, it's useless.

    If you want to use formData parameters in the spec, change your server to accept form data and write the spec accordingly.