Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Json-schema evolution always not compatible with earlier version #1529

Closed
tatitati opened this issue Jul 9, 2020 · 2 comments
Closed

Comments

@tatitati
Copy link

tatitati commented Jul 9, 2020

Hi people, thanks for this cool tool. Is awesome. I'm trying to use json-schemas for my developments, however I'm having something that still I don't understand:

I'm trying to do a very basic json-schema evolution: From this:

{
  "$id": "http://example.com/myURI.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "properties": {
    "myField1": {
      "type": "integer"
    }
  },
  "required": ["myField1"],
  "type": "object"
}

To this new version, which adds another field "myField2", but is not required.

{
  "$id": "http://example.com/myURI.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "properties": {
    "myField1": {
      "type": "integer"
    },
    "myField2": {
      "type": "integer", 
      "default": 0
    }
  },
  "required": [
    "myField1"
  ],
  "type": "object"
}

However I have always in schema registry UI:

Schema being registered is incompatible with an earlier schema

Am I missing something?

@rayokota
Copy link
Member

rayokota commented Jul 9, 2020

You need to specify "additionalProperties": false on the original schema. That is because otherwise the first schema can accept JSON documents with "myField2": "foo" which would not be compatible with the second schema.

@big-andy-coates
Copy link
Contributor

I ran into the same issue. In fact, if you're looking for full compatibility then you're out of luck. While it's technically possible to add and remove optional properties with full compatibility checks, there are some serious hoops to jump through. This makes it, IMHO, not workable as a solution.

I've detailed my findings in a quick post, the second part of which proposes a more user friendly approach to implementing JSON Schema compatibility checks.

I've raised #2927 to get feedback and look at the potential of including this in the Schema Registry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants