{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://catalog.lintel.tools/schemas/schemastore/cnc-codes/versions/latest.json",
  "title": "G/M Code Dictionary",
  "description": "JSON Schema for CNC G & M Codes",
  "x-lintel": {
    "source": "https://appliedengdesign.github.io/cnccodes-json-schema/draft/2022-07/schema",
    "sourceSha256": "71c6eb8917b7fa66a075c85ab07fad3633ba096d3876a6b91011659ae2f12731",
    "fileMatch": [
      "*.cncc.json"
    ],
    "parsers": [
      "json"
    ]
  },
  "type": "object",
  "properties": {
    "$schema": {
      "description": "Link to this schema",
      "type": "string"
    },
    "title": {
      "description": "Descriptive title of the JSON Reference",
      "type": "string"
    },
    "description": {
      "description": "Description of the JSON Reference",
      "type": "string"
    },
    "keywords": {
      "description": "An Array of string keywords describing the JSON Reference (Optional)",
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "type": {
      "description": "The type of code (G or M)",
      "type": "string",
      "enum": [
        "gcode",
        "mcode"
      ]
    },
    "machineType": {
      "description": "The type of CNC machine",
      "type": "string",
      "enum": [
        "edm",
        "mill",
        "lathe",
        "laser",
        "printer",
        "swiss"
      ]
    },
    "variant": {
      "description": "Defined if G/M Codes are for specific MTB/3DP Variant. (Must be lower case, 3-8 characters)",
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 3,
          "maxLength": 8,
          "pattern": "[a-z0-9]"
        },
        "remove": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        }
      }
    },
    "codes": {
      "description": "Individual G/M Codes",
      "type": "object",
      "minProperties": 1,
      "patternProperties": {
        "^G|^M": {
          "type": "object",
          "properties": {
            "category": {
              "description": "Category for the code",
              "type": "string",
              "enum": [
                "motion",
                "coordinate",
                "compensation",
                "canned",
                "other",
                "mcode"
              ]
            },
            "modal": {
              "description": "Modal / Non-Modal (boolean)",
              "type": "boolean"
            },
            "shortDesc": {
              "description": "A short description of the code",
              "type": "string",
              "minLength": 3
            },
            "desc": {
              "description": "A longer description with markdown formatting",
              "type": "string",
              "minLength": 3
            },
            "parameters": {
              "$ref": "#/$defs/parameters"
            }
          },
          "required": [
            "category",
            "shortDesc"
          ],
          "additionalProperties": false
        },
        "additionalProperties": false
      }
    }
  },
  "required": [
    "title",
    "description",
    "type",
    "machineType"
  ],
  "additionalProperties": false,
  "$defs": {
    "parameters": {
      "description": "An array of possible parameters to the code",
      "type": "object",
      "minProperties": 1,
      "patternProperties": {
        "^[A-Z]{1}": {
          "type": "object",
          "properties": {
            "shortDesc": {
              "description": "A short description of the parameter",
              "type": "string",
              "minLength": 3
            },
            "desc": {
              "description": "A description of the parameter",
              "type": "string",
              "minLength": 3
            },
            "optional": {
              "description": "Parameter is required (boolean)",
              "type": "boolean"
            }
          },
          "required": [
            "shortDesc",
            "optional"
          ],
          "additionalProperties": false
        }
      }
    }
  }
}
