Primitive RequestPart parameters generate incorrect Swagger Model
See original GitHub issueMethod parameters of the following form will generate incorrect parameters in Swagger 2. Non-validating parsers will not immediately choke on it, but code generators like swagger-codegen or openapi-codegen will.
public SomeReturnValue webMethod(
@RequestPart("file") MultipartFile file,
@RequestPart("description") String description) {
...
The generated spec will look like this:
{
"name": "file",
"in": "formData",
"description": "file",
"required": true,
"type": "file"
},
{
"in": "formData",
"name": "description",
"description": "description",
"required": true,
"schema": {
"type": "string"
}
}
This is a problem because parameters with in=formData
can’t have a schema, only a type is allowed. The spec doesn’t allow formData parameters to be anything other than a primitive.
The expected JSON should be:
{
"name": "file",
"in": "formData",
"description": "file",
"required": true,
"type": "file"
},
{
"in": "formData",
"name": "description",
"description": "description",
"required": true,
"type": "string"
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Primitive RequestPart parameters generate incorrect Swagger Model
Method parameters of the following form will generate incorrect parameters in Swagger 2. Non-validating parsers will not immediately choke on it, ...
Read more >Wrong @RequestPart name generated in spring server...
Hello Swagger Folks, I have the following parameter definition in a multipart/form-data request method: "/kupo/v1/UploadDateiStream": {
Read more >Multipart Requests - Swagger
Multipart requests combine one or more sets of data into a single body, separated by boundaries. You typically use these requests for file...
Read more >Swagger: Spring MVC models in GET request - Stack Overflow
Swagger is just a documentation. It has nothing to do with generating the controller method with two primitive parameters. Spring basically ...
Read more >[#SCB-736] generate default value to swagger for primitive ...
@GetMapping(path = "test") public String test(int i, boolean b) { return "" + i + b; } request without any query parameter should...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We have the same problem in v2.9.2, any update on this?
I’m running springfox at version 2.9.2
When you build a custom ApiDescription with the ParametersBuilder as follow:
Generates the same broken JSON for formData:
The expected valid JSON is: