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

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

4、x-annotations

作用

添加指定的注解。

该标签用于在api的参数或者dto指定属性上添加注解。

标签值类型

List

使用位置

  • paths.path.operation.parameters.x-annotations(定义在api中的参数上时,只在此参数上生成对应的注解)
  • definitions.model.properties.property.x-annotations(定义在dto的字段上时,只在此字段上生成对应的注解)

使用示例

Card:
    type: "object"
    properties:
      id:
        type: "string"
        description: "id"
        example: "id"
      balance:
        type: "integer"
        format: "int64"
        description: "balance"
        example: 123
      address:
        type: "string"
        description: "address"
        example: "address"
        x-annotations:
          - "@InjectMocks"  # 此处在address属性上添加了一个 @InjectMocks 注解
        x-imports:
          - "org.mockito.InjectMocks;" # x-annotations实际是把 @InjectMocks当做字符串添加到了address上,所以需要自己通过x-imports导入相应的类      
      creator:
        type: "string"
        description: "creator"
        example: "creator"
      create_time:
        type: "string"
        format: "date-time"
        default: "CURRENT_TIMESTAMP"
        description: "create time"
        example: "2020-02-27 15:00:08"
      modify_time:
        type: "string"
        format: "date-time"
        default: "CURRENT_TIMESTAMP"
        description: "modified time"
        example: "2020-02-27 15:00:08"
      description:
        type: "string"
        description: "description info"
        example: "description"
    xml:
      name: "card"
      namespace: "com.huaweicloud.icsl.model"

使用效果:

使用前:

public class Card implements Serializable {
    private static final long serialVersionUID = 1L;

    -----

    @JsonProperty("address")
    private String address = null;

    ----
}

使用后:

public class Card implements Serializable {
    private static final long serialVersionUID = 1L;

    -------

    @JsonProperty("address")
    @InjectMocks   // 通过 x-annotations 引入的注解
    private String address = null;

    --------
}
support.huaweicloud.com/usermanual-astropro/astropro_05_0143.html