Astro企业应用 AstroPro-swagger标签使用指南:5、x-class-annotations
时间:2025-02-12 15:02:26
5、x-class-annotations
作用:
添加指定的注解。

该标签用于在api接口或者dto类上添加指定的注解。
标签值类型:
List
使用位置:
- x-class-annotations(定义在swagger的最外层时,会在所有的api接口上都添加指定的注解)
- components.schemas.model.x-class-annotations(定义dto对象上时,只在该对象上添加指定的注解)
使用示例:
swagger: "2.0"info: description: "" version: "v1" title: "testSwagger" termsOfService: "http://www.coarl.org/service.html"host: "git.huawei.com"basePath: "/testswagger"x-imports: - "org.springframework.stereotype.Controller;" # 使用的时候结尾一定要带上 ; - "org.springframework.transaction.annotation.Transactional;"x-class-annotations: #此处添加的注解,在所有生成的api上都会添加 - "@Controller" # 此处会将 @Controller识别为一个字符串添加到api接口类上,并不会导入相应的包,需要使用 x-imports标签手动导入相应的包 - "@Transactional" # 此处会将 @Transactional识别为一个字符串添加到api接口类上,并不会导入相应的包,需要使用 x-imports标签手动导入相应的包
使用效果:
使用前:
package com.huaweicloud.icsl.api;import ------/** * CARDApi interface */public interface CARDApi { -----------}
使用后:
package com.huaweicloud.icsl.api;import org.springframework.stereotype.Controller; // 通过x-imports 引入的导包import org.springframework.transaction.annotation.Transactional; // 通过x-imports 引入的导包/** * CARDApi interface */@Controller // 通过x-class-annotations 引入的注解@Transactional // 通过x-class-annotations 引入的注解public interface CARDApi { -----------}
support.huaweicloud.com/usermanual-astropro/astropro_05_0143.html