RAML中示例json的动态填充

Eri*_*son 8 raml

我很喜欢在声明resourceType时RAML如何动态引用不同的模式:

resourceTypes:
  - collection:
      get:
        responses:
          200:
            body:
              application/json:
                schema: <<schema>>
      post:
        body:
          application/json:
            schema: <<schema>>Create
        responses:
          200:
            body:
              application/json:
                schema: <<schema>>
Run Code Online (Sandbox Code Playgroud)

在这里,我可以使用这个

/users:
  type: { collection: { schema: user } }
Run Code Online (Sandbox Code Playgroud)

和RAML将给我userGET和POST的架构响应,并使用userCreate架构发送POST请求.凉!现在我可以使用大量不同的模式重用我的集合定义.

但是现在我想要为所有内容提供示例json,我希望以<<schema>>另一种方式利用var来利用"代码重用".我希望能够做到

resourceTypes:
  - collection:
      get:
        responses:
          200:
            body:
              application/json:
                schema: <<schema>>
                example: examples/v1-<<schema>>.json
      post:
        body:
          application/json:
            schema: <<schema>>Create
            example: examples/v1-<<schema>>-create.json
        responses:
          200:
            body:
              application/json:
                schema: <<schema>>
                example: examples/v1-<<schema>>.json
Run Code Online (Sandbox Code Playgroud)

但不幸的是,这不起作用.我收到一个错误说

error: File with path "/examples/v1-%3C%3Cschema%3E%3E.json" does not exist
Run Code Online (Sandbox Code Playgroud)

所以现在我已经使用手动将它添加到我的所有集合中,/users上面的例子已成为

/users:
  type: { collection: { schema: user } }
  get:
    responses:
      200:
        body:
          application/json:
            example: !include examples/v1-user.json
  post:
    body:
      application/json:
        example: !include examples/v1-user-create.json
    responses:
      200:
        body:
          application/json:
            example: !include examples/v1-user.json
Run Code Online (Sandbox Code Playgroud)

对我来说,这只是添加示例的很多开销.特别是当我想在许多资源上重复模式时.

问题:有没有办法实现这一目标?

Rob*_*een 2

不可以,根据规范,RAML 0.8 中不允许这样做。不过,在未来的版本中可能会允许这样做。