【问题标题】:springdoc-openapi-ui swagger 3 change API descriptionspringdoc-openapi-ui swagger 3 更改API描述
【发布时间】:2022-10-25 20:20:57
【问题描述】:

我是 String 和 Swagger 3 的新手。 如何更改默认 API 描述,即 Swagger springdoc-openapi-ui swagger 3 中的 OpenAPI definition

还有版本,开发者信息..

我在用

implementation "org.springframework.boot:spring-boot-starter-web:2.6.6"
implementation "org.springdoc:springdoc-openapi-ui:1.6.8"

在搜索中,我只看到他们显示默认的 Swagger UI

【问题讨论】:

    标签: spring spring-boot swagger swagger-ui


    【解决方案1】:

    只需使用以下注释:

    在应用程序启动器类(配置类)中:

    @OpenAPIDefinition(info=@Info(title="Name of project"))
    

    在控制器中

    import io.swagger.v3.oas.annotations.*
    

    班级等级:

    @OpenAPIDefinition()
    

    或者

    @Tag(name = "", description = "")
    

    方法级别:

     @Operation()
    
     @ApiResponses()
    

    【讨论】:

    • 非常感谢你的回复。你能告诉我 - 如何在 API 上隐藏请求恶魔?我的意思是 - 我有一个通用模型 User = { "userName": "string", "firstName": "string", "lastName": "string", "userToken": "string", "userType": "string" } 使用相同的模型(User.java),“/sign-up”的请求正文应该是 - {“userName”:“string”,“firstName”:“string”,“lastName”:“string”, "userToken": "string", "userType": "string" } 但是,对于 "/sign-in",请求正文应该是 - { "userName": "string", "userToken": "string", }
    • 最好为这种情况创建新问题。@CRSardar
    • 谢谢,如果可能的话,请看看这个stackoverflow.com/questions/72138583/…
    【解决方案2】:

    对于我使用的标准版本:

    @Bean
        public OpenAPI customOpenAPI() {
            final String locUrl = "http://localhost:8080";
            final String devUrl = "https://.de";
            final String testUrl = "https://.de";
            final String preUrl = "https://.de";
            final String proUrl = "https://.grp";
    
            return new OpenAPI().addServersItem(new Server().url(locUrl)).addServersItem(new Server().url(
                    devUrl)).addServersItem(new Server().url(testUrl)).addServersItem(new Server().url(preUrl))
                .addServersItem(new Server().url(proUrl)).info(
                    new Info().version("v1").title("XApp application API")
                        .description("(NOTE: If having Swagger UI issues w/ Chrome then use Firefox instead.)")
                .contact(new Contact().name("Edi")));
        }
    

    并根据我所做的分组进行更改:

    @Profile("!dev")
        @Bean
        public GroupedOpenApi groupedPublicOpenApi10() {
            return GroupedOpenApi
                .builder()
                .addOpenApiCustomiser(openApi -> openApi.getInfo().setVersion("v1"))
                .group("API-v1")
                .pathsToMatch("/api/**")
                .displayName("API v1")
                .build();
        }
    
    

    【讨论】:

      猜你喜欢
      • 2020-09-09
      • 1970-01-01
      • 2022-12-06
      • 2021-06-03
      • 2021-03-03
      • 1970-01-01
      • 2018-12-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多