Vivek Misra
Vivek Misra

Reputation: 175

Is Springdoc swagger not possible when passing HttpServletRequest as method param?

I have below springboot rest controller and using springdoc-openapi. My springboot rest service has to cater to some legacy application( which is the only client which calls this service) and I need to have HttpServletRequest as param.

I am generating swagger openapi doc and when I got to swagger-ui.html, I see that the rerquest body comes for Httprequest param method with uri path = '/personhttprequest' but not when param is HttpServletRequest. I see here https://springdoc.org/faq.html#what-are-the-ignored-types-in-the-documentation

But I am not clear why and how can I get HttpServletRequest param working in swagger ui. I want to pass it as text/xml just like i can make it work for HttpRequest below.enter image description hereI have attached scrrenshot for "/personhttprequest" and you see the box for request body as xml comes up. How can make it work for "/personhttpservletrequest"?

@RestController
public class PersonController {
   
    
    @RequestMapping(path = "/personhttprequest", method = RequestMethod.POST,consumes=MediaType.TEXT_XML_VALUE,produces=MediaType.APPLICATION_JSON_VALUE)
    public Person personHttpRequest(HttpRequest req) {
        Person person = new Person();
        return person;
    }
    
    @RequestMapping(path = "/personhttpservletrequest", method = RequestMethod.POST,consumes=MediaType.TEXT_XML_VALUE,produces=MediaType.APPLICATION_JSON_VALUE)
    public Person personHttpServletRequest(HttpServletRequest req) {
        Person person = new Person();
        return person;
    }
}

Here is git hub : https://github.com/vmisra2018/sb-example-swaggerdoc

Upvotes: 1

Views: 2050

Answers (1)

user14092327
user14092327

Reputation:

Principal, Locale, HttpServletRequest and HttpServletResponse and other injectable parameters supported by Spring MVC are excluded.

Full documentation here:

If you don't want to ignore it:

    SpringDocUtils.getConfig().removeRequestWrapperToIgnore(HttpServletRequest.class)

Upvotes: 1

Related Questions