1

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

Helen
  • 87,344
  • 17
  • 243
  • 314
Vivek Misra
  • 165
  • 2
  • 15
  • As you mentioned `Principal, Locale, HttpServletRequest and HttpServletResponse and other injectable parameters supported by Spring MVC are excluded.` these are not ignored by springdoc – SSK Jul 07 '20 at 04:16
  • If not ignored by springdoc, then why in swagger ui when i want to "Try it out" for" /personhttpservletrequest ", the request box not appear? it appears for httprequest. The code is in github. – Vivek Misra Jul 08 '20 at 19:42

1 Answers1

1

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)