A comprehensive command-line interface for working with the Common Architecture Language Model (CALM)
NOTE: This is a CLI-only command. @finos/calm-cli does not export functions for programmatic use.
The validate command verifies that a CALM architecture conforms to a given pattern or schema. It performs comprehensive validation including JSON schema validation and Spectral-based linting, providing detailed error and warning reports in multiple output formats.
Validates a CALM architecture against a pattern with detailed error and warning reporting.
/**
* Validate that an architecture conforms to a given CALM pattern
* @command calm validate [options]
*/
interface ValidateCommandOptions {
/** Path to pattern file (file path or URL)
* CLI flags: -p, --pattern <file>
*/
pattern?: string;
/** Path to architecture file (file path or URL)
* CLI flags: -a, --architecture <file>
*/
architecture?: string;
/** Path to directory containing meta schemas
* CLI flags: -s, --schema-directory <path>
* Default: CALM_META_SCHEMA_DIRECTORY
*/
schemaDirectory?: string;
/** Fail if warnings are reported
* CLI flags: --strict
* Default: false
*/
strict?: boolean;
/** Output format: 'json', 'junit', or 'pretty'
* CLI flags: -f, --format <format>
* Default: 'json'
*/
format?: 'json' | 'junit' | 'pretty';
/** Output file path (stdout if not specified)
* CLI flags: -o, --output <file>
*/
output?: string;
/** Enable verbose logging
* CLI flags: -v, --verbose
* Default: false
*/
verbose?: boolean;
}Requirements:
pattern or architecture must be specifiedarchitecture is provided, pattern is loaded from the architecture's $schema fieldUsage Examples:
# Validate with both architecture and pattern
calm validate -a architecture.json -p pattern.json
# Validate with JSON output to file
calm validate -a architecture.json -p pattern.json -f json -o results.json
# Validate in strict mode (fail on warnings)
calm validate -a architecture.json -p pattern.json --strict
# Validate with JUnit output format (for CI/CD)
calm validate -a architecture.json -p pattern.json -f junit -o results.xml
# Validate with pretty-printed output
calm validate -a architecture.json -p pattern.json -f pretty
# Validate architecture against its embedded schema
calm validate -a architecture.json
# Use custom schema directory
calm validate -a architecture.json -p pattern.json -s ./custom-schemas
# Enable verbose logging
calm validate -a architecture.json -p pattern.json -vStructured JSON output containing validation results:
{
"jsonSchemaValidationOutputs": [],
"spectralSchemaValidationOutputs": [
{
"code": "architecture-has-no-placeholder-properties-string",
"severity": "warning",
"message": "String placeholder detected in architecture.",
"path": "/nodes/0/interfaces/0/host",
"schemaPath": "",
"line_start": 10,
"line_end": 10,
"character_start": 18,
"character_end": 30
}
],
"hasErrors": false,
"hasWarnings": true
}XML format compatible with CI/CD systems like Jenkins:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="CALM Validation" tests="1" failures="0">
<testcase name="architecture.json" />
</testsuite>
</testsuites>Human-readable formatted output for terminal display:
✓ No errors found
⚠ 2 warnings found:
- String placeholder detected at /nodes/0/interfaces/0/host
- Numerical placeholder detected at /nodes/0/interfaces/0/portEnabled with --strict flag:
Validates architecture structure against JSON schemas:
Applies additional linting rules using Spectral:
calm validate -a ./path/to/architecture.json -p ./path/to/pattern.jsoncalm validate \
-a https://example.com/architectures/my-arch.json \
-p https://example.com/patterns/api-gateway.jsonIf architecture includes a $schema field pointing to a pattern:
{
"$schema": "https://calm.finos.org/patterns/api-gateway.json",
"nodes": [...]
}You can validate without specifying pattern:
calm validate -a architecture.jsonThe CLI will automatically load the pattern from the $schema URL.
The validate command supports loading patterns and architectures from a CALMHub instance using the user configuration file:
Via User Configuration File (~/.calm.json):
{
"calmHubUrl": "https://calmhub.example.com"
}Important: Unlike the generate command which accepts a -c, --calm-hub-url command-line option, the validate command does NOT accept --calm-hub-url as a command-line flag. The validate command will only use the CALMHub URL from the ~/.calm.json configuration file if present.
When a CALMHub URL is configured, the validate command uses it to:
-p https://calmhub.example.com/patterns/api-gateway.json)To configure CALMHub for validation:
~/.calm.json in your home directorycalmHubUrl property with your CALMHub instance URLExample with CALMHub configuration:
# After configuring ~/.calm.json with calmHubUrl
calm validate -a architecture.json -p https://calmhub.example.com/patterns/api-pattern.jsonThe pattern will be loaded from the configured CALMHub instance.
| Exit Code | Condition |
|---|---|
| 0 | Validation successful (no errors, warnings allowed in standard mode) |
| 1 | Validation failed (errors present) or strict mode with warnings |
Missing Required Options:
error: one of the required options '-p, --pattern' or '-a, --architecture' was not specifiedSolution: Provide at least one of the options.
Invalid JSON Format:
An error occurred while validating: Invalid JSON formatSolution: Verify architecture file contains valid JSON.
File Not Found:
An error occurred while validating: ENOENT: no such file or directorySolution: Verify file paths are correct.
Schema Not Found:
An error occurred while validating: Schema not foundSolution: Verify schema directory path and that required schemas are present.
Network Errors:
An error occurred while validating: Failed to fetch URLSolution: Verify URLs are accessible and network connection is available.
// Validation outcome from @finos/calm-shared
interface ValidationOutcome {
/** JSON schema validation errors */
jsonSchemaValidationOutputs: ValidationError[];
/** Spectral linting errors and warnings */
spectralSchemaValidationOutputs: SpectralError[];
/** Whether any errors were found */
hasErrors: boolean;
/** Whether any warnings were found */
hasWarnings: boolean;
}
interface ValidationError {
/** Error code (string or number) */
code: string | number;
/** Error message */
message: string;
/** JSON path to error location */
path: string;
/** Schema path that failed */
schemaPath: string;
}
interface SpectralError {
/** Error/warning code */
code: string;
/** Severity level */
severity: 'error' | 'warning' | 'info' | 'hint';
/** Error/warning message */
message: string;
/** JSON path to issue location */
path: string;
/** Schema path */
schemaPath: string;
/** Line number where issue starts */
line_start: number;
/** Line number where issue ends */
line_end: number;
/** Character position where issue starts */
character_start: number;
/** Character position where issue ends */
character_end: number;
}name: Validate CALM Architecture
on: [push, pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- run: npm install -g @finos/calm-cli
- run: calm validate -a architecture.json -p pattern.json --strict -f junit -o results.xml
- uses: actions/upload-artifact@v3
if: always()
with:
name: validation-results
path: results.xmlvalidate-calm:
image: node:18
script:
- npm install -g @finos/calm-cli
- calm validate -a architecture.json -p pattern.json --strict -f junit -o results.xml
artifacts:
reports:
junit: results.xml--strict to enforce zero-warning policy-v when troubleshooting validation issues$schema field for reproducibilityInstall with Tessl CLI
npx tessl i tessl/npm-finos--calm-cli