Skip to content
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

Query parameter part of request body in controller with MultiPartFile #1793

Closed
Nikos410 opened this issue Aug 17, 2022 · 1 comment
Closed

Comments

@Nikos410
Copy link

Describe the bug
A controller that consumes a MultipartFile and has a query parameter generates an incorrect spec.

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using? 2.7.2
  • What modules and versions of springdoc-openapi are you using? springdoc-openapi-ui:1.6.10
  • What is the actual and the expected result using OpenAPI Description (yml or json)?
    Expected (Generated spec with version 1.5.10):
    "/api/v1/file-upload": {
        "post": {
          "operationId": "uploadFile",
          "parameters": [
            {
              "name": "targetDirectory",
              "in": "query",
              "required": true,
              "schema": {
                "type": "string"
              }
            }
          ],
          "requestBody": {
            "content": {
              "multipart/form-data": {
                "schema": {
                  "required": [
                    "file"
                  ],
                  "type": "object",
                  "properties": {
                    "file": {
                      "type": "string",
                      "format": "binary"
                    }
                  }
                }
              }
            }
          }
          [...]
        }
      },
    Actual:
      "/api/v1/file-upload": {
        "post": {
          "operationId": "uploadFile",
          "requestBody": {
            "content": {
              "multipart/form-data": {
                "schema": {
                  "required": [
                    "file"
                  ],
                  "type": "object",
                  "properties": {
                    "file": {
                      "type": "string",
                      "format": "binary"
                    },
                    "targetDirectory": {}
                  }
                }
              }
            }
          }
          [...]
        }
      },
  • Provide with a sample code (HelloController) or Test that reproduces the problem
@RestController
@RequestMapping("/api/v1/file-upload")
public class FileUploadController {

	@PostMapping(consumes = {"multipart/form-data"})
	@ResponseStatus(HttpStatus.NO_CONTENT)
	@PreAuthorize(UPLOAD_FILES)
	public void uploadFile(
	        @RequestParam("targetDirectory") String targetDirectory,
	        @RequestParam("file") MultipartFile multipartFile)
	        throws IOException {

	}
}

Expected behavior

  • targetDirectory should be a query parameter, not part of the request body

CC @Digirik

@bnasslahsen
Copy link
Contributor

@Nikos410,

This is not a bug. But is an expected behavior.
Both representations are correct. A property will be introduced to accept both.

Starting from next release 1.6.11 you can use:

springdoc.default-support-form-data=false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants