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

--help

Show usage help

N/A

--help

--files

Path to input YAML/JSON file(s) (positional args also supported)

N/A

`--files=app.yaml or "app.yaml,config.json"

--schema

Path or URL to JSON Schema file

Embedded $schema in file

--schema=schema.json or --schema=https://example.com/schema.json

--report-type

Output format: text (colored console), json, yaml, junit (alpha), sarif

text

--report-type=junit

--report-file-name

Output file for non-console reports

stdout

--report-file-name=validation.json

--color

Enable/disable colored output

true

--color=false

--http-timeout

Timeout (seconds) for remote schema fetches

10

--http-timeout=30

--ignore-ssl-errors

Skip SSL certificate validation for HTTPS schemas

false

--ignore-ssl-errors

--ignore-embedded-schema

Ignore $schema in input files (use only provided schema)

false

--ignore-embedded-schema

6. Troubleshooting

Issue Cause Solution

"No schema found"

Missing --schema

Provide via flag or embed in file.

YAML parse error

Invalid syntax

Check line/col in error; use --color=false for plain text.

HTTP timeout

Slow remote schema

Increase --http-timeout=30.

JUnit alpha issues

Experimental

Report bugs; fallback to JSON.

For SSL issues: Use --ignore-ssl-errors (not recommended for production).

7. Contributing

  1. Fork the repo and create a feature branch (git checkout -b feat/amazing-feature).

  2. Commit changes (git commit -m 'Add some AmazingFeature').

  3. Push to the branch (git push origin feat/amazing-feature).

  4. 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

10. Full Documentation