针对raml的一些使用技巧和raml-jaxrs-maven-plugin插件的使用注意

本文介绍了raml-jaxrs-maven-plugin插件,它将RAML文件转化为Java代码,但不支持RAML 1.0和某些特性如Examples、JSON Schema生成。同时,分享了RAML的语法技巧,包括&和*的使用以及如何在0.8版中引用其他类型对象。

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中映射的名称,也可以达到目的

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值