json-schema icon indicating copy to clipboard operation
json-schema copied to clipboard

bug: nested defaults will not be applied

Open lgersman opened this issue 5 years ago • 1 comments

If a json schema provides nested defaults like this schema :

{
  "title": "Schema default properties",
  "type": "object",
  "properties": {
    "valuesInFormData": {
      "title": "Values in form data",
      "$ref": "#/definitions/defaultsExample"
    },
    "noValuesInFormData": {
      "title": "No values in form data",
      "$ref": "#/definitions/defaultsExample"
    }
  },
  "definitions": {
    "defaultsExample": {
      "type": "object",
      "properties": {
        "scalar": {
          "title": "Scalar",
          "type": "string",
          "default": "scalar default"
        },
        "array": {
          "title": "Array",
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "nested": {
                "title": "Nested array",
                "type": "string",
                "default": "nested array default"
              }
            }
          }
        },
        "object": {
          "title": "Object",
          "type": "object",
          "properties": {
            "nested": {
              "title": "Nested object",
              "type": "string",
              "default": "nested object default"
            }
          }
        }
      }
    }
  }
}

json-schema does not apply these defaults using Constraint::CHECK_MODE_APPLY_DEFAULTS flag.

only top level defaults will be applied.

lgersman avatar May 19 '20 08:05 lgersman

Hello @lgersman, we are facing the same issue. In fact, it works for nested properties of objects but it doesn't work for array types.

COil avatar Nov 20 '20 15:11 COil