代码之家  ›  专栏  ›  技术社区  ›  Markus Appel

Springfox:没有应用备用类型规则

  •  0
  • Markus Appel  · 技术社区  · 7 年前

    我的 @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 .

    @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
        {
        ...
        }
    

    遗憾的是,当我运行服务并在Swagger UI上打开端点时,我看到的只是:

    Parameters in Swagger UI

    旁白:剩下的人 @使能招摇2 -上课确实有效。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Markus Appel    7 年前

    原始类型似乎已经有了内部规则 Map<String, Object> .alternateTypeRules()

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

    newRule(
       typeResolver.resolve(MyInputMap.class),
       typeResolver.resolve(InputExample.class)
    )