We automatically generate a JSON schema from our Java model on every build of our application, and automatically publish the schema on specific CI/CD pipeline runs. We need the schema to be versioned, and schema version is different from application version.
Schema version is manually maintained in our application code; whenever we change our model, we need to manually increase schema version defined in a constant. Eventually, each schema version will be published to a website as our-schema-x.y.json.
To avoid accidentally changing the Java model (and thus schema) without updating schema version, we’d like to compare the previously published schema with the newly generated schema, and fail the build if they are semantically different.
We only care about structural schema changes, like allowed properties being added or removed, changes in allowed property (enum) values, … Non-structural changes like updated property descriptions are allowed, in which case we’d update the already published schema version.
Question is how to best perform such comparison, based on deserializing the schemas into Jackson JsonNode instances:
- Default Jackson-based comparison ignores property order, so we don’t need to worry about this
- Default Jackson-based comparison takes array order into account. I guess for enum arrays we should explicitly ignore array order, what about other JSON schema fields that take array values?
- We can remove description fields before comparison. Are there any other JSON schema fields that could potentially change without affecting the JSON structure described by the schema?
- Any other considerations/specific JSON schema properties that require special attention?