【问题标题】:springdoc swagger not detect correct url for callspringdoc swagger 没有检测到正确的调用 URL
【发布时间】:2021-10-06 11:35:34
【问题描述】:

在我的项目中,我需要为所有 @RestController beans 映射添加前缀。所以我添加了这个配置类:

@Configuration
public class AppConfiguration implements WebMvcConfigurer {

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer.addPathPrefix("/rest",
                HandlerTypePredicate.forAnnotation(RestController.class));
    }
}

之后我看到 swagger 无法使用默认地址正确预览,所以我添加了这个配置键:

springdoc.swagger-ui.path= swagger
springdoc.swagger-ui.url= /rest/api-docs

现在我看到这个页面有正确的控制器映射但是当我尝试它时,url 再次添加前缀并将地址更改为 /rest/rest/...

@RestController
public class WorkflowController {

    private final WorkflowService workflowService;
    private final Environment environment;


    public WorkflowController(WorkflowService workflowService, Environment environment) {
        this.workflowService = workflowService;
        this.environment = environment;
    }

    @PostMapping(value = "/phoneCharge")
    public GeneralResponse startChargeProcess(@Valid @RequestBody MerchantChargeRequestDto dto, HttpServletRequest request) {
        return workflowService.startChargeProcess(dto, request.getRemoteAddr(), "ChargeProcess");
    }
}

怎么了?

我用这个版本

spring-boot-starter-parent => 2.3.12.RELEASE

springdoc-openapi-data-rest & springdoc-openapi-ui => 1.5.9

【问题讨论】:

    标签: spring-boot swagger-ui springdoc


    【解决方案1】:

    这是该版本中的一个错误(不支持 HandlerTypePredicate)。

    查看我的已关闭问题:

    https://github.com/springdoc/springdoc-openapi/issues/1258#issuecomment-922325290

    【讨论】:

    • 已添加支持。使用 v1.6.4 测试!
    猜你喜欢
    • 2021-06-01
    • 1970-01-01
    • 2022-06-14
    • 1970-01-01
    • 1970-01-01
    • 2020-10-06
    • 2019-06-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多