Add schema validation for collection files #369
This commit improves collection file editing and error detection directly in the IDE. It adds YAML schema, IDE configuration and automatic tests to validate it. - Introduce a YAML schema for collection file. - Use `yaml-language-server` for enhanced YAML support in VSCode. - Add telemetry disabling in `configure_vscode.py` to respect user privacy. - Add automated checks to validate YAML file structure against the schema. - Remove unused properties and do not allow them in compiler.
This commit is contained in:
192
src/application/collections/.schema.yaml
Normal file
192
src/application/collections/.schema.yaml
Normal file
@@ -0,0 +1,192 @@
|
||||
# Schema Definition for Collection Files
|
||||
# Purpose:
|
||||
# - Defines the structure and data types for collection YAML files.
|
||||
# - Enhances IDE support with features like auto-completion and error checking.
|
||||
# - Used for automated validation of YAML files to ensure data integrity.
|
||||
|
||||
$schema: 'https://json-schema.org/draft/2020-12/schema'
|
||||
|
||||
$ref: '#/definitions/Collection'
|
||||
|
||||
definitions:
|
||||
Collection:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
properties:
|
||||
os:
|
||||
type: string
|
||||
enum: [windows, macos, linux]
|
||||
scripting:
|
||||
$ref: '#/definitions/ScriptingDefinition'
|
||||
actions:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/Category'
|
||||
functions:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/Function'
|
||||
|
||||
ScriptingDefinition:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
required: [language, startCode, endCode]
|
||||
properties:
|
||||
language:
|
||||
type: string
|
||||
startCode:
|
||||
type: string
|
||||
endCode:
|
||||
type: string
|
||||
|
||||
Category:
|
||||
type: object
|
||||
allOf:
|
||||
- $ref: '#/definitions/ExecutableDefinition'
|
||||
unevaluatedProperties: false
|
||||
required: [children, category]
|
||||
properties:
|
||||
children:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/Executable'
|
||||
category:
|
||||
type: string
|
||||
|
||||
Executable:
|
||||
oneOf:
|
||||
- $ref: '#/definitions/Category'
|
||||
- $ref: '#/definitions/Script'
|
||||
|
||||
ExecutableDefinition:
|
||||
allOf:
|
||||
- $ref: '#/definitions/Documentable'
|
||||
|
||||
Script:
|
||||
type: object
|
||||
unevaluatedProperties: false
|
||||
anyOf:
|
||||
- $ref: '#/definitions/CodeScript'
|
||||
- $ref: '#/definitions/CallScript'
|
||||
|
||||
ScriptDefinition:
|
||||
type: object
|
||||
allOf:
|
||||
- $ref: '#/definitions/ExecutableDefinition'
|
||||
required: [name]
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
recommend:
|
||||
type: string
|
||||
enum: [standard, strict]
|
||||
|
||||
CodeScript:
|
||||
type: object
|
||||
unevaluatedProperties: false
|
||||
anyOf:
|
||||
- $ref: '#/definitions/ScriptDefinition'
|
||||
- $ref: '#/definitions/CodeInstruction'
|
||||
|
||||
CallScript:
|
||||
type: object
|
||||
unevaluatedProperties: false
|
||||
anyOf:
|
||||
- $ref: '#/definitions/ScriptDefinition'
|
||||
- $ref: '#/definitions/CallInstruction'
|
||||
|
||||
Documentable:
|
||||
type: object
|
||||
properties:
|
||||
docs:
|
||||
$ref: '#/definitions/Documentation'
|
||||
|
||||
Documentation:
|
||||
unevaluatedProperties: false
|
||||
oneOf:
|
||||
- type: string
|
||||
- type: array
|
||||
items:
|
||||
type: string
|
||||
|
||||
Function:
|
||||
unevaluatedProperties: false
|
||||
oneOf:
|
||||
- $ref: '#/definitions/CodeFunction'
|
||||
- $ref: '#/definitions/CallFunction'
|
||||
|
||||
FunctionDefinition:
|
||||
type: object
|
||||
required: [name]
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
parameters:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/ParameterDefinition'
|
||||
docs:
|
||||
type: string
|
||||
|
||||
ParameterDefinition:
|
||||
required: [name]
|
||||
unevaluatedProperties: false
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
optional:
|
||||
type: boolean
|
||||
|
||||
CodeFunction:
|
||||
type: object
|
||||
unevaluatedProperties: false
|
||||
allOf:
|
||||
- $ref: '#/definitions/FunctionDefinition'
|
||||
- $ref: '#/definitions/CodeInstruction'
|
||||
|
||||
CallFunction:
|
||||
type: object
|
||||
unevaluatedProperties: false
|
||||
allOf:
|
||||
- $ref: '#/definitions/FunctionDefinition'
|
||||
- $ref: '#/definitions/CallInstruction'
|
||||
|
||||
CodeInstruction:
|
||||
type: object
|
||||
required: [code]
|
||||
properties:
|
||||
code:
|
||||
type: string
|
||||
revertCode:
|
||||
type: string
|
||||
|
||||
CallInstruction:
|
||||
type: object
|
||||
required: [call]
|
||||
properties:
|
||||
call:
|
||||
$ref: '#/definitions/FunctionCalls'
|
||||
|
||||
FunctionCalls:
|
||||
unevaluatedProperties: false
|
||||
oneOf:
|
||||
- $ref: '#/definitions/FunctionCall'
|
||||
- type: array
|
||||
items:
|
||||
$ref: '#/definitions/FunctionCall'
|
||||
|
||||
FunctionCall:
|
||||
type: object
|
||||
required: [function]
|
||||
unevaluatedProperties: false
|
||||
properties:
|
||||
function:
|
||||
type: string
|
||||
parameters:
|
||||
$ref: '#/definitions/FunctionCallParameters'
|
||||
|
||||
FunctionCallParameters:
|
||||
type: object
|
||||
unevaluatedProperties: true
|
||||
additionalProperties:
|
||||
type: string
|
||||
13
src/application/collections/README.md
Normal file
13
src/application/collections/README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# Collections
|
||||
|
||||
This directory contains the **collection files**, which are the central source of truth for scripts and categories within privacy.sexy.
|
||||
|
||||
In addition to the collection files, this folder contains two special files:
|
||||
|
||||
- [`.schema.yaml`](./.schema.yaml): Provides the schema definition for collection files.
|
||||
- [`collection.yaml.d.ts`](./collection.yaml.d.ts): Defines TypeScript typings for the collection files.
|
||||
|
||||
## Additional documentation
|
||||
|
||||
- Refer to [`collection-files.md`](./../../../docs/collection-files.md) for details on the structure of these files.
|
||||
- To validate these files, use the `validate-collections-yaml` script. For instructions, see its [`README.md`](./../../../scripts/validate-collections-yaml/README.md).
|
||||
@@ -16,7 +16,7 @@ declare module '@/application/collections/*' {
|
||||
}
|
||||
|
||||
export type ExecutableData = CategoryData | ScriptData;
|
||||
export type DocumentationData = ReadonlyArray<string> | string | undefined;
|
||||
export type DocumentationData = ReadonlyArray<string> | string;
|
||||
|
||||
export interface DocumentableData {
|
||||
readonly docs?: DocumentationData;
|
||||
@@ -73,7 +73,6 @@ declare module '@/application/collections/*' {
|
||||
|
||||
export interface ScriptingDefinitionData {
|
||||
readonly language: string;
|
||||
readonly fileExtension: string;
|
||||
readonly startCode: string;
|
||||
readonly endCode: string;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
# yaml-language-server: $schema=./.schema.yaml
|
||||
# ↑ Adds a schema support in VS Code for auto-completion and validation.
|
||||
|
||||
# Structure is documented in "docs/collection-files.md"
|
||||
|
||||
os: linux
|
||||
scripting:
|
||||
language: shellscript
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
# yaml-language-server: $schema=./.schema.yaml
|
||||
# ↑ Adds a schema support in VS Code for auto-completion and validation.
|
||||
|
||||
# Structure is documented in "docs/collection-files.md"
|
||||
|
||||
os: macos
|
||||
scripting:
|
||||
language: shellscript
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
# yaml-language-server: $schema=./.schema.yaml
|
||||
# ↑ Adds a schema support in VS Code for auto-completion and validation.
|
||||
|
||||
# Structure is documented in "docs/collection-files.md"
|
||||
|
||||
os: windows
|
||||
scripting:
|
||||
language: batchfile
|
||||
|
||||
Reference in New Issue
Block a user