question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Primitive RequestPart parameters generate incorrect Swagger Model

See original GitHub issue

Method 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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
spylightadmincommented, Jun 12, 2019

We have the same problem in v2.9.2, any update on this?

1reaction
msangalscommented, Feb 27, 2019

I’m running springfox at version 2.9.2

When you build a custom ApiDescription with the ParametersBuilder as follow:

new ParameterBuilder()
    .name("password")
    .parameterType("formData")
    .required(true)
    .modelRef(new ModelRef("string"))
    .build()

Generates the same broken JSON for formData:

                   {
                        "in": "formData",
                        "name": "password",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }

The expected valid JSON is:

                   {
                        "in": "formData",
                        "name": "password",
                        "required": true,
                        "type": "string"
                    }
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found