将HttpServletRequest作为方法参数传递时,Springdoc是否会大张旗鼓?

时间:2020-07-05 23:07:52

标签: spring-boot swagger springdoc-openapi-ui

我在springboot rest控制器下面并使用springdoc-openapi。我的springboot rest服务必须迎合某些旧版应用程序(这是唯一调用此服务的客户端),我需要将HttpServletRequest作为参数。

我正在生成swagger openapi doc,当我转到swagger-ui.html时,我看到rerquest主体来自uri path ='/ personhttprequest'的Httprequest param方法,但是当param是HttpServletRequest时不是。我在这里看到 https://springdoc.org/faq.html#what-are-the-ignored-types-in-the-documentation

但是我不清楚为什么以及如何在swagger ui中使HttpServletRequest参数工作。我想将其作为text / xml传递,就像我可以在下面的HttpRequest上使它一样。enter image description here我为“ / personhttprequest”附加了scrrenshot,随着xml的出现,您会看到请求正文的框。如何使其适用于“ / 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;
    }
}

这是git hub: https://github.com/vmisra2018/sb-example-swaggerdoc

1 个答案:

答案 0 :(得分:1)

不包括Spring MVC支持的Principal,Locale,HttpServletRequest和HttpServletResponse以及其他可注入参数。

完整文档在这里:

如果您不想忽略它:

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