规则的 key | 规则目标(上下文 it) | 版本 | 规则描述 |
---|---|---|---|
folder.name | method | 1.1.11+ | 设置 api 所属文件夹 |
class.prefix.path | class | 1.1.11+ | 设置 API 请求前缀 |
ignore | class/method | 1.1.11+ | 忽略 API |
module | class | 1.1.11+ | 为 api 分组 |
规则的 key | 规则目标(上下文 it) | 版本 | 规则描述 |
---|---|---|---|
api.name | method | 1.1.11+ | 设置 api 的名称 |
api.tags | method | 1.1.24+ | 设置 api 的标签 |
api.status | method | 1.1.24+ | 设置 api 的状态 |
method.description | method | 1.1.24+ | 方法(api)的额外注释 |
method.defaultContentType | - | 1.1.24+ | 用以设置 API 请求的 content-type |
method.default.http.method | method | 1.1.11+ | 设置默认的 api 的 HttpMethod |
method.request.replace | method | 1.1.29+ | 设置默认的 api 的入参命名转换 |
method.response.replace | method | 1.1.29+ | 设置默认的 api 的返回值命名转换 |
method.additional.header | method | 1.1.11+ | API 需要额外的 header, |
{name: "header name",value: "",desc: "",required:false, example:""} | |||
method.additional.param | method | 1.1.11+ | API 需要额外的参数 |
{name: "param name",value: "defaultValue",desc: "",required:false} | |||
☆method.return | method | 1.1.11+ | 设置返回值的类型 |
☆method.return.main | method | 1.1.11+ | 设置返回值的核心主体 |
☆method.return.body.type | method | 1.1.28+ | 设置返回值的返回类型 |
path.multi | - | 1.1.11+ | 设置返回值的核心主体 |
规则的 key | 规则目标(上下文 it) | 版本 | 规则描述 |
---|---|---|---|
param.defaultValue | arg | 1.1.11+ | API 参数的默认值 |
param.description | arg | 1.1.11+ | 参数的额外注释 |
param.type | arg | 1.1.11+ | 用于设置 API 参数在 HTTP 请求中的类型 |
param.ignore | arg | 1.1.11+ | 忽略 API 参数 |
param.required | arg | 1.1.11+ | API 参数是否为必须(即不可为空) |
规则的 key | 规则目标(上下文 it) | 版本 | 规则描述 |
---|---|---|---|
field.order | - | 1.1.27+ | 用以设置字段的排序 |
field.order.with | - | 1.1.27+ | 用以设置字段的排序,通过比较器 |
field.defaultValue | - | 1.1.11+ | 用以设置字段的默认值 |
field.example | - | 1.1.11+ | 用以设置字段的示例值 |
☆field.description | field | 1.1.11+ | 字段的额外注释 |
field.ignore | field | 1.1.11+ | 忽略字段(设置某些字段不出现在 json 中,或不需要请求时给出) |
☆field.mock | field | 1.1.11+ | 生成 mock 信息 |
field.mock.resolveProperty | - | 1.1.11+ | 用以开关是否解析field.mock 规则结果中的占位符 |
field.name | field | 1.1.11+ | 设置输出的字段名(用于 json 中字段名与类中字段名不一致) |
field.required | field | 1.1.11+ | 字段是否为必须(即不可为空) |
constant.field.ignore | field | 1.1.11+ | 忽略常量字段 |
field.schema.title | field | 1.1.27+ | 用以设置字段的数据模型的中文名 |
field.schema.min.length | field | 1.1.27+ | 用以设置字段的数据模型的最小长度 |
field.schema.max.length | field | 1.1.27+ | 用以设置字段的数据模型的最大长度 |
field.schema.format | field | 1.1.27+ | 用以设置字段的数据模型格式format |
field.schema.pattern | field | 1.1.27+ | 用以设置字段的数据正则表达式 |
field.schema.const | field | 1.1.27+ | 用以设置字段的数据模型常量 |
field.schema.read.only | field | 1.1.27+ | 数据模型作为请求参数时,该字段将被隐藏 |
field.schema.write.only | field | 1.1.27+ | 数据模型作为返回结构时,该字段将被隐藏 |
field.schema.permit.null | field | 1.1.29+ | 数据模型字段是否允许为 null,默认允许为 null |
规则的 key | 规则目标(上下文 it) | 版本 | 规则描述 |
---|---|---|---|
enum.use.custom | class | 1.1.11+ | 用于设置使用 @see 枚举类型时的默认取值字段, 优先级高于enum.use.by.type |
enum.use.by.type | class | 1.1.11+ | 用于设置使用 @see 枚举类型时的默认使用类型一致的字段, 优先级低于enum.use.custom |
enum.use.ordinal | class | 1.1.11+ | 用于设置使用 @see 枚举类型时的默认使用 ordinal 作为取值 |
enum.use.name | class | 1.1.11+ | 用于设置使用 @see 枚举类型时的默认使用 name 作为取值 |
规则的 key | 规则目标(上下文 it) | 版本 | 规则描述 |
---|---|---|---|
☆json.rule.convert | - | 1.1.11+ | 用于设置某些类型转换为其他类型处理, 通常用于使用了 Spring 的自定义类型转换器的情况 |
json.rule.enum.convert | class | 1.1.11+ | 用于枚举类型的特殊转换 |
field | 1.1.11+ | 忽略字段(设置某些字段不出现在 json 中,或不需要请求时给出) 已废弃, 使用field.ignore代替 | |
field | 1.1.11+ | 设置输出的字段名(用于 json 中字段名与类中字段名不一致) | |
json.rule.class.description | field | 1.1.29+ | 设置数据模型的描述 |
规则的 key | 规则目标(上下文 it) | 版本 | 规则描述 |
---|---|---|---|
mdoc.class.filter | class | 1.1.11+ | 选择哪些类可以导出方法文档(rpc) |
mdoc.method.path | method | 1.1.11+ | 设置方法文档(rpc)的路径 |
mdoc.method.http.method | method | 1.1.11+ | 设置方法文档(rpc)HTTP 请求方式 |
规则的 key | 版本 | 配置类型 | 规则描述 | 示例 |
---|---|---|---|---|
dev | 1.1.11+ | bool | 启动开发模式,打印更详细的日志 | dev=true |
max.deep | 1.1.11+ | int | 解析json 时最大深度,默认 6 | max.deep=8 |
max.elements | 1.1.11+ | int | 解析json 时最大字段数,默认 256 | max.elements=512 |
json.cache.disable | 1.1.11+ | bool | 禁用json 解析缓存 | json.cache.disable=true |
http.timeOut | 1.1.11+ | int | http 请求的超时时间(s),优先级高于setting | http.timeOut=5 |
auto.format.url | 1.1.11+ | bool | 导入时是否格式化url ,确保url 以/ 开始,且将[a-zA-Z0-9-/_:.{}?=!]之外的字符替换为/ | auto.format.url=false |
field.mock.resolveProperty | 1.1.11+ | bool | 是否处理mock 信息中的占位符${xxx} | field.mock.resolveProperty=true |
api.tags.delimiter | 1.1.24+ | string | tags 的分割符, 默认为, | api.tags.delimiter=,# |
it
, 但可能会有附加的上下文供使用规则的 key | 规则目标(上下文 it) | 附加上下文 | 版本 | 规则描述 |
---|---|---|---|---|
api.class.parse.before | class | 无 | 1.1.11+ | 解析api 前回调 |
api.class.parse.after | class | 无 | 1.1.11+ | 解析api 后回调 |
api.method.parse.before | method | 无 | 1.1.11+ | 解析api 方法前回调 |
api.method.parse.after | method | 无 | 1.1.11+ | 解析api 方法后回调 |
api.param.parse.before | param | 无 | 1.1.11+ | 解析api 参数前回调 |
api.param.parse.after | param | 无 | 1.1.11+ | 解析api 参数后回调 |
export.after | method | api | 1.1.11+ | 每个 api 导出完成后回调 |
http.call.before | 无 | request | 1.1.11+ | http 请求前回调 |
http.call.after | 无 | request, response | 1.1.11+ | http 请求后回调 |
json.class.parse.before | class | 无 | 1.1.11+ | 解析类型前回调 |
json.class.parse.after | class | 无 | 1.1.11+ | 解析类型后回调 |
json.field.parse.before | field | 无 | 1.1.11+ | 解析类型字段前回调 |
json.field.parse.after | field | 无 | 1.1.11+ | 解析类型字段后回调 |
json.method.parse.before | method | 无 | 1.1.11+ | 解析类型方法 (getter/setter ) 前回调 |
json.method.parse.after | method | 无 | 1.1.11+ | 解析类型方法 (getter/setter ) 后回调 |
#fake
对应取的注释如下:
@org.springframework.web.bind.annotation.RequestMapping
@RequestMapping("path")
public class FakeClass{...}
@org.springframework.web.bind.annotation.RequestMapping#value
@RequestMapping(value = "path")
public class FakeClass{...}
api.status=done
JDK11
后js
引擎可能缺失, 故推荐使用groovy
作为首选groovy
规则为 groovy:groovyScript
js
规则为 js:jsScript
# 使用 tag `folder` 设置接口所在目录
folder.name=#folder
用户相关
, 加上注释 @folder 一级目录/二级目录
后归属到一级目录/二级目录
,如果希望成为用户相关
的子目录,加上注释 @folder 用户相关/一级目录/二级目录
后归属到用户相关/一级目录/二级目录
多级目录使用斜杠/
分隔。其中\
和/
为特殊字符,需要转义,\/
表示字符/
,\\
表示字符\
。设置 API 请求前缀
#[import_spring_properties]
#Import spring properties
###set ignoreNotFoundFile = true
###set ignoreUnresolved = true
properties.additional=${module_path}/src/main/resources/application.properties
properties.additional=${module_path}/src/main/resources/application.yml
properties.additional=${module_path}/src/main/resources/application.yaml
properties.additional=${module_path}/src/main/resources/bootstrap.yaml
properties.additional=${module_path}/src/main/resources/bootstrap.properties
properties.additional=${module_path}/src/main/resources/bootstrap.yml
###set ignoreUnresolved = false
###set ignoreNotFoundFile = false
#[resolve_spring_properties]
#Resolve spring properties
###set ignoreUnresolved = true
class.prefix.path=${server.servlet.context-path}
###set ignoreUnresolved = false
server.servlet.context-path=/demo
server:
servlet:
context-path: /demo
class.prefix.path=${server.servlet.context-path}
class.prefix.path=/demo
用于忽略 class
/method
, 不进行解析
注释在 class
上时,整个类将被忽略
注释在 method
上时,当前方法将被忽略
ignore=#ignore
@ignore
忽略当前类
@ignore
忽略当前 API
要将 API 导入到多个 Apifox 项目时才需要配置每个 module
对应一个 Apifox 项目
module=#module
用于设置 API 接口名称默认情况下, 使用 api 注释的第一行作为 API 的名称
# read api name from tag `api.name`
api.name=#api.name
用于设置 Apifox 的请求标签,默认情况下用 ,
分割
在1.1.24版本之前使用api.tag
,如需使用最新配置,请更新插件
api.tags=#tags
用于设置的请求状态,默认有 designing
,pending
,developing
,integrating
,testing
,tested
,released
,deprecated
,exception
,obsolete
api.status[#obsolete]=obsolete
API 接口说明,方法(API)的额外注释
在1.1.24版本之前使用method.doc
,如需使用最新配置,请更新插件
#deprecated info(java)
method.description[#deprecated]=groovy:"\n「已废弃」" + it.doc("deprecated")
method.description[@java.lang.Deprecated]=「已废弃」
method.description[groovy:it.containingClass().hasDoc("deprecated")]=groovy:"\n「已废弃」" + it.containingClass().doc("deprecated")
method.description[groovy:it.containingClass().hasAnn("java.lang.Deprecated")]=「已废弃」
#deprecated info(kotlin)
method.description[@kotlin.Deprecated]=groovy:"\n「已废弃」" + it.ann("kotlin.Deprecated","message")
method.description[groovy:it.containingClass().hasAnn("kotlin.Deprecated")]=groovy:"\n「已废弃」 " + it.containingClass().ann("kotlin.Deprecated","message")
method.description=@io.swagger.annotations.ApiOperation#value
在1.1.24版本之前使用 method.content.type
,如需使用最新配置,请更新插件
用于设置 API 请求默认的 content-type,
插件依然会在必要的时候强行覆盖掉
如当遇到 @RequestBody
时, 将被强行覆盖为application/json
application/x-www-form-urlencoded
, 如希望优先使用multipart/form-data
method.defaultContentType=multipart/form-data
设置默认的 api 的 HttpMethod
默认情况下, 当 API 上未指定 HttpMethod, 且无特殊参数时默认使用 GET
POST
method.default.http.method=POST
传入参数命名方式转换规则有 小驼峰 camelCase
,大驼峰 pascalCase
,下划线 snakeCase
,全小写 flatcase
,全大写 uppercase
,全大写下划线 macroCase
,大驼峰下划线 titleCase
。此规则小于全局配置,如果想要使用请设置参数命名方式转换为保持原样
method.request.replace[#requestUppercase]=uppercase
名称 | 类型 | 是否必须 | 默认值 | 备注 | 其他信息 |
---|---|---|---|---|---|
REQUESTUPPERCASE1 | string | ||||
REQUESTUPPERCASE2 | integer |
返回参数命名方式转换规则有 小驼峰 camelCase
,大驼峰 pascalCase
,下划线 snakeCase
,全小写 flatcase
,全大写 uppercase
,全大写下划线 macroCase
,大驼峰下划线 titleCase
。此规则小于全局配置,如果想要使用请设置参数命名方式转换为保持原样
method.response.replace[#responseUppercase]=uppercase
名称 | 类型 | 是否必须 | 默认值 | 备注 | 其他信息 |
---|---|---|---|---|---|
MOCK STRING | string |
API 需要额外的 header
method.additional.header={name: "Authorization",value: "",description: "认证 Token",required:true, example:""}
method.additional.header[!@com.apifox.common.annotation.Public]={name: "Authorization",value: "",description: "认证 Token",required:true}
method.additional.header[groovy:!it.hasAnn("com.apifox.common.annotation.Public")]={name: "Authorization",value: "",description: "认证 Token",required:true}
method.additional.header[groovy:it.containingClass().name().startsWith("com.test.api")]={name: "Authorization",value: "",description: "认证 Token",required:true}
method.additional.header[groovy:!it.containingClass().name().startsWith("com.test.api")]={name: "Authorization",value: "",description: "认证 Token",required:true}
method.additional.header[groovy:it.containingClass().name().startsWith("com.test.api")]={name: "a",value: "",description: "",required:true}
method.additional.header[groovy:it.containingClass().name().startsWith("com.test.api")]={name: "b",value: "",description: "",required:true}
API 需要额外的 param
仅适用于 url 参数,不支持 form
/body
param
中携带 tokenmethod.additional.param={name: "Authorization",value: "",description: "认证 Token",required:true}
method.additional.param[!@com.apifox.common.annotation.Public]={name: "Authorization",value: "",description: "认证 Token",required:true, example:""}
method.additional.param[groovy:!it.hasAnn("com.apifox.common.annotation.Public")]={name: "Authorization",value: "",description: "认证 Token",required:true, example:""}
设置方法的返回值
常用于以下情况:
<Object>
/<?>
/<*>
void
,但实际响应的是Result<UserInfo>
, 所以需要通过额外的途径来表明此API
的实际响应.method.return=#response
{@link}
来设置实际响应类型, 利用helper.resolveLink
来解析method.return[#response]=groovy: helper.resolveLink(it.doc("response"))
com.apifox.common.dto.Result
包装method.return[#response]=groovy: "com.apifox.common.dto.Result<" + helper.resolveLink(it.doc("response")) +">"
此配置仅设置返回值的核心主体, 使得 @return
的注释落在主体属性上,不影响返回类型及字段.
method.return.main[groovy:it.returnType().isExtend("com.apifox.common.dto.Result")]=data
名称 | 类型 | 是否必须 | 默认值 | 备注 | 其他信息 |
---|---|---|---|---|---|
msg | string | 非必须 | 响应消息 | mock: | |
code | integer | 非必须 | 响应码 | mock: 0 | |
data | integer | 非必须 | 响应数据 当前用户类型,[用户类型] | 枚举: 1,2,3 枚举备注: 1:管理员 2: 成员 3: 游客 |
名称 | 类型 | 是否必须 | 默认值 | 备注 | 其他信息 |
---|---|---|---|---|---|
msg | string | 非必须 | 响应消息 | mock: | |
code | integer | 非必须 | 响应码 | mock: 0 | |
+data | integer[] | 非必须 | item 类型: integer | ||
integer | 枚举: 1,2,3 枚举备注: 1:管理员 2: 成员 3: 游客 |
控制返回值类型,返回值类型有 raw/json/xml/html/binary/msgpack/eventStream
,默认返回json
method.return.body.type[#returnXml]=xml
用于当 API 有多个可用路径时如何处理目前可用策略(策略不区分大小写):
可用策略 | 策略描述 |
---|---|
FIRST | 选择第一个可用路径 |
LAST | 选择最后一个可用路径 |
LONGEST | 选 择最长的可用路径 |
SHORTEST | 选择最短的可用路径 |
ALL | 为每一个可用路径生成一个 api |
path.multi=first
path.multi=last
path.multi=longest
path.multi=shortest
path.multi=all
path.multi=#multi
用于设置 API 参数的默认值
在1.1.24版本之前使用param.default.value
,如需使用最新配置,请更新插件
param.defaultValue=@io.swagger.annotations.ApiParam#defaultValue
参数的额外注释
在1.1.24版本之前使用param.doc
,如需使用最新配置,请更新插件
param.description=js:"类型:"+it.type().name()
param.description=groovy:"类型:"+tool.uncapitalize(it.type().name().replace("java.lang.",""))
参数名称 | 是否必须 | 示例 | 备注 |
---|---|---|---|
id | 是 | 用户 id 类型: long | |
newName | 是 | 新的用户名 类型: string | |
slogan | 是 | 个人签名 类型: string | |
times | 是 | 类型: long |
用于设置 API 参数在 HTTP 请求中的类型(位置:body/form/query)
@RequestBody
/@ModelAttribute
/@RequestHeader
/@PathVariable
等忽略此规则
参数注解有 @RequestParam
且HttpMehotd
为GET
也忽略此规则
其他不满足规则的参数在规则缺省的情况下, 优先采取 query
模式
在1.1.24版本之前使用 param.http.type
,如需使用最新配置,请更新插件
param.type=form
param.type[@org.springframework.web.bind.annotation.RequestParam]=query
param.type=form
忽略 API 参数
param.ignore=@io.swagger.annotations.ApiParam#hidden
如果你希望自定义忽略 param
参数,或者使用注释的方式来忽略参数,可以使用如下配置
param.ignore=groovy:```
return session.get("json-ignore", it.name())
用于标记 API 参数是否为必须(即不可为空)
#Support for javax.validation annotations
param.required=@javax.validation.constraints.NotBlank
param.required=@javax.validation.constraints.NotNull
param.required=@javax.validation.constraints.NotEmpty
param.required=@io.swagger.annotations.ApiParam#required
参数名称 | 是否必须 | 示例 | 备注 |
---|---|---|---|
seed | 是 | 666666 | seed for mock |
用于设置 字段
的排序
name | type |
---|---|
c | integer |
propertyB | integer |
a | integer |
用于设置 字段
的排序,与比较器类似,它通过比较两个字段返回-1、0或1,以指示结果中 两个比较字段的顺序。其优先级高于field.order,一般不建议同时使用
{
"name": "",
"birthDay": "", //birthday
"age": 0, //age
"id": 0, //user id
"regtime": "", //registration time
"sex": 0, //「Deprecated」It's a secret
/**
* 1 :Administrator
* 2 :Member
* 3 :Guest
*/
"type": 0
}
用于设置 字段
的默认值
在1.1.24版本之前使用field.default.value
,如需使用最新配置,请更新插件
private Integer code = 200;//响应码
field.defaultValue=#default
名称 | 类型 | 是否必须 | 默认值 | 备注 | 其他信息 |
---|---|---|---|---|---|
price | number | 必须 | 666 | 价格 |
字段示例信息
在1.1.24版本之前使用field.demo
,如需使用最新配置,请更新插件
field.example=#example
字段的额外注释
#deprecated info(java)
field.description[#deprecated]=groovy:"\n「已废弃」" + it.description("deprecated")
field.description[@java.lang.Deprecated]=「已废弃」
#deprecated info(kotlin)
field.description[@kotlin.Deprecated]=groovy:"\n「已废弃」" + it.ann("kotlin.Deprecated","message")
field.description=@io.swagger.annotations.ApiModelProperty#value
名称 | 类型 | 是否必须 | 默认值 | 备注 | 其他信息 |
---|---|---|---|---|---|
a | string | 非必须 | 666 | 字段 A「已废弃」不再使用 |
忽略字段(设置某些字段不出现在 json 中,或不需要请求时给出)
#Support for Jackson annotations
field.ignore=@com.fasterxml.jackson.annotation.JsonIgnore#value
#Support for Gson annotations
field.ignore=!@com.google.gson.annotations.Expose#serialize
名称 | 类型 | 是否必须 | 默认值 | 备注 | 其他信息 |
---|---|---|---|---|---|
shouldNotIgnoreForGson | integer |