{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://catalog.lintel.tools/schemas/schemastore/cnc-codes/versions/2022-06.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-06/schema",
    "sourceSha256": "f534caae26d23b51447c88ca070f2aebbc4de06ba8b4b2fe3ab72ca00d697c24",
    "fileMatch": [
      "*.cncc.json"
    ],
    "parsers": [
      "json"
    ]
  },
  "type": "object",
  "properties": {
    "$schema": {
      "description": "Link to this schema",
      "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": "string",
      "minLength": 3,
      "maxLength": 8,
      "pattern": "[A-Za-z0-9]"
    },
    "title": {
      "description": "Descriptive title of the JSON",
      "type": "string"
    },
    "codes": {
      "description": "Individual G/M Codes",
      "type": "object",
      "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": [
    "type",
    "machineType",
    "title"
  ],
  "additionalProperties": false,
  "$defs": {
    "parameters": {
      "description": "An array of possible parameters to the code",
      "type": "object",
      "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
        }
      }
    }
  }
}
