5

有没有办法让 API Kit 路由器验证传入的模式?我的 RAML 文件中有以下内容,但它不验证传入的架构。

  - emails: |
      {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type" : "object",
        "properties" : {
          "email" : {
            "type" : "string"
          },
          "name" : {
            "type" : "string"
          },
          "emailOrigin" : {
            "type" : "string"
          }
        }
      }

resourceTypes: 
  - postbase:
      post:
        responses:
          200:
            body:
              application/json:
          500:
            body:
              application/json:
  - putBase:
      put:
        responses:
          200:
            body:
              application/json:
          500:
            body:
              application/json:

/emails:
  type: postbase
  post:
    description: |
      Recieve emails captured from various parts of the site.
    body: 
     schema: emails   
4

2 回答 2

1

以下参考资料可帮助您进一步 http://forums.raml.org/t/examples-validations-in-raml-parsers/80

进一步的例子如下:employeeDetailsS​​chema.json

{
    "type": "object",
    "$schema": "http://json-schema.org/draft-03/schema",
    "id": "http://jsonschema.net",
    "required": true,
    "properties": {
        "employeeID": {
            "type": "string",  -------> Validates the Data type
            "required": true   -------> Validates whether data is present or not 
        },
        "employeeFirstName": {
            "type": "string",
            "required": true
        },
        "employeeLastName": {
            "type": "string",
            "required": true
        },
        "employeeDOB": {
            "type": "string",
            "required": true
        }
    }
}

我的 RAML 中使用的架构文件

#%RAML 0.8
title: ManageEmployees
version: 1.0

baseUri: http://api.acme.com/

mediaType: application/json


/newEmployee:
  post:
    description: Create new employees

    body:
          schema: !include com/ww/schema/employeeDetailsSchema.json

  put:
    description: Update employees details
    body:
          schema: !include com/ww/schema/employeeDetailsSchema.json

    responses:
          200: 
            body: 
              example: !include com/ww/schema/employeeExample.json
于 2015-12-11T05:44:21.643 回答
0

据我所知,任何主体都对该模式有效。所有字段都是字符串,不是必需的,不是任何特定格式。尝试根据需要放置一些字段,看看会发生什么

干杯!

于 2014-12-17T18:30:34.733 回答