Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In JsonSchema, the format value should be set as "full-date" or "date"?

You may use jsonSchemaLint for testing purposes.

I have this JsonSchema, which sets format as "full-date". All Draft-6 validators (Json.Net) accepts the schema as valid.

{
  "title": "MyTestSchema",
  "type": "object",
  "properties": {
    "MyDateValue": {
      "type": "string",
      "format": "full-date",
      "description": "We expect yyyy-MM-dd"
    }
  }
}

But it is unable to identify this Json object is wrong:

{
 "MyDateValue": "2017-10-1"
}

When I switch the schema from "full-date" to "date" only, it works:

 {
  "title": "MyTestSchema",
  "type": "object",
  "properties": {
    "MyDateValue": {
      "type": "string",
      "format": "date",
      "description": "We expect yyyy-MM-dd"
    }
  }
}

Is the one on the top ("full-date") correct term as Json rules? Please refer some documentation.

like image 792
Hakan Avatar asked Nov 10 '17 13:11

Hakan


1 Answers

The value should be date and not full-date please refer this documentation

Following are the valid values

  1. date-time : This SHOULD be a date in ISO 8601 format of YYYY-MM- DDThh:mm:ssZ in UTC time. This is the recommended form of date/ timestamp.

  2. date : This SHOULD be a date in the format of YYYY-MM-DD. It is recommended that you use the "date-time" format instead of "date" unless you need to transfer only the date part.

  3. time : This SHOULD be a time in the format of hh:mm:ss. It is recommended that you use the "date-time" format instead of "time" unless you need to transfer only the time part.

  4. utc-millisec : This SHOULD be the difference, measured in milliseconds, between the specified time and midnight, 00:00 of January 1, 1970 UTC. The value SHOULD be a number (integer or float).

source : here

like image 82
Ganesh Avatar answered Sep 21 '22 21:09

Ganesh