Job Receipt Schema: How to Check Before a Change
In this article
- What Is a Job Receipt Schema?
- Why Checking Before a Change Matters
- Where to Find the Schema
- How to Validate a Receipt Against the Schema
- How to Choose the Right Schema Versioning Strategy
- Common Problems and How to Avoid Them
- Comparing JSON Schema and XSD for Receipts
- Safety and Validation Best Practices
- Frequently Asked Questions
To check a job receipt schema before making a change, you must first locate the schema definition (usually a JSON Schema or XSD file) that validates the receipt, then validate a sample receipt against it using a schema validator tool or library. This article explains where to find the schema, how to interpret it, and how to test your changes safely without breaking downstream systems.
What Is a Job Receipt Schema?
A job receipt schema is a formal description of the structure and data types expected in a receipt that is generated after a job (e.g., a batch process, a print job, a data export) completes. It defines which fields are required, optional, their types (string, integer, object, array), and any constraints like minimum/maximum values or allowed enums. Schemas are commonly written in JSON Schema (for JSON receipts) or XSD (for XML receipts). They act as a contract between the system that produces the receipt and the systems that consume it.
Why Checking Before a Change Matters
Changing a receipt schema without checking can break consumers that parse the receipt. A consumer might expect a field to always exist, or expect a certain data type. If you add a required field, old receipts become invalid. If you change a field name, consumers that look for the old name will fail. If you change a type (e.g., from string to number), consumers that concatenate strings will break. Checking first helps you avoid these issues and lets you plan migrations.
Where to Find the Schema
Schemas are usually stored in one of these places:
- In the source code repository of the producer service, often under a
schemas/orspec/directory. - In a shared schema registry (like Confluent Schema Registry for Kafka, or a central JSON Schema store).
- Embedded in the code as a constant or generated from code annotations.
- In the documentation of the API or job system.
If you cannot find a schema file, check the consumer code to see how it parses the receipt – that effectively defines an implicit schema.
How to Validate a Receipt Against the Schema
Once you have the schema, you need a validator. For JSON Schema, popular tools include:
- ajv (Node.js)
- jsonschema (Python)
- everit (Java)
- Online validators like jsonschemavalidator.net (but be careful with sensitive data).
For XSD, tools like xmllint (command line) or XMLSpy work. The general process is:
- Get a sample receipt that represents the current output.
- Run the validator with the current schema to confirm it passes.
- Modify the schema as needed.
- Run the validator again with the same sample receipt – it should still pass (unless you intentionally made a breaking change).
- Create a new sample receipt that reflects the new fields and validate that too.
How to Choose the Right Schema Versioning Strategy
Schema changes can be backward-compatible or breaking. A common approach is to use semantic versioning for the schema itself:
- Major version – breaking changes (removing fields, changing types, adding required fields).
- Minor version – backward-compatible additions (adding optional fields).
- Patch version – fixes that don't affect structure (e.g., fixing a description).
Before making a change, decide if it is backward-compatible. If not, you may need to support multiple versions simultaneously or coordinate with consumers.
Common Problems and How to Avoid Them
- Adding a required field – This breaks all existing receipts. Make it optional or provide a default.
- Renaming a field – Consumers using the old name will break. Use
deprecatedand add a new field instead. - Changing a type – e.g., from integer to string. This can break consumers that do arithmetic. Use a new field name if the type must change.
- Ignoring
additionalProperties– If the schema setsadditionalProperties: false, adding a new field will fail validation. You may need to relax that. - Not testing with real data – Synthetic samples may not cover all real variations. Use a few real receipts if possible.
Comparing JSON Schema and XSD for Receipts
JSON Schema is more common for modern REST APIs and job systems because it is lightweight and easy to use with JavaScript/Python. XSD is older, more verbose, and used in enterprise XML-based systems. JSON Schema supports features like required, type, pattern, and enum. XSD has similar concepts but with different syntax. Choose based on your stack; the checking process is conceptually the same.
Safety and Validation Best Practices
- Always validate a receipt against the schema before sending it to consumers – catch errors early.
- Use a schema registry to enforce compatibility checks automatically on publish.
- Write unit tests that validate sample receipts against the schema.
- Document changes in a changelog so consumers know what to expect.
- If you are using a schema registry, use its compatibility mode (e.g., BACKWARD, FORWARD, FULL) to prevent accidental breaking changes.
Frequently Asked Questions
How do I check if a schema change is backward-compatible?
Run the new schema against all existing sample receipts. If any fail, the change is breaking. Also, check if any required fields were added, types changed, or fields removed – those are almost always breaking.
What if there is no schema file for my job receipt?
Look at the consumer code to see what fields it accesses. Alternatively, generate a schema from a set of sample receipts using a tool like json-schema-generator (Python) or to-json-schema (Node.js). That gives you a starting point.
Can I test a schema change without affecting production?
Yes. Use a local or staging environment. Validate sample receipts against the new schema before deploying. You can also use a schema registry that supports multiple versions and test against a specific version.
What is the best tool to validate JSON Schema?
For most developers, ajv (Node.js) is fast and supports the latest draft. In Python, jsonschema is standard. For quick checks, online validators work but avoid uploading sensitive data.
How do I handle a breaking change if I can't avoid it?
Coordinate with consumers. Announce the change, provide a migration period, and consider supporting both old and new versions simultaneously. Use a schema registry to allow consumers to choose the version they want.