Search code examples
javaspring-bootswagger-ui

Hide HttpServletRequest request in Swagger OpenAPI 3


I am currently using Spring Boot 3.0.2 with Swagger OpenAPI 3. But the SwaggerUI keeps marking a parameter in my controller as a required request parameter.

In my pom.xml

<dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-ui</artifactId>
        <version>1.6.14</version>
</dependency>

In my RestController.java

@GetMapping("/endpoint")
    public ResponseEntity<Object> Hello(HttpServletRequest request, 
@RequestParam String paramOne){}

In my swagger UI, there are two required parameters: paramOne and request (which I don't want to be a part of). How can I hide or mark it as not a URL parameter?


Solution

  • Mark the HttpServletRequest parameter with @Parameter(hidden = true). Your code should look like this:

    @GetMapping("/endpoint")
        public ResponseEntity<Object> Hello(@Parameter(hidden = true) HttpServletRequest request, 
    @RequestParam String paramOne){}
    

    This will hide the request parameter in Swagger UI and it will not be visible.