Swagger注解-@ApiModel 和 @ApiModelProperty

系统管理员 2021-02-17 09:02 4391阅读 2赞

@ApiModel
使用场景
在实体类上边使用,标记类时swagger的解析类

概述
提供有关swagger模型的其它信息,类将在操作中用作类型时自动内省

属性

属性名称 数据类型 默认值 说明
value String 类名 为模型提供备用名称
description String “” 提供详细的类描述
parent Class<?> parent Void.class 为模型提供父类以允许描述继承关系
discriminatory String “” 支持模型继承和多态,使用鉴别器的字段的名称,可以断言需要使用哪个子类型
subTypes Class<?>[] {} 从此模型继承的子类型数组
reference String “” 指定对应类型定义的引用,覆盖指定的任何其他元数据

@ApiModelProperty
使用场景
使用在被 @ApiModel 注解的模型类的属性上

概述
添加和操作模型属性的数据

属性

属性名称 数据类型 默认值 说明
value String “” 属性简要说明
name String “” 运行覆盖属性的名称。重写属性名称
allowableValues String “” 限制参数可接收的值,三种方法,固定取值,固定范围
access String “” 过滤属性,参阅:io.swagger.core.filter.SwaggerSpecFilter
notes String “” 目前尚未使用
dataType String “” 参数的数据类型,可以是类名或原始数据类型,此值将覆盖从类属性读取的数据类型
required boolean false 是否为必传参数,false:非必传参数; true:必传参数
position int 0 允许在模型中显示排序属性
hidden boolean false 隐藏模型属性,false:不隐藏; true:隐藏
example String “” 属性的示例值
readOnly boolean false 指定模型属性为只读,false:非只读; true:只读
reference String “” 指定对应类型定义的引用,覆盖指定的任何其他元数据
allowEmptyValue boolean false 允许传空值,false:不允许传空值; true:允许传空值

发表评论

表情:
评论列表 (有 1 条评论,4391人围观)
朱雀
朱雀V铁粉 2021-03-30 09:47
Swagger注解-@ApiModel 和 @ApiModelProperty

相关阅读