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

JSON compatibility check for object #1395

Closed
hhkkxxx133 opened this issue Mar 30, 2021 · 2 comments
Closed

JSON compatibility check for object #1395

hhkkxxx133 opened this issue Mar 30, 2021 · 2 comments

Comments

@hhkkxxx133
Copy link
Contributor

Hello,

I am testing the JSON compatibility check for the object. Similar to tuple, there are multiple cases when adding or removing items for an object in JSON Schema that seem incorrect.

Let me know what do you think!

Examples:

  1. Should be backward compatible - Add properties when additionalProperties false to true
"original": {
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "postal_code": {"type": "number"},
    "street": {"type": "string"}
  },
  "additionalProperties": false
},
"updated": {
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "postal_code": {"type": "number"},
    "street": {"type": "string"},
    "country": {"type": "string"}
  }
}
  1. Should be backward compatible - Remove properties when additionalProperties false to true
"original": {
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "postal_code": {"type": "number"},
    "street": {"type": "string"},
    "country": {"type": "string"}
  },
  "additionalProperties": false
},
"updated": {
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "postal_code": {"type": "number"},
    "street": {"type": "string"}
  }
}
  1. Should be backward compatible - Add properties when when additionalProperties remain false
"original": {
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "postal_code": {"type": "number"},
    "street": {"type": "string"}
  },
  "additionalProperties": false
},
"updated": {
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "postal_code": {"type": "number"},
    "street": {"type": "string"},
    "country": {"type": "string"}
  },
  "additionalProperties": false
}
  1. Should be forward compatible - Remove properties when additionalProperties remain false
"original": {
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "postal_code": {"type": "number"},
    "street": {"type": "string"},
    "country": {"type": "string"}
  },
  "additionalProperties": false
},
"updated": {
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "postal_code": {"type": "number"},
    "street": {"type": "string"}
  },
  "additionalProperties": false
}
  1. Should be backward compatible - Add properties when additionalProperties false to schema
"original": {
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "postal_code": {"type": "number"},
    "street": {"type": "string"}
  },
  "additionalProperties": false
},
"updated": {
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "postal_code": {"type": "number"},
    "street": {"type": "string"},
    "country": {"type": "string"}
  },
  "additionalProperties": {"type": "string"}
}
  1. Should be backward compatible - Remove compatible properties when additionalProperties false to schema
"original": {
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "postal_code": {"type": "number"},
    "street": {"type": "string"},
    "country": {"type": "string"}
  },
  "additionalProperties": false
},
"updated": {
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "postal_code": {"type": "number"},
    "street": {"type": "string"}
  },
  "additionalProperties": {"type": "string"}
}
  1. Should be forward compatible - Remove compatible properties when additionalProperties true to schema
"original": {
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "postal_code": {"type": "number"},
    "street": {"type": "string"},
    "country": {"type": "string"}
  },
  "additionalProperties": true
},
"updated": {
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "postal_code": {"type": "number"},
    "street": {"type": "string"}
  },
  "additionalProperties": {"type": "string"}
}
@hhkkxxx133
Copy link
Contributor Author

@jsenko Can you review the issue?

@jsenko
Copy link
Member

jsenko commented Apr 15, 2021

hi @hhkkxxx133 thanks again for testing & contributing!

  1. I agree, in general adding a new property schema should not be backward compatible, but if the additionalProperties was false, that would prevent a conflict.
  2. I've run the test and it should currently work.
  3. I agree, similar to Increase resource limit for CircleCI builds #1
  4. I agree, it is the Task/modularize #3 reversed
  5. I agree, similar to Increase resource limit for CircleCI builds #1
  6. I agree again, the problem is that the additionalProperties schema must be backward compatible with the property schema(s) that was(were) removed, so there has to be a sub-schema check.
  7. Is correct as well, but the tricky part is similar to Some more in-memory impl. #6, the property (properties) that was removed must be forward compatible with the new additionalProperties schema.

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