Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

API Kit Router schema validation

Is there a way to have the API Kit Router validate incoming schema? I have the following in my RAML file but it does not validate the incoming schema.

  - 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   
like image 454
SteveS Avatar asked Nov 11 '22 00:11

SteveS


1 Answers

The following references help you further http://forums.raml.org/t/examples-validations-in-raml-parsers/80

Further Example as below: employeeDetailsSchema.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
        }
    }
}

Schema file used in my 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
like image 179
Sudha Ch Avatar answered Dec 06 '22 05:12

Sudha Ch