API模型定义
API模型的定义保存在
app/models
目录中
API模型和Swagger的模型对象一一对应,jmms完全采用Swagger的规范来定义一个模型。
创建模型
在app/models
目录中创建一个文件{Name}.json
,其中Name
是模型的名字。
定义模型
参考Swagger Schema的定义。
Example:
{
"description": "示例模型对象",
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer",
"minimum": 0
},
"stringArray" : {
"type": "array",
"items": {
"type": "string"
}
}
}
}
数据类型
在{Model}.json
中的type
也可以直接使用数据类型的写法。
Example:
{
"properties": {
"stringArray" : {
"type": "string[]"
}
}
}
引用类型
引用类型的属性可以直接写type={Referenced Model Name}
。