Skip to content

appliedengdesign/cnccodes-json-schema

Folders and files

NameName
Last commit message
Last commit date

Latest commit

86e62bd · Jul 22, 2022

History

77 Commits
Jul 22, 2022
Jun 15, 2022
Jul 22, 2022
Jul 15, 2022
Jul 22, 2022
Jul 22, 2022
Mar 16, 2021
Jun 15, 2022
Jun 15, 2022
Mar 16, 2021
Mar 16, 2021
Jun 15, 2022
Jun 17, 2022
Jun 15, 2022
Jun 15, 2022
Jul 22, 2022
Jun 15, 2022
Jun 30, 2022
Jun 15, 2022
Jul 22, 2022
Jun 15, 2022
Jul 22, 2022
Jul 22, 2022
Jun 17, 2022
Jun 17, 2022

Repository files navigation

NPM Version NPM DL MIT License

Follow @appliedengdesign

CNCCodes JSON Schema

This project is a schema definition for using JSON to store description and usage information about G & M codes. It was developed out of a necessity for G-Code Reference. It will be updated as the needs arise for the various types of G/M codes and various Machine Tools or 3D Printers.

Latest NPM Version: v0.3.0

Latest Draft Schema Version: 2022-07

Previous Versions: 2022-06

Schema

{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://appliedengdesign.github.io/cnccodes-json-schema/draft/2022-07/schema",
    "title": "G/M Code Dictionary",
    "description": "JSON Schema for CNC G & M Codes",
    "type": "object",
    "required": [
        "title",
        "description",
        "type",
        "machineType"
    ],
    "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",
            "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"
                        }
                    },
                    "additionalProperties": false,
                    "required": [
                        "category",
                        "shortDesc"
                    ]
                },
                "additionalProperties": false
            },
            "minProperties": 1
        }
    },
    "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
                }
            },
            "minProperties": 1
        }
    }
}

Goals

Provide a an accurate JSON Schema to validate JSON files containing G & M code information.

Usage

Use the schema in your JSON that describes a set of G & M codes in your project (Or use our gcode-reference project) by adding https://appliedengdesign.github.io/cnccodes-json-schema/draft/2022-06/schema to your $schema reference in your JSON file.

Alternatively, you can install this as a package inside of your Javscript or Typescript project:

Install the latest version:

npm install @appliedengdesign/cnccodes-json-schema

Reference the schema file from node_modules:

node_modules/@appliedengdesign/cnccodes-json-schema/dist/schema/cnccodes.schema.json

Or use directly in script applications:

// Import the Schema
import { cncCodesJSONSchema } from 'cnccodes-json-schema';
// OR
const cncCodesJSONSchema = require('cnccodes-json-schema');

// Use schema with AJV
const Ajv = require('ajv').default;
const validate = ajv.compile(cncCodesJSONSchema);

Issues

If you find any bugs or issues with the package, please create a new GitHub issue.

Contributing

For information on contributing, please refer to the CONTRIBUTING doc for workflows and best practices.

About Applied Eng & Design

We are a full service engineering and design firm, specializing in CAD/CAM, CNC milling, rapid prototyping, training and more. We also like to dabble in Arudino / RaspberryPi projects, electronics, drones and robotics projects! Subscribe to our YouTube channel for videos on our projects, screencast tutorials, and more!

Follow us on Twitter & Instagram, and like our Facebook Page!

License

This extension is licensed under the MIT License.