2

Is it possible to reference a json block from within the same rAML file for request/response examples? From the spec there does not appear to be a way to do this other than having an external file; but I'd like to have the example and schema live next to each other if possible. Much like how you can use schema:

schemas:
  - awesomeSchema: |
      { ... }
# Is this possible?
examples: | 
  - awesomeExample: |
      { ... }

/awesome:
  get:
    responses:
      200:
       body:
          application/json:
            schema: awesomeSchema
            example: awesomeExample
4

2 回答 2

1

虽然它不是规范的一部分,但它实际上是受支持的,因为 RAML 是 YAML 的超集,它确实具有DRY-ing 重复块的语法。引用规范:

重复的节点(对象)首先由锚(用 & 标记 - “&”)标识,然后被别名(用星号 - “*”引用)。

将其应用于您的示例:

/awesome:
  get:
    responses:
      200:
       body:
          application/json:
            example: &awesomeExample |
              {
                id: 123,
                type: "foobar"
              }
/delicious:
  get:
    responses:
      200:
        body:
          application/json:
            example: *awesomeExample
于 2014-07-31T10:53:27.547 回答
1

在 RAML 1.0 中是可能的,请查看https://github.com/raml-org/raml-spec/issues/107

于 2014-10-07T19:55:25.933 回答