0

我正在使用 RAML 来指定我的 REST 合同,我想知道是否有某种方法可以更好地在 POST 方法中编写合同。

实际上,我的 POST 方法向我显示了以下信息:

<application>
  <grammars/>
  <resources base="http://localhost:8080/ouat-servicesImpl/api">
    <resource path="/topics">
      <method name="POST">
        <request>
          <representation mediaType="application/json"/>
        </request>
        <response>
          <representation mediaType="application/json"/>
        </response>
      </method>
    </resource>
  </resources>
</application>

是否有任何配置可以在表示中公开更多细节?我尝试了标签示例,但它不起作用

我的 RAML 文件:

schemas:
  - error:       !include schemas/error.json
  - topic:       !include schemas/topic.json
  - topicCreate: !include schemas/topicCreate.json

/topics:
  description: Topic resource.
  displayName: Topic
  post:
    description: Create topic.
    securedBy: [oauth_2_0]
    body:
      application/json:
        schema: topicCreate
    responses:
      201:
        description: Success
        body:
          application/json:
            schema: topic
            example: topic
      400:
        body:
          application/json:
            schema: error
            example: error

我正在使用外部 JSON 文档,例如

{
  "$schema": "http://json-schema.org/schema",
  "type" : "object",
  "description": "The canonical topic representation.",
  "properties" : {
    "id" :       {"type" : "string"},
    "writerID" : {"type" : "string"},
    "text" :     {"type" : "string"}
  },
  "required" : ["id", "text", "writerID"]
}

就我使用了很多 SOAP 合约而言,它期望在请求和响应中看到更多信息

4

1 回答 1

1

RAML 文件中的方法规范POST看起来已经很完整了。

您唯一可以添加的是示例 JSON 实体。

编辑:JSON Schema 支持titledescription字段:您可以使用它们来完整记录您的模式成员。

于 2015-06-02T05:08:16.063 回答