不检查请求标头参数

时间:2019-06-11 10:53:48

标签: spring-boot swagger-ui swagger-2.0 springfox

我有一个spring boot应用程序,它使用REST调用Web服务: 这是我使用bean配置调用的示例:

nav_graph.xml

春季狐狸豆:

sudo gem install cocoapods

当我在Swagger Document中执行不带标题'TRACE_ID'的请求时,它阻止了执行,但使用curl命令的效果很好:

@ApiResponses(value = {
            @ApiResponse(code = 200, message = "", response = ResultSearch.class),
            @ApiResponse(code = 204, message = "No data found", response = Object.class),
            @ApiResponse(code = 404, message = ApiMessageResponse.HTTP_STATUS_CODE_404, response = ErrorModel.class),
            @ApiResponse(code = 400, message = ApiMessageResponse.HTTP_STATUS_CODE_400, response = ErrorModel.class) })
    @GetMapping(path = "corporates", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "Search for corporates")
    public Object searchCorporate(@RequestParam(name = "query") String query) throws Exception {

        return searchManagement.searchCorporates(search);

    } 

它通过了,而没有检查标题授权/要求! 我正在使用@Bean public Docket api() { //Adding Header ParameterBuilder headerParameterBuilder = new ParameterBuilder(); java.util.List<Parameter> headersParameters = new ArrayList<Parameter>(); headersParameters.clear(); headerParameterBuilder.name(Headers.TRACE_ID).description("ID of the whole trace forest").modelRef(new ModelRef("string")).parameterType("header").required(true).build(); headersParameters.add(headerParameterBuilder.build()); return new Docket(DocumentationType.SWAGGER_2).useDefaultResponseMessages(false).select() .apis(RequestHandlerSelectors.basePackage(swaggerResourcePackage)).paths(PathSelectors.any()).build() .apiInfo(new ApiInfo(swaggerTitle, swaggerDescription, swaggerVersion, "", null, "", "", Collections.emptyList())) .protocols( new HashSet<>(Arrays.asList("http","https"))) .globalOperationParameters(headersParameters); } curl -X GET "http://localhost:8081/search/corporates?query=bddf" -H "accept: application/json;charset=UTF-8" 我的配置有什么问题,无法在执行请求之前先确认请求标头

0 个答案:

没有答案