kristianmandrup / schema-to-yup

Schema to Yup validation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Latest daft version `2020-12` is not supported

rajsenthil opened this issue · comments

I tried to create the yup schema using the jsonschema
{ "$schema": "https://json-schema.org/draft/2020-12/schema", "$ref": "#/$defs/Product", "$defs": { "Product": { "properties": { "id": { "type": "integer" }, "productType": { "type": "string", "enum": [ "Simple", "Configurable", "Grouped", "Virtual", "Bundle" ], "maxLength": 20, "minLength": 1, "title": "product type", "description": "product type", "default": "Simple", "examples": [ "Bundle", "Configurable" ] }, "product_date": { "type": "string", "format": "date-time", "message": { "required": "Product date is required", "type": "Correct format of Product Date Of Birth is yyyy-mm-ddTHH:MM:SSZ as 2006-01-02T15:04:05Z" } }, "productPrice": { "$ref": "#/$defs/ProductPrice" }, "tags": { "type": "object", "a": "b", "foo": [ "bar", "bar1" ] } }, "additionalProperties": false, "type": "object", "required": [ "id", "productType", "product_date", "productPrice" ] }, "ProductPrice": { "properties": { "regularPrice": { "type": "number" }, "markedPrice": { "type": "number" }, "discount": { "type": "integer" } }, "additionalProperties": false, "type": "object", "required": [ "regularPrice", "markedPrice" ] } } }
I validated the json schema here and it works good.
With schema-to-yup, I think it supports until draft-07 because I am getting an error invalid schema: must be type: "object", was type: undefined when trying to build buildYup(data, config) using above json-schema.
It will be helpful if you please confirm, if the draft was the issue or any other probable cause.

Sorry that I cannot change the above format and pasted below

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$ref": "#/$defs/Product",
  "$defs": {
    "Product": {
      "properties": {
        "id": {
          "type": "integer"
        },
        "productType": {
          "type": "string",
          "enum": [
            "Simple",
            "Configurable",
            "Grouped",
            "Virtual",
            "Bundle"
          ],
          "maxLength": 20,
          "minLength": 1,
          "title": "product type",
          "description": "product type",
          "default": "Simple",
          "examples": [
            "Bundle",
            "Configurable"
          ]
        },
        "product_date": {
          "type": "string",
          "format": "date-time",
          "message": {
            "required": "Product date is required",
            "type": "Correct format of Product Date Of Birth is yyyy-mm-ddTHH:MM:SSZ as 2006-01-02T15:04:05Z"
          }
        },
        "productPrice": {
          "$ref": "#/$defs/ProductPrice"
        },
        "tags": {
          "type": "object",
          "a": "b",
          "foo": [
            "bar",
            "bar1"
          ]
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "id",
        "productType",
        "product_date",
        "productPrice"
      ]
    },
    "ProductPrice": {
      "properties": {
        "regularPrice": {
          "type": "number"
        },
        "markedPrice": {
          "type": "number"
        },
        "discount": {
          "type": "integer"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "regularPrice",
        "markedPrice"
      ]
    }
  }
}

Yes, it does not support $defs with $ref and $schema. If this is a critical feature for your needs you are welcome to help me implement support for it. I think the easiest workaround for now would be to normalize it to match previous draft expectations.