Springboot 2.6.7,Springdoc 1.6.8我需要有V3/API-DOC和V1/API-DOCS

发布于 2025-01-27 01:28:00 字数 473 浏览 5 评论 0原文

我正在尝试将Springboot应用程序从2.5.9升级到2.6.7,因此由于许多兼容性问题,我需要从Springfox 3.0.0迁移到Springdoc 1.6.8。

在Springfox中,我以这种方式配置了

springfox:
  documentation:
    swaggerUi:
      baseUrl: /documentation
    openApi:
      v3:
        path: /documentation/v3/api-docs
    swagger:
      v2:
        path: /documentation/v2/api-docs

我使用V2 API-DOC作为其他内容,因此我想继续拥有V2文档。

您知道是否有可能与SpringDoc生产V2和V3文档?

谢谢

I'm trying to upgrade my springboot app from 2.5.9 to 2.6.7 so i needed to migrate from springfox 3.0.0 to springdoc 1.6.8 because of many compatibility issues.

In springfox i configured in this way

springfox:
  documentation:
    swaggerUi:
      baseUrl: /documentation
    openApi:
      v3:
        path: /documentation/v3/api-docs
    swagger:
      v2:
        path: /documentation/v2/api-docs

I used v2 api-docs for other stuffs so i'd like to continue to have also a v2 documentation.

Do you know if is possible to produce v2 and v3 documentation with springdoc?

thx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

各自安好 2025-02-03 01:28:00

您需要使用SpringDoc的API组来实现所需的目标。

API组是一个指定API的BEAN,该API将/排除在组中。在您的情况下,V2 API形成一个组,而V3 API形成另一组。

V2 bean应定义如下

@Bean
public GroupedOpenApi v2Apis() {
    return GroupedOpenApi.builder().group("v2 APIs")
            // show all v2 APIs. 
            .pathsToMatch("/api/v2/**", "/v2/**") // assuming you have v2 APIs which start with either of the entry in the list.
            .build();
}

,V3豆如下所述,

@Bean
public GroupedOpenApi v3Apis() {
    return GroupedOpenApi.builder().group("v3 APIs")
            // show all v3 APIs. 
            .pathsToMatch("/api/v3/**", "/v3/**") // assuming you have v3 APIs which start with either of the entry in the list.
            .build();
}

请参阅答案在这里API组。

You need to use the API Groups from Springdoc to achieve what you're looking for.

An API Group is a bean that specifies which APIs to include/exclude from a group. In your case, v2 APIs form one group while v3 APIs form another group.

The v2 bean should be defined as follows

@Bean
public GroupedOpenApi v2Apis() {
    return GroupedOpenApi.builder().group("v2 APIs")
            // show all v2 APIs. 
            .pathsToMatch("/api/v2/**", "/v2/**") // assuming you have v2 APIs which start with either of the entry in the list.
            .build();
}

and the v3 bean as follows

@Bean
public GroupedOpenApi v3Apis() {
    return GroupedOpenApi.builder().group("v3 APIs")
            // show all v3 APIs. 
            .pathsToMatch("/api/v3/**", "/v3/**") // assuming you have v3 APIs which start with either of the entry in the list.
            .build();
}

Refer to the answer here for details on how wildcards behave for the API Groups.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文