Springfox:不被应用于替代类型规则

问题描述 投票:0回答:1

@EnableSwagger2注释类包含下列方法:

@Bean
    public Docket myServiceApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("My Service API").apiInfo(apiInfo()).select()
            .paths(PathSelectors.regex("/api.*")).build()
            .alternateTypeRules(
                newRule(
                    typeResolver.resolve(Map.class, String.class, Object.class),
                    typeResolver.resolve(InputExample.class)
                )
            )
            ;

    }

其中InputExample是包含与@ApiModelProperty注释许多不同的属性的类。

在我的REST控制器的方法是这样的:

@ApiOperation(
        value = "Do stuff",
        consumes = MediaType.APPLICATION_JSON_VALUE,
        produces = MediaType.APPLICATION_JSON_VALUE,
        response = SomeOutput.class
    )
    @RequestMapping(
        value = "/api/v1/stuff",
        method = RequestMethod.POST,
        consumes = {MediaType.APPLICATION_JSON_VALUE},
        produces = {MediaType.APPLICATION_JSON_VALUE}
    )
    @ApiResponses(
        value = {
            @ApiResponse(code = 200, message = "Service execution successful"),
            @ApiResponse(code = 400, message = "Bad input data"),
            @ApiResponse(code = 500, message = "An internal server error occurred"),
            @ApiResponse(code = 503, message = "The service is currently unavailable")
        }
    )
    public ResponseEntity<SomeOutput> doServiceStuff(
        HttpServletRequest request,
        @RequestBody Map<String, Object> inputContent
    ) throws
        ValidationException,
        ServiceUnavailableException,
        IOException,
        WorkflowDocumentProcessingException
    {
    ...
    }

可悲的是,当我跑我的服务,然后打开我的上扬鞭UI终点,我看到的是:

Parameters in Swagger UI

那会是由以下原因造成?如何调试呢?

P.S:在@EnableSwagger2的其余部分 - 类确实工作。

swagger swagger-ui springfox
1个回答
0
投票

目前似乎已经与原来的类型Map<String, Object>压倒一切的一切开发者添加到.alternateTypeRules()内部规则。

我能找到解决这个问题的唯一方法是创建一个class MyInputMap extends Map<String, Object>并在有关的所有端点使用它,同时还调整类型规则:

newRule(
   typeResolver.resolve(MyInputMap.class),
   typeResolver.resolve(InputExample.class)
)
© www.soinside.com 2019 - 2024. All rights reserved.