ASTRO企业应用 ASTROPRO-swagger标签使用指南:3、x-imports

时间:2024-09-14 14:45:08

3、x-imports

作用

自主定义类中需要添加的 import 引用。

标签值类型

List

使用位置

  • x-imports(当定义在swagger的最外层时,所有的类中都会引入import)
  • components.schemas.model.properties.property.x-imports(当定义在dto的字段中时,只会在该dto类中引入import)
  • definitions.model.x-imports(当定义在dto上时,只会在该dto类中引入import)
  • paths.path.operation.x-imports(当定义在api中时,只会在该api中引入import)

在生成代码的时候,最终会有格式化的一个步骤,类上的无用import会被消除。

使用示例

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;"

使用效果:

使用前:api类中不生成org.springframework.stereotype.Controller; 和org.springframework.transaction.annotation.Transactional;引用。

使用后:api类中生成如下引用。

import org.springframework.stereotype.Controller;  # 通过x-import引入
import org.springframework.transaction.annotation.Transactional;  # 通过x-import引入

public interface CARDApi {
   -------
);
support.huaweicloud.com/usermanual-astropro/astropro_05_0143.html