multi-schema

command
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

README

Multi-schema example

Demonstrates two-phase JSON Schema validation using WithJSONSchemaFunc around WithEnvSubst.

What it shows

  • Validate the raw manifest against a partial schema before variable substitution.
  • Expand ${VAR} placeholders with WithEnvSubst.
  • Validate the fully-substituted manifest against the complete schema after substitution.

Why two schemas?

Some fields must be structurally valid before substitution (e.g. the environments array must exist as a concrete list). Other fields may contain placeholders before substitution (e.g. service: ${APP_SERVICE}). Running one schema before and one after substitution enforces both constraints cleanly.

Pipeline

Load manifest.yaml
  → WithJSONSchemaFunc (validates environments block, no placeholders allowed)
  → WithEnvSubst (expands ${VAR} from OS environment)
  → WithJSONSchemaFunc (validates complete substituted manifest)

Run

cd examples/multi-schema && go run .

With a custom service name:

APP_SERVICE=my-api go run .

Tests

cd examples/multi-schema && go test -v

Key ideas

  1. WithJSONSchemaFunc takes a function func(*Values) ([]byte, error) so the schema can be chosen dynamically based on already-loaded values.
  2. Placing a schema step before WithEnvSubst catches unexpanded placeholders in required fields.
  3. Placing a schema step after WithEnvSubst validates the final resolved values.
  4. synthra.ConfigError carries a Path field indicating which step failed. Useful for diagnostic messages.

Documentation

Overview

Package main demonstrates two-phase validation using WithJSONSchemaFunc.

The pipeline:

  1. Load manifest YAML.
  2. Validate the "environments" block before variable substitution (the raw values must not contain unexpanded placeholders in required fields).
  3. Substitute ${VAR} placeholders from OS environment variables.
  4. Validate the fully-substituted manifest against the complete schema.

This pattern is useful when different fields have different substitution requirements: some fields must already be concrete before substitution (e.g. environment definitions), while others may contain placeholders that are expanded in a later step.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL