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

Content-type for POST endpoints with multipart/form-data does not work since v2.4.0 #2621

Closed
maxdobler opened this issue Jun 12, 2024 · 5 comments

Comments

@maxdobler
Copy link

Describe the bug

Sind version 2.4.0 POST Endpoints with content-type multipart/form-data are not generated properly in open api spec. This leads to missing content-type in swagger ui webpage.

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using?
    3.3.0

  • What modules and versions of springdoc-openapi are you using?
    springdoc-openapi-starter-webmvc-ui:2.4.0

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

  • Provide with a sample code (HelloController) or Test that reproduces the problem
    POST Endpoint which accepts multipart/form-data. Use [sprin](springdoc-openapi-starter-webmvc-ui in version 2.4.0 or 2.5.0
    @PostMapping(produces = APPLICATION_JSON_VALUE, consumes = MULTIPART_FORM_DATA_VALUE)

Go to swagger-ui webpage and the content-type is missing for the POST Endpoint.

Expected behavior

Adds content-type multipart/form-data to POST Endpoints in OpenApi docs

Screenshots
Open Api Diff:
image

Swagger UI in v2.3.0
Screenshot 2024-06-12 at 18 13 45

Swagger UI in 2.4.0 / 2.5.0
Screenshot 2024-06-12 at 18 14 50

Additional context

@bnasslahsen
Copy link
Contributor

Not reproducible.
Feel free to provide a Minimal, Reproducible Example - with HelloController that reproduces the problem.

This ticket will be closed, but can be reopened if your provide the reproducible sample.

@maxdobler
Copy link
Author

maxdobler commented Jun 18, 2024

I created an example to reproduce the bug: https://github.com/maxdobler/springdoc-example

I noticed that it makes a difference if the UploadDto has the @Valid annotation. With the annotation, the swagger-ui displays the dropdown an displayes the right content-type.

If you change the springdoc version to 2.5.0 the consuming content-type is not displayed in the swagger-ui.

Please reopen this issue.

@maxdobler
Copy link
Author

@bnasslahsen Please reopen this issue

@bnasslahsen bnasslahsen reopened this Jun 18, 2024
@bnasslahsen
Copy link
Contributor

@maxdobler,

This behavior was a bug in previous versions. In version 2.5.0, the workaround is to explicitly declare @RequestBody.

  @Operation(summary = "Upload new content", description = "Upload test content")
  @PostMapping(produces = APPLICATION_JSON_VALUE, consumes = MULTIPART_FORM_DATA_VALUE)
  HelloDto uploadContent(@RequestBody HelloUploadDto contentUploadDto) throws IOException;

@maxdobler
Copy link
Author

Oh I see, thank you for the fast Feedback. It now works with @RequestBody. 👍

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

No branches or pull requests

2 participants