【问题标题】:Swagger with Springboot add personalized information whith java anotationsSwagger 与 Spring Boot 使用 java 注解添加个性化信息
【发布时间】:2023-04-10 22:36:01
【问题描述】:

如何使用 java 注释在 swagger-UI 中个性化页面上显示的信息?

in swagger petstore

【问题讨论】:

    标签: java spring spring-boot swagger openapi


    【解决方案1】:

    如果要自定义api信息可以包含java风格的注解:

    
    
        @OpenAPIDefinition(
            info = @Info(
                     title = "API personas", 
                     description = "Este es un ejemplo de servidor Personas-Server."
                + "Usted puyede encontrar mas acerca de Swagger " ++"[http://swagger.io](http://swagger.io) o en "
                + "[irc.freenode.net, #swagger](http://swagger.io/irc/).",
                termsOfService = "http://swagger.io/terms/", 
                  license = @License(
                              name = "Apache 2.0", 
                              url = "http://springdoc.org"), 
           version = "otra"
        ))
        @Tag(name = "persona", description = "API para personas")
        @RestController
        @RequestMapping("persona")
        public class PersonaRest extends GeneralRest {}
    
    

    也可以为特殊方法生成:

    
    
         @Operation(
             summary = "traer todas las personas", 
             description = "api para traer todas las personas, aqui no se tienen en cuenta paginaciones, ni filtros, trae todos los registros", 
             tags = { "persona" }
             )
         @ApiResponses(
             value = {
             @ApiResponse(
                 responseCode = "200", 
                 description = "Operación exitosa", 
                 content = @Content(
                     mediaType = "application/json", 
                     array = @ArraySchema(
                         schema = @Schema(
                             implementation = PersonaTO.class
                             )))),
             @ApiResponse(
                 responseCode = "401", 
                 description = "Sin autorización", 
                 content = @Content(
                     mediaType = "application/json", 
                     schema = @Schema(
                         implementation = Object.class
                         ))),
         })
         @GetMapping
         public List personas() {
                return personaServicio.obtenerTodo();
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-23
      • 2023-02-16
      • 2016-12-30
      • 1970-01-01
      • 2018-02-12
      • 2021-06-02
      • 2014-05-28
      • 1970-01-01
      相关资源
      最近更新 更多