You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Swagger1.5迁移至2.0时@ApiModelProperty等注解对应@Schema替代属性查询

各属性对应替代关系如下

  • position → @Schema 的 order 属性
    功能完全对齐,用于控制字段在文档中的排序,数值越小排序越靠前。
  • notes → 合并到 @Schema 的 description 属性
    OpenAPI 3规范不再单独区分短描述和补充注释,所有说明内容都可以写在description中,支持Markdown语法排版区分不同层级的说明。
  • dataType → @Schema 的 type 或 implementation 属性
    原dataType传字符串类型标识的用法可以替换为type属性,需要直接绑定Java类的场景可使用implementation属性传入对应Class对象,类型校验更精准。
  • @ApiModel的parent → @Schema 的 allOf 属性
    直接传入父类Class即可,生成文档时会自动继承父类的所有字段说明。

替换示例

原1.5版本注解写法:

// 类注解
@ApiModel(value = "用户信息", parent = BaseModel.class)
// 字段注解
@ApiModelProperty(value = "用户ID", position = 1, notes = "全局唯一自增ID", dataType = "java.lang.Long")
private Long userId;

替换为2.0版本@Schema写法:

// 类注解
@Schema(name = "用户信息", allOf = BaseModel.class)
// 字段注解
@Schema(description = "用户ID\n> 全局唯一自增ID", order = 1, type = "long", implementation = Long.class)
private Long userId;

内容的提问来源于stack exchange,提问作者lesnar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 23:12:03