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

More user-friendly JSON Schema compatibility checks #2927

Open
big-andy-coates opened this issue Jan 12, 2024 · 2 comments
Open

More user-friendly JSON Schema compatibility checks #2927

big-andy-coates opened this issue Jan 12, 2024 · 2 comments

Comments

@big-andy-coates
Copy link
Contributor

big-andy-coates commented Jan 12, 2024

tl;dr; I'm proposed a better way to perform schema compatibility checks for JSON Schema, that allows the addition and removal of optional properties. See part 2 post for details.

They've been a few issues raised in the past by people being surprised how restrictive the compatibility checks are for JSON schema types:

Robert wrote a post explaining why it is the way it is and proposed a solution for full compatible schema changes using patternProperties. Unfortunately, using patternProperties is very restrictive and verbose, e.g. here's my stab at such a schema before I added any actual properties:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Verbose and restrictive partially open content model",
  "$ref": "#/definitions/obj",
  "definitions": {
    "obj": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
       "^i_": { "type": "integer" },
       "^n_": { "type": "number" },
       "^s_": { "type": "string" },
       "^b_": { "type": "boolean" },
       "^o_": { "$ref": "#/definitions/obj"},
       "^ai_": { "type": "array", "items": {"type": "integer"} },
       "^an_": { "type": "array", "items": {"type": "number" } },
       "^as_": { "type": "array", "items": {"type": "string" } },
       "^ab_": { "type": "array", "items": {"type": "boolean" } },
       "^ao_": { "type": "array", "items": {"$ref": "#/definitions/obj"} }
      }
    }
  }
}

Without using a partially-open object model, like the one above, it is simply not possible to achieve full compatibility when making schema changes: there are no valid meaningful schema changes.

Other schema types allow optional properties to be added and removed while maintaining full compatibility.

I believe I've an improved model for JSON schema compatibility checks that does allow optional properties to be added and removed. I've detailed the approach in a post.

Thoughts very much appreciated all, @rayokota

@rayokota
Copy link
Member

Thanks @big-andy-coates , I'll take a look!

@big-andy-coates
Copy link
Contributor Author

Hey @rayokota, any thoughts?

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

2 participants