RAML 1.0 - 单个响应的多个示例

时间:2016-08-15 21:00:47

标签: syntax raml

我无法在任何地方找到任何使用!include演示多个示例的代码。我试图尝试以下方法:

200:
  description: Successful project creation
  body:
    application/json:
      type: JiraResponseSuccess
      example: !include examples/jira/projects/success/CreateSuccess.json
400:
  description: User error
  body:
    application/json:
      type: JiraResponseError
      examples:
        username: 
          !include examples/jira/projects/fail/user/UsernameFail.json
        projectKey: 
          !include examples/jira/projects/fail/user/ProjectKeyFail.json

第一个示例呈现正常(其中只有一个响应)而第二个示例没有。 syntax是正确的,但我不明白为什么它会在!include语句中窒息。我是否有错误或是否需要等待工具赶上?

2 个答案:

答案 0 :(得分:3)

您可以为正文回复示例指定不同的内容类型,即使它们实际上并不是真正的内容类型:

200:
  body:
    role/admin:
      example: !include http/list-res-200.json
    role/admin-Search-for-User:
      example: !include http/search-as-admin-res-200.json
    role/member-Search-for-User:
      example: !include http/search-as-member-res-200.json

只是因为文档工作正常,我使用RAML2HTML解析为HTML并且一切都没有问题。

答案 1 :(得分:2)

我们一直在为RAML文档做同样的事情,而且此解决方案也适用于RAML 0.8版。您在更改内容类型方面具有很大的灵活性,甚至可以包含空格和其他基本符号以提高可读性。

如@manatico所述,内容类型不必必须是有效类型,因为RAML不会对其进行验证。它只是认识到存在差异,因此可以列出多个示例。为了向客户提供清晰的信息,我建议对实际的内容类型进行开头,但是在满足您提供其他示例的需要时,请紧随其后。

  get:
    responses:
      200:
        body:
          application/json - Example - Filtering by AppId:
             example: |
                { 
                   "tagId": "475889c9-773d-462a-a4ec-099242308170"
                   "appId": "12"
                   "tagName": "school",
                   "status": "ACTIVE"
                }
          application/json - Example - No Filtering:
             example: |
                {
                   "tagId": "58237aa0-3fa6-11e6-a16b-6d3f576c1098",
                   "tagName": "exercise",
                   "status": "ACTIVE"
                },
                {
                   "tagId": "06b8b7b5-8e6b-40e9-9e48-f87dec0665e4",
                   "tagName": "camping",
                   "status": "INACTIVE"
                }