Support for json-schema draft-04 required properties and date-time validation


#1

Hello,

I’ve defined json schema according to version draft-04 - below part of it.

{
  "$schema": "http://json-schema.org/draft-04/schema#",

  "definitions": {

    "summary": {
      "type": "object",
      "properties": {
        "timeRegistered": { "type": "string", "format": "date-time" },
        "projectName": { "type": "string" },
        "projectCode": { "type": "string" }
      },
      "required": ["timeRegistered", "projectCode"]
    },

  // other definitions ...

 },
  
  "type": "object",

  "properties": {
  	"summary": { "$ref": "#/definitions/summary" },

         // other properties ...

  }
}

The schema and example json object validate properly at http://json-schema-validator.herokuapp.com/

However I’m facing two issues in APIKit.

  1. It doesn’t allow to use draft-04 specification of required attributes (expects boolean version 3 syntax):

    INFO 2014-05-08 13:22:59,946 [[PMBServices].connector.http.mule.default.receiver.03] org.mule.module.apikit.validation.RestJsonSchemaValidator: Schema validation failed: /summary: domain: syntax; keyword: required; message: incorrect type for value; expected: [“boolean”]; found: "array"
    ERROR 2014-05-08 13:22:59,950 [[PMBServices].connector.http.mule.default.receiver.03] org.mule.module.apikit.MappingExceptionListener:

  2. It doesn’t validate date-time properly:

    INFO 2014-05-08 14:07:25,772 [[PMBServices].connector.http.mule.default.receiver.05] org.mule.module.apikit.validation.RestJsonSchemaValidator: Schema validation failed: /summary/timeRegistered: domain: validation; keyword: format; message: string is not a valid ISO 8601 date; format: “date-time”; value: "2014-03-01T23:20:50.52Z"
    ERROR 2014-05-08 14:07:25,776 [[PMBServices].connector.http.mule.default.receiver.05] org.mule.module.apikit.MappingExceptionListener:


    Message : /summary/timeRegistered: domain: validation; keyword: format; message: string is not a valid ISO 8601 date; format: “date-time”; value: "2014-03-01T23:20:50.52Z"
    Code : MULE_ERROR–2

    Exception stack is:

    1. /summary/timeRegistered: domain: validation; keyword: format; message: string is not a valid ISO 8601 date; format: “date-time”; value: “2014-03-01T23:20:50.52Z” (org.mule.module.apikit.exception.BadRequestException)
      org.mule.module.apikit.validation.RestJsonSchemaValidator:76 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/module/apikit/exception/BadRequestException.html)

    Root Exception stack trace:
    org.mule.module.apikit.exception.BadRequestException: /summary/timeRegistered: domain: validation; keyword: format; message: string is not a valid ISO 8601 date; format: “date-time”; value: "2014-03-01T23:20:50.52Z"
    at org.mule.module.apikit.validation.RestJsonSchemaValidator.validate(RestJsonSchemaValidator.java:76)
    at org.mule.module.apikit.HttpRestRequest.validateSchema(HttpRestRequest.java:399)
    at org.mule.module.apikit.HttpRestRequest.valideateBody(HttpRestRequest.java:308)
    + 3 more (set debug level logging or ‘-Dmule.verbose.exceptions=true’ for everything)

Am I missing something or the features are not supported?

Regards,
Marcin


#2

Hello Marcin! Thanks for your interest.

APIkit for now supports only json schema draft 0.3, so you will need to use the 0.3 versions of the settings that you want to apply.

  1. for the required, you need to specify them for every property.
  2. for the date, you can check here: http://tools.ietf.org/rfcdiff?url1=draft-zyp-json-schema-03.txt&url2=draft-zyp-json-schema-04.txt, version 5.23 of the 0.3 part.

Hope this helps!
Fede