yj-schema-validator
1. YAML Schema Validator
YJ Schema Validator is a lightweight Java CLI tool for validating YAML and JSON files against JSON Schema definitions (drafts 2019-09/2020-12). Built with Spring Boot for easy bootstrapping, it uses Jackson for parsing and NetworkNT for robust validation. Perfect for quick local checks or automated CI/CD pipelines.
2. Features
-
Dual Format Support: Validates YAML and JSON files seamlessly.
-
Remote Schemas: Fetch schemas via HTTP/HTTPS (with timeout & SSL ignore options).
-
Flexible Outputs: Console (colored), JSON, YAML, JUnit (alpha) for CI integration.
-
Batch Processing: Validate multiple files in one run; exits 0 on success, 1 on failure.
-
Schema Override: Ignore embedded
$schema
in files for centralized control. -
Java 17+ compatible; no external deps beyond the fat JAR.
3. Installation
Download the latest fat JAR from Maven Central:
curl -L -o yj-schema-validator.jar https://repo1.maven.org/maven2/org/alexmond/yj-schema-validator/{page-component-version}/yj-schema-validator-{page-component-version}.jar
Verify: java -jar yj-schema-validator.jar --help
Build from source (requires Maven and Java 17+):
git clone https://github.com/alexmond/yj-schema-validator.git
cd yj-schema-validator
mvn clean package
java -jar target/yj-schema-validator-{page-component-version}.jar --help
4. Usage
Basic syntax: java -jar yj-schema-validator.jar [options] <file1> <file2> …
4.1. Quick Start
Validate a single file (assumes schema in file’s $schema
):
java -jar yj-schema-validator.jar config.yaml
Validation Result: ok
config.yaml: ok
With explicit schema:
java -jar yj-schema-validator.jar config.yaml --schema=schema.json
Batch with JUnit report (for CI):
java -jar yj-schema-validator.jar *.yaml --schema=schema.json --report-type=junit --report-file-name=report.xml
4.2. CI/CD Integration Example (GitHub Actions)
- name: Validate Schemas
run: |
curl -L -o yj-schema-validator.jar https://repo1.maven.org/maven2/org/alexmond/yj-schema-validator/{page-component-version}/yj-schema-validator-{page-component-version}.jar
java -jar yj-schema-validator.jar config/*.yaml --schema=schema.json --report-type=junit --report-file-name=report.xml
# Use actions like 'dorny/test-reporter' to publish report.xml
5. Configuration
Flag |
Description |
Default |
Example |
|
Show usage help |
N/A |
|
|
Path to input YAML/JSON file(s) (positional args also supported) |
N/A |
`--files=app.yaml or "app.yaml,config.json" |
|
Path or URL to JSON Schema file |
Embedded |
|
|
Output format: |
|
|
|
Output file for non-console reports |
stdout |
|
|
Enable/disable colored output |
|
|
|
Timeout (seconds) for remote schema fetches |
10 |
|
|
Skip SSL certificate validation for HTTPS schemas |
|
|
|
Ignore |
|
|
6. Troubleshooting
Issue | Cause | Solution |
---|---|---|
"No schema found" |
Missing |
Provide via flag or embed in file. |
YAML parse error |
Invalid syntax |
Check line/col in error; use |
HTTP timeout |
Slow remote schema |
Increase |
JUnit alpha issues |
Experimental |
Report bugs; fallback to JSON. |
For SSL issues: Use --ignore-ssl-errors
(not recommended for production).
7. Contributing
-
Fork the repo and create a feature branch (
git checkout -b feat/amazing-feature
). -
Commit changes (
git commit -m 'Add some AmazingFeature'
). -
Push to the branch (
git push origin feat/amazing-feature
). -
Open a Pull Request.
Build and test locally:
mvn clean package
mvn test
See open issues for details.
8. License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
9. Acknowledgments
-
Built on NetworkNT JSON Schema Validator.
-
Thanks to contributors: List here.