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.

Doesn't support @RequestPart CustomObject in Spring Boot

See original GitHub issue

Please take the time to search the repository, if your question has already been asked or answered.

  • What version of the library are you using?
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.2.RELEASE</version>
    <relativePath/>
  </parent>

<dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-boot-starter</artifactId>
      <version>3.0.0</version>
</dependency>

What kind of issue is this?

  • Bug report. If you’ve found a bug, spend the time to write a failing test. Bugs with tests or steps to reproduce get fixed faster. Here’s an example: https://gist.github.com/swankjesse/6608b4713ad80988cdc9
    • spring xml/java config that is relevant
    • springfox specific configuration if it makes sense
    • include any output you’ve received; logs, json snippets etc.; and what the expected output should be
    • if you have a repo that demonstrates the issue for bonus points! See this example

Please do consider starring this repository if you do like this project and find it useful.

Please take a look at this api which is automatically converted to a form data with 3 properties:

  • InteractionQuestionRequest request
  • MultipartFile question-image
  • MultipartFile winner-image
@PostMapping(value = ServicePath.QUESTIONS)
  public ResponseEntity<RestResult<InteractionQuestionDTO>> createQuestion(
      @RequestPart(name = "request") InteractionQuestionRequest request,
      @RequestPart(name = "question-image", required = false) MultipartFile questionImage,
      @RequestPart(name = "winner-image", required = false) MultipartFile winnerImage) {
    RestResult<InteractionQuestionDTO> result = new RestResult<>();
    result.setData(interactionService.createQuestion(request, questionImage, winnerImage));
    result.setStatus(RestResult.STATUS_SUCCESS);
    result.setMessage(resourceBundle.getMessage("msg.data.get.success"));
    return new ResponseEntity<>(result, HttpStatus.OK);
  }

Springfox swagger successfully display the MultipartFile with no error but any other objects seems to not be parsed into swagger. Example: image

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
vodukucommented, Apr 8, 2021

Here is my config:

@Bean
  public Docket api(Environment environment, DocumentationCache documentationCache) {
    boolean isLocal = Boolean.parseBoolean(environment.getProperty("api.local", "false"));
    return new Docket(DocumentationType.OAS_30)
        .securityContexts(Collections.singletonList(securityContext()))
        .securitySchemes(Collections.singletonList(apiKey()))
        .host(!isLocal ? environment.getProperty("api.host") : null)
        .apiInfo(apiInfo())
        .protocols(Collections.singleton(isLocal ? "http" : "https"))
        .select()
        .apis(RequestHandlerSelectors.any())
        .paths(PathSelectors.any())
        .build()
        .directModelSubstitute(Pageable.class, SwaggerPageable.class);
  }
1reaction
fisco-unimaticcommented, Apr 8, 2021

If I construct my Docket with DocumentationType.OAS_30 instead of DocumentationType.SWAGGER_2, then it works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring MVC: Complex object as GET @RequestParam
I have request params as such: page-number and page-size . How will my request DTO object look like? In java, I can't create...
Read more >
How to bind @RequestParam to object in Spring - Dev in Web
There's no easy way to magically bind HTTP arguments to a POJO using a parameterized constructor. The non-argument constructor is inevitable.
Read more >
Spring @RequestParam Annotation - Baeldung
In this quick tutorial, we'll explore Spring's @RequestParam annotation and its attributes. Simply put, we can use @RequestParam to extract ...
Read more >
Spring Boot request parameters validation - Wim Deblauwe
Use the org.springframework.validation.annotation.Validated annotation on the class level. (NOTE: javax.validation.Valid would not work here!)
Read more >
Web on Reactive Stack - Spring
Spring WebFlux does not have built-in support to start or stop a server. However, it is easy to assemble an application from Spring ......
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