SteveS
SteveS

Reputation: 1030

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   

Upvotes: 5

Views: 3734

Answers (2)

Sudha Ch
Sudha Ch

Reputation: 147

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

Upvotes: 1

nohorbee
nohorbee

Reputation: 139

As far as I can see, any body will be valid for that schema. All the fields are string, not required, not any specific format. Try putting some of the fields as required and see what happens

Cheers!

Upvotes: 0

Related Questions