gpt4 book ai didi

swagger-2.0 - 从 springfox swagger2 迁移到 springdoc openapi

转载 作者:行者123 更新时间:2023-12-01 12:04:20 30 4
gpt4 key购买 nike

https://www.dariawan.com/tutorials/spring/documenting-spring-boot-rest-api-springdoc-openapi-3/

试图遵循这些

我如何处理像这样的注释

@ApiModel(value = "Response container")

@ApiModelProperty(value = "Iventory response", required = true)

最佳答案

Migrating from SpringFox

  • 删除 springfox 和 swagger 2 依赖项。添加 springdoc-openapi-ui依赖代替。

  •    <dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>@springdoc.version@</version>
    </dependency>
  • 用 swagger 3 注释替换 swagger 2 注释(它已经包含在 springdoc-openapi-ui 依赖项中)。
    swagger 3 注释的包是 io.swagger.v3.oas.annotations .
  • @ApiParam -> @Parameter
  • @ApiOperation -> @Operation
  • @Api -> @Tag
  • @ApiImplicitParams -> @Parameters
  • @ApiImplicitParam -> @Parameter
  • @ApiIgnore -> @Parameter(hidden = true)@Operation(hidden = true)@Hidden
  • @ApiModel -> @Schema
  • @ApiModelProperty -> @Schema

  • 此步骤是可选的:仅当您有 时多个 Docket beans 用 GroupedOpenApi 替换它们 bean 。
    前:
        @Bean
    public Docket publicApi() {
    return new Docket(DocumentationType.SWAGGER_2)
    .select()
    .apis(RequestHandlerSelectors.basePackage("org.github.springshop.web.public"))
    .paths(PathSelectors.regex("/public.*"))
    .build()
    .groupName("springshop-public")
    .apiInfo(apiInfo());
    }

    @Bean
    public Docket adminApi() {
    return new Docket(DocumentationType.SWAGGER_2)
    .select()
    .apis(RequestHandlerSelectors.basePackage("org.github.springshop.web.admin"))
    .paths(PathSelectors.regex("/admin.*"))
    .build()
    .groupName("springshop-admin")
    .apiInfo(apiInfo());
    }
    现在:
        @Bean
    public GroupedOpenApi publicApi() {
    return GroupedOpenApi.builder()
    .setGroup("springshop-public")
    .pathsToMatch("/public/**")
    .build();
    }

    @Bean
    public GroupedOpenApi adminApi() {
    return GroupedOpenApi.builder()
    .setGroup("springshop-admin")
    .pathsToMatch("/admin/**")
    .build();
    }
    如果您有 只有一个 Docket -- 删除它,而是将属性添加到您的 application.properties :
    springdoc.packagesToScan=package1, package2
    springdoc.pathsToMatch=/v1, /api/balance/**
  • OpenAPI bean 类型。见示例:
        @Bean
    public OpenAPI springShopOpenAPI() {
    return new OpenAPI()
    .info(new Info().title("SpringShop API")
    .description("Spring shop sample application")
    .version("v0.0.1")
    .license(new License().name("Apache 2.0").url("http://springdoc.org")))
    .externalDocs(new ExternalDocumentation()
    .description("SpringShop Wiki Documentation")
    .url("https://springshop.wiki.github.org/docs"));
    }
  • 如果 swagger-ui 在代理后面提供:
  • https://springdoc.org/faq.html#how-can-i-deploy-the-doploy-springdoc-openapi-ui-behind-a-reverse-proxy .

  • 自定义 Swagger UI
  • https://springdoc.org/faq.html#how-can-i-configure-swagger-ui .

  • 从文档中隐藏操作或 Controller
  • https://springdoc.org/faq.html#how-can-i-hide-an-operation-or-a-controller-from-documentation- .

  • 关于swagger-2.0 - 从 springfox swagger2 迁移到 springdoc openapi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59291371/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com