KSML Schema Validation
KSML provides a JSON Schema specification file that enables IDE validation, autocompletion, and error checking for your KSML definition files. This helps you write correct KSML syntax and catch errors early in development.
The KSML project is available at: https://github.com/Axual/ksml
What is the KSML Language Specification?
The KSML Language Specification is a comprehensive JSON Schema file (docs/ksml-language-spec.json
) that defines the complete structure and syntax of KSML definition files. This schema validates:
- YAML Structure: Correct nesting and organization of KSML components (streams, tables, globalTables, functions, pipelines, producers)
- Field Names: Valid property names for operations (transformValue, filter, aggregate, join, etc.)
- Field Types: Whether a field should be a string, object, array, or boolean
- Required Fields: Which properties must be present in each component
- Configuration Structure: Proper formatting of configuration sections
Note: The schema validates YAML syntax and structure, not the semantic correctness of string values. For example, it checks that resultType
is a string, but doesn't verify if the specified type (e.g., "json"
or "avro:MySchema"
) is actually valid in your KSML context.
Schema Benefits
Using the KSML schema in your IDE provides:
- Real-time Validation: Immediate feedback on syntax errors and invalid configurations
- Autocompletion: IDE suggestions for properties, operations, and values
- Documentation: Inline help text explaining each field and operation
- Structure Validation: Ensures correct YAML structure and required fields are present
- Error Prevention: Catch configuration mistakes before deployment
Setting Up Schema Validation in IntelliJ IDEA
Follow these steps to configure KSML schema validation in IntelliJ IDEA:
Step 1: Access JSON Schema Settings
- Open IntelliJ IDEA
- Go to File → Preferences (on macOS) or File → Settings (on Windows/Linux)
- Navigate to Languages & Frameworks → Schemas and DTDs → JSON Schema Mappings
Step 2: Add KSML Schema
- Click the + (plus) button to add a new schema mapping
- Configure the mapping:
- Name:
KSML Language Specification
- Schema file or URL: Browse to
docs/ksml-language-spec.json
in your KSML project directory - Schema version: Select JSON Schema version 4
Step 3: Configure File Mappings
Add mappings for your KSML definition files by clicking + in the mappings section:
-
For specific files:
- Add individual KSML definition files (e.g.,
my-pipeline.yaml
)
- Add individual KSML definition files (e.g.,
-
For directories:
- Add a directory pattern like
**/definitions/**/*.yaml
- Add a directory pattern like
-
For file patterns:
- Add patterns like
*-pipeline.yaml
orksml-*.yaml
- Add patterns like
Setting Up Schema Validation in Visual Studio Code
For VS Code users, follow these steps:
Step 1: Install YAML Extension
- Install the YAML extension by Red Hat from the Extensions Marketplace
Step 2: Configure Schema Association
- Open Settings (Ctrl/Cmd + ,)
- Search for "yaml schemas"
- Add the following to your
settings.json
:
{
"yaml.schemas": {
"file:///path/to/ksml/docs/ksml-language-spec.json": [
"**/definitions/**/*.yaml",
"**/pipelines/**/*.yaml",
"*-pipeline.yaml",
"ksml-*.yaml"
]
}
}
Step 3: Workspace Configuration
Alternatively, create a .vscode/settings.json
file in your project root:
{
"yaml.schemas": {
"./docs/ksml-language-spec.json": [
"definitions/**/*.yaml",
"pipelines/**/*.yaml"
]
}
}
Verifying Schema Validation
Once configured, you should see:
Valid KSML Syntax
- Green underlines or checkmarks
- Autocompletion suggestions when typing
- Inline documentation on hover
Invalid Syntax Detection
- Red squiggly underlines for errors
- Error messages explaining what's wrong
- Suggestions for corrections
Example: Testing Validation
Create a test KSML file with an intentional error:
name: "Test Pipeline"
streams:
input:
topic: "input-topic"
keyType: string
valueType: json
pipelines:
test:
from: "input"
via:
- type: "invalidOperation" # This should show an error
to:
topic: "output-topic"
The schema validator should highlight invalidOperation
as an invalid operation type and suggest valid alternatives like transformValue
, filter
, etc.
Schema File Location
The KSML language specification is located at:
This file is:
- Version-controlled: Updated with each KSML release
- Comprehensive: Covers all KSML features and syntax
- Self-documenting: Includes descriptions for all properties and operations
Next Steps
With schema validation configured:
- Follow the KSML Basics Tutorial to build your first validated application