Skip to content

Support @Parameter annotation attached to @RequestPart, for several @RequestParts #674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ajeans opened this issue May 15, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@ajeans
Copy link

ajeans commented May 15, 2020

Is your feature request related to a problem? Please describe.
Using a Rest Controller from spring-boot, I want to annotate the parameter names and descriptions of several multi-part parts in a request

  • A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
    As far as I can see, only one @Parameter tag is read from all the @Parameter attached to the request parts

A reproducer is:

  @Operation(summary = "Multiple files and JSON payloads as multi part request")
  @PostMapping(
      value = "multi",
      consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
      produces = MediaType.TEXT_PLAIN_VALUE)
  public String multiFilesInMultiPart(
      @RequestPart("params")
          @Parameter(
              description = "This is the configuration",
              content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE))
          final JsonRequest jsonRequest,
      @RequestPart(value = "file1", required = false) @Parameter(description = "This is file1")
          final MultipartFile file1,
      @RequestPart(value = "file2", required = false) @Parameter(description = "This is file2")
          final MultipartFile file2) {
    return "Hello World " + jsonRequest.getName();
  }

This is valid spring boot, deploys properly and can be queried with

curl -X POST "http://localhost:8080/multi" -H  "accept: text/plain" -H  "Content-Type: multipart/form-data" -F 'params={"name": "Bob"}'
Hello world Bob
  • What is the actual result using OpenAPI Description (yml or json)?
curl http://localhost:8080/v3/api-docs | jq '.paths | {"/multi"}'

The corresponding yml shows that only one @Parameter description was processed,

{
  "/multi": {
    "post": {
      "tags": [
        "foo-controller"
      ],
      "summary": "Multiple files and JSON payloads as multi part request",
      "operationId": "multiFilesInMultiPart",
      "requestBody": {
        "description": "This is file2",
        "content": {
          "multipart/form-data": {
            "schema": {
              "type": "object",
              "properties": {
                "params": {
                  "$ref": "#/components/schemas/JsonRequest"
                },
                "file1": {
                  "type": "string",
                  "format": "binary"
                },
                "file2": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          }
        }
      },
      "responses": {
        "400": {
          "description": "Invalid request from client",
          "content": {
            "*/*": {
              "schema": {
                "$ref": "#/components/schemas/ErrorDto"
              }
            }
          }
        },
        "404": {
          "description": "No Handler for request",
          "content": {
            "*/*": {
              "schema": {
                "$ref": "#/components/schemas/ErrorDto"
              }
            }
          }
        },
        "500": {
          "description": "Generic server error",
          "content": {
            "*/*": {
              "schema": {
                "$ref": "#/components/schemas/ErrorDto"
              }
            }
          }
        },
        "415": {
          "description": "Unsupported response media type",
          "content": {
            "*/*": {
              "schema": {
                "$ref": "#/components/schemas/ErrorDto"
              }
            }
          }
        },
        "200": {
          "description": "OK",
          "content": {
            "text/plain": {
              "schema": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}

Describe the solution you'd like

  • A clear and concise description of what you want to happen.

I would like each part: params, file1, file2 to get assigned the description corresponding to what was declared in the @Parameter tag.

  • What is the expected result using OpenAPI Description (yml or json)?

Not sure, I assume a something like the following, but cannot say whether this is valid according to the spec.

          "multipart/form-data": {
            "schema": {
              "type": "object",
              "properties": {
                "params": {
                  "$ref": "#/components/schemas/JsonRequest",
                  "description": "This is the configuration"
                },
                "file1": {
                  "type": "string",
                  "format": "binary",
                  "description": "This is file1"
                },
                "file2": {
                  "type": "string",
                  "format": "binary",
                  "description": "This is file2"
                }
              }
            }
          }

Describe alternatives you've considered

  • A clear and concise description of any alternative solutions or features you've considered.

I tried to add the description of @RequestPart in a @Parameter attached directly (as described), I also tried to attach it through @Operation:parameters with no luck.

Additional context

  • Add any other context or screenshots about the feature request here.

The swagger ui is as follows for the reference endpoint
image

@ajeans
Copy link
Author

ajeans commented May 17, 2020

Thanks a lot @bnasslahsen , this seems to work well and swagger-ui is now looking good. 👍

@ajeans
Copy link
Author

ajeans commented Oct 31, 2021 via email

@bnasslahsen bnasslahsen added the enhancement New feature or request label Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants