raml-jaxrs-maven-plugin是一種將raml文件轉換爲java代碼的maven插件
該插件有以下幾點注意事項:
- 目前爲止並不支持 raml 1.0 的解析
- 不支持Examples,JSON schema的生成,這裏的不支持schema生成指的是生成request代碼中,並不會同樣生成返回的schema的代碼,但是會在model目錄下生成schema實體
- 不支持外部Trait 和 Resource-Type raml資源的解析
- 可以外部定義schemas
raml的一些額外語法技巧
(1). & 和 *的用法
resourceTypes:
- base:
get?:
responses: &standardResponses
200:
description: OK
body:
application/json:
example:
put?:
responses: *standardResponses
patch?:
responses: *standardResponses
post?:
responses:
201:
description: Created
delete?:
responses: *standardResponses
&{name} - declare a block *{name} - use the block
如上片段:
在responses用 & 進行聲明standardResponses
在下面的responses用 * 進行standardResponses所標識的responses的引用
(2). raml 0.8 中引入其他類型對象
- author: |
{
"properties": {
"name": {
"type": "string"
},
"email": {
"type": "string"
},
"date": {
"description": "ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ",
"type": "string"
}
},
"type": "object"
}
- authors_info: |
{ "$schema": "http://json-schema.org/draft-03/schema",
"type": "object",
"description": "A collection of product Presentations",
"properties": {
"authors": {
"type": "array",
"items": { "$ ref": "author" }
}
}
}
raml中可以通過”$ref”的方式來引用其他schema類型,也可以以同樣方式進行非數組引用:
- authors_info: |
{ "$schema": "http://json-schema.org/draft-03/schema",
"type": "object",
"description": "A collection of product Presentations",
"properties": {
"authors": {
"$ref": "author"
}
}
}
將schema拆分後直接引用schema在raml中映射的名稱,也可以達到目的