{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "id": "https://ngx-schema-form/schema",
  "$comment": "Definition of all types supported by ngx-schema-form",
  "title": "JSON Schema ngx-schema-form",
  "type": "object",
  "allOf": [
    {
      "$ref": "#/definitions/formWidgetType"
    },
    {
      "$ref": "http://json-schema.org/draft-07/schema#"
    }
  ],
  "definitions": {
    "widgetTypeCustom": {
      "$ref": "#/definition/stringNotBlank",
      "description": "[NSF] - The name of custom widget type to use"
    },
    "widgetTypeSimple": {
      "type": "string",
      "description": "[NSF] - The name of widget type to use",
      "enum": [
        "array",
        "object",
        "string",
        "search",
        "tel",
        "url",
        "email",
        "password",
        "color",
        "date",
        "date-time",
        "time",
        "integer",
        "number",
        "range",
        "textarea",
        "file",
        "select",
        "radio",
        "boolean",
        "checkbox",
        "button",
        "hidden"
      ]
    },
    "widgetType": {
      "type": "object",
      "description": "[NSF] - The widget type to use.",
      "properties": {
        "id": {
          "description": "[NSF] - The id of the widget.",
          "anyOf": [
            {
              "$ref": "#/definitions/widgetTypeSimple"
            },
            {
              "$ref": "#/definitions/widgetTypeCustom"
            }
          ]
        },
        "buttons": {
          "$ref": "#/definitions/buttonArrayType"
        },
        "oneOf": {
          "type": "array",
          "description": "[NSF] - Defines a collection to use for selectable widgets (SELECT, RADIO ...).",
          "items": {
            "properties": {
              "enum": {
                "type": "array",
                "items": {
                  "oneOf": [
                    {
                      "type": "string",
                      "description": "[NSF] - Any string value."
                    },
                    {
                      "type": "boolean",
                      "description": "[NSF] - Either true or false."
                    },
                    {
                      "type": "number",
                      "description": "[NSF] - Any number value."
                    },
                    {
                      "type": "null",
                      "description": "[NSF] - Null value."
                    }
                  ]
                },
                "minItems": 1,
                "uniqueItems": true,
                "description": "[NSF] - The value of this item in the selection. Only the first item will be used as value. Any value except object is allowed."
              },
              "description": {
                "type": "string",
                "description": "[NSF] - The label of this item in the selection."
              }
            }
          }
        }
      },
      "additionalProperties": true
    },
    "buttonType": {
      "description": "[NSF] - A list of buttons to trigger some action for this field.",
      "type": "object",
      "properties": {
        "label": {
          "type": "string",
          "description": "[NSF] - The label to show on the button."
        },
        "id": {
          "type": "string",
          "description": "[NSF] - The action id must match action defined in the action object."
        },
        "parameters": {
          "type": "object",
          "description": "[NSF] - Custom defined properties that will be passed to the action method."
        },
        "widget": {
          "$ref": "#/definitions/widgetTypeCustom",
          "description": "[NSF] - Custom defined widget id, that will do the rendering of this button. Will render a default button if not set."
        }
      },
      "required": [
        "id",
        "label"
      ],
      "additionalProperties": true
    },
    "buttonArrayType": {
      "description": "[NSF] - A list of buttons to trigger some action for this field.",
      "type": "array",
      "items": {
        "$ref": "#/definitions/buttonType"
      },
      "uniqueItems": true,
      "default": [],
      "minItems": 1
    },
    "fieldsArrayType": {
      "description": "[NSF] - A list of field paths.",
      "type": "array",
      "items": {
        "type": "string"
      },
      "uniqueItems": true,
      "default": []
    },
    "fieldsetsType": {
      "description": "[NSF] - A section of fields.",
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "[NSF] - The section id."
        },
        "title": {
          "type": "string",
          "description": "[NSF] - The label of the section."
        },
        "fields": {
          "description": "[NSF] - A list of property keys representing fields that belong to this sections.",
          "$ref": "#/definitions/fieldsArrayType"
        }
      },
      "required": [
        "id",
        "fields"
      ],
      "additionalProperties": true
    },
    "fieldsetsArrayType": {
      "description": "[NSF] - A list of definitions representing sections of widgets.",
      "type": "array",
      "items": {
        "$ref": "#/definitions/fieldsetsType"
      },
      "uniqueItems": true,
      "default": [],
      "minItems": 1
    },
    "visibleIfType": {
      "type": "object",
      "description": "[NSF] - Definition of when is this widget visible or not. The schema property path of target fields is expected to be separated by '/' and not by '.'. E.g. '/myform/myfield'",
      "patternProperties": {
        "^.*$": {
          "description": "[NSF] - The path to any other property. E.g: /cat/name",
          "type": "array",
          "items": {
            "anyOf": [
              {
                "type": "string",
                "enum": [
                  "$ANY$"
                ],
                "description": "[NSF] - When the field has any values set."
              },
              {
                "type": "string"
              },
              {
                "type": "boolean"
              },
              {
                "type": "null"
              },
              {
                "type": "number"
              }
            ]
          }
        }
      }
    },
    "formWidgetTypeProperties": {
      "properties": {
        "title": {
          "type": "string",
          "description": "[NSF] - The form title of the root form. Will only be showed when is an inline form"
        },
        "widget": {
          "anyOf": [
            {
              "$ref": "#/definitions/widgetTypeSimple"
            },
            {
              "$ref": "#/definitions/widgetType"
            },
            {
              "$ref": "#/definitions/widgetTypeCustom"
            }
          ]
        },
        "order": {
          "description": "[NSF] - A list of unique property keys describing the final order.",
          "$ref": "#/definitions/fieldsArrayType"
        },
        "fieldsets": {
          "$ref": "#/definitions/fieldsetsArrayType"
        },
        "buttons": {
          "$ref": "#/definitions/buttonArrayType"
        },
        "placeholder": {
          "type": "string",
          "description": "[NSF] - A placeholder to pre-fill input field. Will work with any HTML element of type input."
        },
        "visibleIf": {
          "$ref": "#/definitions/visibleIfType"
        },
        "properties": {
          "patternProperties": {
            "^.*$": {
              "allOf": [
                {
                  "$ref": "#/definitions/formWidgetTypeProperties"
                },
                {
                  "$ref": "http://json-schema.org/draft-07/schema#"
                }
              ]
            }
          }
        },
        "additionalProperties": true
      }
    },
    "formWidgetType": {
      "$ref": "#/definitions/formWidgetTypeProperties",
      "type": "object",
      "description": "[NSF] - A form widget.",
      "additionalProperties": true
    },
    "stringNotBlank": {
      "type": "string",
      "pattern": "^\\S*$",
      "minLength": 1
    }
  }
}
