Skip to content

Instantly share code, notes, and snippets.

@JustinGrote
Created December 4, 2023 22:22
Show Gist options
  • Save JustinGrote/60e0a4f3736f36fe3b1f8d138d5c84b8 to your computer and use it in GitHub Desktop.
Save JustinGrote/60e0a4f3736f36fe3b1f8d138d5c84b8 to your computer and use it in GitHub Desktop.
Snippet JSON Schema Attempt
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"any": {
"anyOf": [
{ "$ref": "#/definitions/tabstop" },
{ "$ref": "#/definitions/placeholder" },
{ "$ref": "#/definitions/choice" },
{ "$ref": "#/definitions/variable" },
{ "$ref": "#/definitions/text" }
]
},
"tabstop": {
"anyOf": [
{ "$ref": "#/definitions/tabstopInt" },
{ "$ref": "#/definitions/tabstopIntTransform" }
]
},
"placeholder": {
"$ref": "#/definitions/placeholderIntAny"
},
"choice": {
"$ref": "#/definitions/choiceIntTextArray"
},
"variable": {
"anyOf": [
{ "$ref": "#/definitions/variableVar" },
{ "$ref": "#/definitions/variableVarAny" },
{ "$ref": "#/definitions/variableVarTransform" }
]
},
"transform": {
"$ref": "#/definitions/transformRegexFormatArrayOptions"
},
"format": {
"anyOf": [
{ "$ref": "#/definitions/formatInt" },
{ "$ref": "#/definitions/formatIntCase" },
{ "$ref": "#/definitions/formatIntIf" },
{ "$ref": "#/definitions/formatIntElse" }
]
},
"regex": {
"type": "string",
"pattern": "^/.*/[a-zA-Z]*$"
},
"options": {
"type": "string",
"pattern": "^[a-zA-Z]*$"
},
"var": {
"type": "string",
"pattern": "^[_a-zA-Z][_a-zA-Z0-9]*$"
},
"int": {
"type": "integer",
"minimum": 0
},
"text": {
"type": "string"
}
},
"definitions": {
"tabstopInt": {
"type": "integer",
"minimum": 0
},
"tabstopIntTransform": {
"type": "object",
"properties": {
"tabstop": { "$ref": "#/definitions/tabstopInt" },
"transform": { "$ref": "#/definitions/transform" }
},
"required": ["tabstop", "transform"],
"additionalProperties": false
},
"placeholderIntAny": {
"type": "object",
"properties": {
"placeholder": { "$ref": "#/definitions/placeholderInt" },
"any": { "$ref": "#/definitions/any" }
},
"required": ["placeholder", "any"],
"additionalProperties": false
},
"placeholderInt": {
"type": "integer",
"minimum": 0
},
"choiceIntTextArray": {
"type": "object",
"properties": {
"choice": { "$ref": "#/definitions/choiceInt" },
"text": {
"type": "array",
"items": { "type": "string" },
"minItems": 1
}
},
"required": ["choice", "text"],
"additionalProperties": false
},
"choiceInt": {
"type": "integer",
"minimum": 0
},
"variableVar": {
"type": "string",
"pattern": "^[_a-zA-Z][_a-zA-Z0-9]*$"
},
"variableVarAny": {
"type": "object",
"properties": {
"variable": { "$ref": "#/definitions/variableVar" },
"any": { "$ref": "#/definitions/any" }
},
"required": ["variable", "any"],
"additionalProperties": false
},
"variableVarTransform": {
"type": "object",
"properties": {
"variable": { "$ref": "#/definitions/variableVar" },
"transform": { "$ref": "#/definitions/transform" }
},
"required": ["variable", "transform"],
"additionalProperties": false
},
"transformRegexFormatArrayOptions": {
"type": "object",
"properties": {
"transform": { "$ref": "#/definitions/transform" },
"regex": { "$ref": "#/definitions/regex" },
"format": {
"type": "array",
"items": {
"anyOf": [
{ "$ref": "#/definitions/formatInt" },
{ "$ref": "#/definitions/formatIntCase" },
{ "$ref": "#/definitions/formatIntIf" },
{ "$ref": "#/definitions/formatIntElse" },
{ "$ref": "#/definitions/text" }
]
},
"minItems": 1
},
"options": { "$ref": "#/definitions/options" }
},
"required": ["transform", "regex", "format", "options"],
"additionalProperties": false
},
"formatInt": {
"type": "integer",
"minimum": 0
},
"formatIntCase": {
"type": "object",
"properties": {
"format": { "$ref": "#/definitions/formatInt" },
"case": {
"type": "string",
"enum": [
"/upcase",
"/downcase",
"/capitalize",
"/camelcase",
"/pascalcase"
]
}
},
"required": ["format", "case"],
"additionalProperties": false
},
"formatIntIf": {
"type": "object",
"properties": {
"format": { "$ref": "#/definitions/formatInt" },
"if": { "type": "string" }
},
"required": ["format", "if"],
"additionalProperties": false
},
"formatIntElse": {
"type": "object",
"properties": {
"format": { "$ref": "#/definitions/formatInt" },
"else": { "type": "string" }
},
"required": ["format", "else"],
"additionalProperties": false
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment