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
相关产品推荐
相关产品推荐

