Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading