Last active
September 26, 2023 19:39
-
-
Save kevinswiber/b517d16eef878503f14f1ae1a7e4ad4b to your computer and use it in GitHub Desktop.
Spectral JSON Schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "http://json-schema.org/draft-07/schema#", | |
"$id": "@stoplight/spectral-core/meta/extensions", | |
"$defs": { | |
"Extends": { | |
"$anchor": "extends", | |
"oneOf": [ | |
{ | |
"type": "string" | |
}, | |
{ | |
"type": "array", | |
"items": { | |
"oneOf": [ | |
{ | |
"type": "string" | |
}, | |
{ | |
"type": "array", | |
"minItems": 2, | |
"additionalItems": false, | |
"items": [ | |
{ | |
"type": "string" | |
}, | |
{ | |
"enum": ["all", "recommended", "off"], | |
"errorMessage": "allowed types are \"off\", \"recommended\" and \"all\"" | |
} | |
] | |
} | |
] | |
} | |
} | |
] | |
}, | |
"Format": { | |
"$anchor": "format", | |
"type": "string", | |
"errorMessage": "must be a valid format" | |
}, | |
"Functions": { | |
"$anchor": "functions", | |
"type": "array", | |
"items": { | |
"type": "string" | |
} | |
}, | |
"FunctionsDir": { | |
"$anchor": "functionsDir", | |
"type": "string" | |
}, | |
"Function": { | |
"$anchor": "function", | |
"type": "object", | |
"properties": { | |
"function": { | |
"type": "string" | |
} | |
}, | |
"required": ["function"] | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "http://json-schema.org/draft-07/schema#", | |
"$id": "@stoplight/spectral-core/meta/rule.schema", | |
"$defs": { | |
"Then": { | |
"type": "object", | |
"allOf": [ | |
{ | |
"properties": { | |
"field": { | |
"type": "string" | |
} | |
} | |
}, | |
{ | |
"$ref": "extensions.json#/$defs/Function" | |
} | |
] | |
}, | |
"Severity": { | |
"$ref": "shared.json#/$defs/Severity" | |
} | |
}, | |
"if": { | |
"type": "object" | |
}, | |
"then": { | |
"type": "object", | |
"properties": { | |
"description": { | |
"type": "string" | |
}, | |
"documentationUrl": { | |
"type": "string", | |
"format": "url", | |
"errorMessage": "must be a valid URL" | |
}, | |
"recommended": { | |
"type": "boolean" | |
}, | |
"given": { | |
"$ref": "shared.json#/$defs/Given" | |
}, | |
"resolved": { | |
"type": "boolean" | |
}, | |
"severity": { | |
"$ref": "#/$defs/Severity" | |
}, | |
"message": { | |
"type": "string" | |
}, | |
"tags": { | |
"items": { | |
"type": "string" | |
}, | |
"type": "array" | |
}, | |
"formats": { | |
"$ref": "shared.json#/$defs/Formats" | |
}, | |
"then": { | |
"if": { | |
"type": "array" | |
}, | |
"then": { | |
"type": "array", | |
"items": { | |
"$ref": "#/$defs/Then" | |
} | |
}, | |
"else": { | |
"$ref": "#/$defs/Then" | |
} | |
}, | |
"type": { | |
"enum": ["style", "validation"], | |
"type": "string", | |
"errorMessage": "allowed types are \"style\" and \"validation\"" | |
}, | |
"extensions": { | |
"type": "object" | |
} | |
}, | |
"required": ["given", "then"], | |
"additionalProperties": false, | |
"patternProperties": { | |
"^x-": true | |
}, | |
"errorMessage": { | |
"required": "the rule must have at least \"given\" and \"then\" properties" | |
} | |
}, | |
"else": { | |
"oneOf": [ | |
{ | |
"$ref": "shared.json#/$defs/HumanReadableSeverity" | |
}, | |
{ | |
"type": "boolean" | |
} | |
] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "http://json-schema.org/draft-07/schema#", | |
"$id": "@stoplight/spectral-core/meta/ruleset.schema", | |
"type": "object", | |
"additionalProperties": false, | |
"properties": { | |
"documentationUrl": { | |
"type": "string", | |
"format": "url", | |
"errorMessage": "must be a valid URL" | |
}, | |
"description": { | |
"type": "string" | |
}, | |
"rules": { | |
"type": "object", | |
"additionalProperties": { | |
"$ref": "rule.schema.json#" | |
} | |
}, | |
"functions": { | |
"$ref": "extensions.json#/$defs/Functions" | |
}, | |
"functionsDir": { | |
"$ref": "extensions.json#/$defs/FunctionsDir" | |
}, | |
"formats": { | |
"$ref": "shared.json#/$defs/Formats" | |
}, | |
"extends": { | |
"$ref": "extensions.json#/$defs/Extends" | |
}, | |
"parserOptions": { | |
"type": "object", | |
"properties": { | |
"duplicateKeys": { | |
"$ref": "shared.json#/$defs/Severity" | |
}, | |
"incompatibleValues": { | |
"$ref": "shared.json#/$defs/Severity" | |
} | |
}, | |
"additionalProperties": false | |
}, | |
"overrides": { | |
"type": "array", | |
"minItems": 1, | |
"items": { | |
"if": { | |
"type": "object", | |
"properties": { | |
"files": { | |
"type": "array", | |
"minItems": 1, | |
"items": { | |
"type": "string", | |
"minLength": 1, | |
"pattern": "^[^#]+#" | |
}, | |
"errorMessage": "must be an non-empty array of glob patterns" | |
} | |
}, | |
"required": ["files"] | |
}, | |
"then": { | |
"type": "object", | |
"properties": { | |
"files": true, | |
"rules": { | |
"type": "object", | |
"additionalProperties": { | |
"$ref": "shared.json#/$defs/Severity" | |
}, | |
"errorMessage": { | |
"enum": "must be a valid severity level" | |
} | |
} | |
}, | |
"required": ["rules"], | |
"additionalProperties": false, | |
"errorMessage": { | |
"required": "must contain rules when JSON Pointers are defined", | |
"additionalProperties": "must not override any other property than rules when JSON Pointers are defined" | |
} | |
}, | |
"else": { | |
"allOf": [ | |
{ | |
"type": "object", | |
"properties": { | |
"files": { | |
"type": "array", | |
"minItems": 1, | |
"items": { | |
"type": "string", | |
"pattern": "[^#]", | |
"minLength": 1 | |
}, | |
"errorMessage": "must be an non-empty array of glob patterns" | |
} | |
}, | |
"required": ["files"], | |
"errorMessage": { | |
"type": "must be an override, i.e. { \"files\": [\"v2/**/*.json\"], \"rules\": {} }" | |
} | |
}, | |
{ | |
"type": "object", | |
"properties": { | |
"formats": { | |
"$ref": "shared.json#/$defs/Formats" | |
}, | |
"extends": { | |
"$ref": "#/properties/extends" | |
}, | |
"rules": { | |
"$ref": "#/properties/rules" | |
}, | |
"parserOptions": { | |
"$ref": "#/properties/parserOptions" | |
}, | |
"aliases": { | |
"$ref": "#/properties/aliases" | |
} | |
}, | |
"anyOf": [ | |
{ | |
"required": ["extends"] | |
}, | |
{ | |
"required": ["rules"] | |
} | |
] | |
} | |
] | |
} | |
}, | |
"errorMessage": { | |
"minItems": "must not be empty" | |
} | |
}, | |
"aliases": { | |
"type": "object", | |
"propertyNames": { | |
"pattern": "^[A-Za-z][A-Za-z0-9_-]*$", | |
"errorMessage": { | |
"pattern": "to avoid confusion the name must match /^[A-Za-z][A-Za-z0-9_-]*$/ regular expression", | |
"minLength": "the name of an alias must not be empty" | |
} | |
}, | |
"additionalProperties": { | |
"if": { | |
"type": "object" | |
}, | |
"then": { | |
"type": "object", | |
"properties": { | |
"description": { | |
"type": "string" | |
}, | |
"targets": { | |
"type": "array", | |
"minItems": 1, | |
"items": { | |
"type": "object", | |
"properties": { | |
"formats": { | |
"$ref": "shared.json#/$defs/Formats" | |
}, | |
"given": { | |
"$ref": "shared.json#$defs/Given/then" | |
} | |
}, | |
"required": ["formats", "given"], | |
"errorMessage": "a valid target must contain given and non-empty formats" | |
}, | |
"errorMessage": { | |
"minItems": "targets must have at least a single alias definition" | |
} | |
} | |
}, | |
"required": ["targets"], | |
"errorMessage": { | |
"required": "targets must be present and have at least a single alias definition" | |
} | |
}, | |
"else": { | |
"$ref": "shared.json#/$defs/Given/then" | |
} | |
} | |
} | |
}, | |
"patternProperties": { | |
"^x-": true | |
}, | |
"anyOf": [ | |
{ | |
"required": ["extends"] | |
}, | |
{ | |
"required": ["rules"] | |
}, | |
{ | |
"required": ["overrides"] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment