Petr
Petr

Reputation: 6269

Testing two versions of json-schema for backwards compatibility

I have a repository that contains versioned json-schemas so for each type of schema I could have several revisions: v1, v2, v3 etc. I want to test schemas for backwards compatibility, so that any event which was valid for v1 schema is guaranteed to be valid for a v2 schema.

To do that, I need to ensure that properties are only added and never removed, non-required properties never become required and so on. Is there any library for node.js available to achieve my goal?

Upvotes: 13

Views: 925

Answers (2)

BDurand
BDurand

Reputation: 450

I see two ways of doing it,

  • Writing some kind of validation using some json-diff library to make sure that there is only properties additions, not removals

  • Implements some extensive testing to make sure that events that were correct for v1, are still for v2

Upvotes: 0

Limtorak
Limtorak

Reputation: 81

Naive question: is it something you need to do programmaticaly (i.e. regularly) or is just singular check whenever you introduce a new version ?

If it's "singular", you may try to use this website on your v1. It will generate a "fake" json based on your imposed schema. Then, by passing it to your upgraded schema versions, you should be able to make sure backward compatibility is achieved.

Note I have never used the tool myself so I don't know to which extent it deals with non-"required" fields...

Sorry if I missed your point ;)

Upvotes: 0

Related Questions