Generate and Validate
Generate and validate in a pipeline
Section titled “Generate and validate in a pipeline”fhir-test-data and fhir-resource-diff are designed to work together. Generate a resource and pipe it directly to the validator:
fhir-test-data generate patient --locale uk --seed 42 \ | fhir-resource-diff validate - --fhir-version R4Validate annotated output
Section titled “Validate annotated output”When using --annotate, the output shape is { resource, notes } rather than a raw FHIR resource. Extract .resource with jq before piping to the validator:
fhir-test-data generate patient --locale au --annotate \ | jq '.resource' \ | fhir-resource-diff validate - --fhir-version R4Validate multiple resources (NDJSON)
Section titled “Validate multiple resources (NDJSON)”Generate several resources in NDJSON format and validate each line:
fhir-test-data generate patient --locale us --count 10 --format ndjson \ | while IFS= read -r line; do echo "$line" | fhir-resource-diff validate -; doneRegression fixtures
Section titled “Regression fixtures”Generate a bundle and compare against a baseline to detect drift:
# Generate baselinefhir-test-data generate bundle --locale us --seed 1 --output ./fixtures/baseline/
# Later: compare against baselinefhir-resource-diff compare ./fixtures/current/Bundle-001.json \ ./fixtures/baseline/Bundle-001.json \ --preset metadata \ --exit-on-diffCI fixture workflow
Section titled “CI fixture workflow”In a CI pipeline, generate fixtures deterministically with a fixed seed and commit them as test data:
# Generate deterministic fixturesfhir-test-data generate all --locale uk --seed 42 --output ./tests/fixtures/
# Validate each fixturefor f in ./tests/fixtures/*.json; do fhir-resource-diff validate "$f" --fhir-version R4 || exit 1doneWith a fixed seed, fixtures are identical across runs. Use --output to write files, then commit them. Regenerate when the resource schema changes, re-validate, and commit the diff.