{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://umltimate.quicko.org.in/schema/v1/umltimate.json",
  "title": "UMLtimateSchema",
  "description": "This schema defines a JSON Schema document made with UMLtimate, and every extension that UMLtimate adds to standard JSON Schema 2020-12. UMLtimate is a tool to design object models (classes, enums, inheritance and relationships) and export them as JSON Schema. Validators ignore the extensions; code generators read them. Use @company.quicko/jsonschema-to-typescript-objects-generator 2.0.0-beta or later: version 1.x does not read 'x-enum' and names enum members after their values.",

  "type": "object",
  "required": ["$schema", "definitions"],
  "properties": {
    "$schema": {
      "description": "The JSON Schema dialect of the document. UMLtimate writes 2020-12. Documents from older versions use draft-07.",
      "type": "string",
      "enum": ["https://json-schema.org/draft/2020-12/schema", "http://json-schema.org/draft-07/schema#"]
    },
    "$comment": {
      "description": "A note for people who read the document. UMLtimate writes the URL of this schema here.",
      "type": "string"
    },
    "title": {
      "description": "The name of the data model.",
      "type": "string"
    },
    "metadata": {
      "description": "Information about the data model as a whole.",
      "$ref": "#/$defs/metadata"
    },
    "definitions": {
      "description": "The classes and enums of the data model. Each key is the name of one class or enum. Use PascalCase names: code generators use the key as the class name.",
      "type": "object",
      "additionalProperties": { "$ref": "#/$defs/definition" }
    },
    "$defs": {
      "description": "The classes and enums that come from libraries. The data model refers to them but does not own them. Code generators import these types from a package and do not generate them.",
      "type": "object",
      "additionalProperties": { "$ref": "#/$defs/libraryDefinition" }
    },
    "oneOf": {
      "description": "The values that a document of this data model can hold at its root: one object of a concrete class, or a list of them. Abstract classes are not in this list.",
      "type": "array",
      "items": { "type": "object" }
    }
  },

  "$defs": {
    "definition": {
      "description": "One class or one enum of the data model.",
      "anyOf": [{ "$ref": "#/$defs/enumDefinition" }, { "$ref": "#/$defs/classDefinition" }]
    },

    "libraryDefinition": {
      "description": "One class or one enum that comes from a library. It has the same shape as a definition. Its metadata tells code generators which package to import it from.",
      "allOf": [{ "$ref": "#/$defs/definition" }],
      "properties": {
        "metadata": { "$ref": "#/$defs/metadata" }
      }
    },

    "enumDefinition": {
      "description": "An enum: a fixed set of values. The standard keyword 'enum' holds the values that a document can contain. The extension 'x-enum' gives each value a name for code and a description.",
      "examples": [
        {"type": "string", "description": "Where the taxpayer lives for tax purposes.", "enum": ["resident", "non_resident_indian"], "x-enum": [{"key": "RESIDENT", "value": "resident", "description": "Resident and ordinarily resident"}, {"key": "NRI", "value": "non_resident_indian"}]}
      ],
      "type": "object",
      "required": ["enum"],
      "properties": {
        "title": { "description": "The name of the enum.", "type": "string" },
        "description": { "description": "What the enum is for.", "type": "string" },
        "type": {
          "description": "The type of the values. UMLtimate writes 'number' when all values are numbers, otherwise 'string'.",
          "enum": ["string", "number"]
        },
        "enum": {
          "description": "The values that a document can contain. This is standard JSON Schema, so validators check it. Documents from older UMLtimate versions put {key, value} objects here; that format is deprecated because validators then expect the whole object as the value.",
          "type": "array",
          "minItems": 1,
          "items": {
            "anyOf": [{ "type": "string" }, { "type": "number" }, { "$ref": "#/$defs/legacyEnumValue" }]
          }
        },
        "x-enum": { "$ref": "#/$defs/x-enum" },
        "metadata": { "$ref": "#/$defs/metadata" }
      }
    },

    "x-enum": {
      "description": "Extension. One entry for each value in 'enum'. An entry gives the value its name in generated code and an optional description. Entries match values by 'value', not by position. A value without an entry gets its name from the value in uppercase.",
      "type": "array",
      "items": { "$ref": "#/$defs/x-enumEntry" },
      "examples": [
        [
          { "key": "RESIDENT", "value": "resident", "description": "Resident and ordinarily resident" },
          { "key": "NRI", "value": "non_resident_indian" }
        ]
      ]
    },

    "x-enumEntry": {
      "description": "The code name and description of one enum value.",
      "type": "object",
      "required": ["key", "value"],
      "additionalProperties": false,
      "properties": {
        "key": {
          "description": "The name of the value in generated code, for example the TypeScript enum member. Use letters, digits and underscores, and do not start with a digit.",
          "type": "string",
          "pattern": "^[A-Za-z_$][A-Za-z0-9_$]*$"
        },
        "value": {
          "description": "The value as it appears in a document. It must also be in 'enum'.",
          "type": ["string", "number"]
        },
        "description": {
          "description": "What the value means. Code generators write it as a comment above the enum member.",
          "type": "string"
        }
      }
    },

    "legacyEnumValue": {
      "description": "Deprecated. The format that older UMLtimate versions wrote inside 'enum'. UMLtimate still reads it. New documents use plain values in 'enum' and the names in 'x-enum'.",
      "type": "object",
      "required": ["key"],
      "properties": {
        "key": { "type": "string" },
        "value": { "type": ["string", "number"] },
        "description": { "type": "string" }
      }
    },

    "classDefinition": {
      "description": "A class: an object with named properties. A class that extends another class uses 'allOf': the first item refers to the parent, the second item holds the properties that this class adds.",
      "examples": [
        {"type": "object", "description": "A person who files a return.", "properties": {"@entity": {"type": "string", "const": "org.quicko.tax_payer"}, "pan": {"type": "string", "pattern": "^[A-Z]{5}[0-9]{4}[A-Z]$"}, "residential_status": {"$ref": "#/definitions/ResidentialStatus"}, "addresses": {"type": "array", "items": {"$ref": "#/definitions/Address"}}}, "required": ["@entity", "pan"], "additionalProperties": false},
        {"description": "Salary from an employer.", "allOf": [{"$ref": "#/definitions/Income"}, {"type": "object", "properties": {"@entity": {"type": "string", "const": "org.quicko.salary_income"}, "employer_name": {"type": "string"}}, "required": ["@entity"]}], "unevaluatedProperties": false},
        {"type": "object", "description": "Any income head.", "x-abstract": true, "properties": {"amount": {"type": "number", "minimum": 0}}, "required": ["amount"]}
      ],
      "type": "object",
      "properties": {
        "title": { "description": "The name of the class.", "type": "string" },
        "description": {
          "description": "What the class is for. On an abstract class, UMLtimate also writes the text '{ abstract: true }' at the end. Code generators read this text to make the class abstract. 'x-abstract' holds the same information in a form that is easier to read.",
          "type": "string"
        },
        "type": { "const": "object" },
        "properties": {
          "description": "The properties of the class. Each value is a standard JSON Schema. A property whose name is the discriminator property (by default '@entity') has a 'const' on each concrete class; the value names the class in documents. Extension: a property whose type is an enum also carries 'enumType', the name of that enum's definition, next to its '$ref' (or next to 'items' for a list of enum values). Validators ignore it; the code generator reads it to type enum properties, and needs it for lists of enum values.",
          "type": "object"
        },
        "required": {
          "description": "The names of the properties that a document must contain.",
          "type": "array",
          "items": { "type": "string" }
        },
        "allOf": {
          "description": "For a class that extends another class: the first item is a $ref to the parent class, and the second item holds the properties that this class adds.",
          "type": "array",
          "minItems": 2,
          "maxItems": 2
        },
        "additionalProperties": {
          "description": "Standard JSON Schema. UMLtimate writes false on a class that has no parent and no child classes, so a document cannot contain unknown properties. A 'base' class allows other properties and has true.",
          "type": "boolean"
        },
        "unevaluatedProperties": {
          "description": "Standard JSON Schema 2020-12. UMLtimate writes false on a class that extends another class. Unlike 'additionalProperties', it also counts the properties that the parent defines, so a document that uses the parent's properties stays valid.",
          "type": "boolean"
        },
        "x-abstract": {
          "description": "Extension. true when the class is abstract: documents never contain an object of this class itself, only objects of its child classes. Abstract classes are not in the root 'oneOf'.",
          "type": "boolean"
        },
        "discriminator": { "$ref": "#/$defs/discriminator" },
        "metadata": { "$ref": "#/$defs/metadata" }
      }
    },

    "discriminator": {
      "description": "Extension, from OpenAPI. It is on a class that has child classes. It names the property that tells which child class an object is, and maps each value of that property to a class. Validators ignore it. The child classes set the same value with 'const' on that property.",
      "type": "object",
      "required": ["propertyName"],
      "additionalProperties": false,
      "properties": {
        "propertyName": {
          "description": "The name of the property that tells which class an object is. UMLtimate uses '@entity' unless the setting is changed.",
          "type": "string"
        },
        "mapping": {
          "description": "For each value of the property, a $ref to the class that the value names.",
          "type": "object",
          "additionalProperties": { "type": "string" }
        }
      },
      "examples": [
        {
          "propertyName": "@entity",
          "mapping": {
            "org.quicko.salary_income": "#/definitions/SalaryIncome",
            "org.quicko.capital_gain": "#/definitions/CapitalGain"
          }
        }
      ]
    },

    "metadata": {
      "description": "Extension. Information about the data model, or about a class or enum that comes from a library. The keys below have a fixed meaning. Other keys are free text that UMLtimate keeps on import and export.",
      "type": "object",
      "properties": {
        "x-typescript-package": {
          "description": "The npm package that contains the generated TypeScript code for this type. Code generators import the type from this package and do not generate it. Use it on library types in '$defs'.",
          "type": "string",
          "examples": ["@org-quicko/core"]
        },
        "x-origin": {
          "description": "The URL of the schema that this type was copied from. UMLtimate uses it to find and update the library when you import the document again. UMLtimate does not write it into exported files.",
          "type": "string",
          "format": "uri"
        }
      },
      "additionalProperties": { "type": "string" }
    }
  }
}
