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

Extending a schema doesn't allow overrides #22

Closed
shadoi opened this issue Jan 16, 2012 · 5 comments
Closed

Extending a schema doesn't allow overrides #22

shadoi opened this issue Jan 16, 2012 · 5 comments

Comments

@shadoi
Copy link

shadoi commented Jan 16, 2012

http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.26 where it says "A schema that extends another schema MAY define additional attributes, constrain existing attributes, or add other constraints."

Seems like it should allow me to extend a base schema and change the type of a property, for example:

{
  "name":"Parent",
  "properties":{
    "id":{
      "type":"string",
      "required":true
    }
  }
}

{
  "name":"Child",
  "extends":"Parent",
  "properties":{
    "id":{
      "type":"integer"
    }
  }
}

If I attempt to validate a Child, it complains that the "id" property is not a string.

@markolson
Copy link

As I understand it, "additional", "constrain existing" and "add" are the key words there. Redefining is not specified or supported. Beyond that, it further says:

Conceptually, the behavior of extends can be seen as validating an
instance against all constraints in the extending schema as well as
the extended schema(s).

So in your example, you would require it to be both a string and an integer.

@shadoi
Copy link
Author

shadoi commented Jan 16, 2012

I see how it would be interpreted that way, but it does seem significantly less useful without being able to do basic overriding... no?

@hoxworth
Copy link
Contributor

As @markolson said, the draft-03 specification (and the many discussions that occurred around it) state that extending a schema should be viewed as simply placing additional constraints on an existing schema.

While I agree that overriding an attribute has a lot of use, I am aiming for meeting the JSON Schema specification; the language for "extends" is currently the same in draft-04 as is it in draft-03, which is currently being discussed. There has been some movement towards an "inherits" attribute that allows for multiple schema inheritance with a defined schema merge strategy, but that is still in the design stages.

@shadoi
Copy link
Author

shadoi commented Jan 17, 2012

Understood, thanks for the response. I'll work around it for now.

On Jan 17, 2012, at 7:33 AM, Kenny Hoxworth wrote:

As @markolson said, the draft-03 specification (and the many discussions that occurred around it) state that extending a schema should be viewed as simply placing additional constraints on an existing schema.

While I agree that overriding an attribute has a lot of use, I am aiming for meeting the JSON Schema specification; the language for "extends" is currently the same in draft-04 as is it in draft-03, which is currently being discussed. There has been some movement towards an "inherits" attribute that allows for multiple schema inheritance with a defined schema merge strategy, but that is still in the design stages.


Reply to this email directly or view it on GitHub:
#22 (comment)

@kavika13
Copy link

Look into http://en.wikipedia.org/wiki/Liskov_substitution_principle

"Extends" is only for substitutability, not for code reuse. If you want code reuse, build a code generator instead :) As for whether it is "useful" or not - building type coercion into a schema definition is begging for subtle bugs and giant headaches for any software that uses that schema definition.

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

4 participants