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

17,560

Solution 1

Referring to this issue on github here, turns out it was ok to create your own schema code, with the knowledge that the validators might not be able to capture it.

"It's technically always correct because format is extensible. However, user-defined formats will be ignored by validators that don't recognize them. And of course, if someone else is using a validator that they have configured to recognize the same name but treat it differently, then you will have an interoperability problem. However, with this particular value, full-date, it depends on your version of JSON Schema.

In draft-04 or draft-06, full-date is not an official format. Although anyone who adds it as a custom format and does not have it mean the same thing it means in RFC 3339 is asking for trouble, so you're probably fine using it this way even in those versions.

In the forthcoming (next week? hopefully?) draft-07, full-date is part of the reserved RFC 3339 format namespace, and if implemented, MUST be compatible with RFC 3339's definition of full-date. draft-07 also defines date as a synonym for full-date and recommends using it instead, as date is more common in the wild as far as I know.

Either way, this usage you're showing here is probably pretty safe since it matches RFC 3339, and as of draft-07 the standard does not enforce support but does enforce that, if implemented, it must behave as expected by RFC 3339."

Solution 2

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

Share:
17,560
Pecheneg
Author by

Pecheneg

Updated on July 05, 2022

Comments

  • Pecheneg
    Pecheneg over 1 year

    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.

  • 4givN
    4givN almost 3 years