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

"allOf" tag does not work when used to extend existing schema. #126

Closed
sirockin opened this issue Oct 24, 2017 · 2 comments
Closed

"allOf" tag does not work when used to extend existing schema. #126

sirockin opened this issue Oct 24, 2017 · 2 comments
Labels

Comments

@sirockin
Copy link

Probably related to #112

"allOf" tag does not work as per this sample code, which is the standard pattern for extending one schema with another:

{
  "schema":{
    "definitions": {
      "base":
      {
        "required": ["name"],
        "properties": 
        {
          "name":{"type":"string", "default":"hello world!"}
        }
      }
    },
    "allOf":[
      {"$ref":"#/definitions/base"},
      {
        "properties": 
        {
          "foo":{"type":"boolean", "default":false}
        }
      }
    ] 
  }
}
@dschnelldavis
Copy link
Owner

Actually, this pattern should work.

OneOf and anyOf will need their own special widget, but allOf is already supported, and as long as the properties of the schemas being merged don't conflict, it should render correctly.

However, it appears you've found a bug in the algorithm that merges allOf schemas.

Thanks for posting the example. I'll look into it.

@dschnelldavis
Copy link
Owner

Never mind. The allOf merging algorithm is working fine. The problem is that your schema doesn't have a "type" property.

(In some cases, angular2-json-schema-form will add "type": "object" to a schema, but only if it sees a "properties" key at the root level of the schema, which this schema doesn't have.)

To make this schema render correctly, just add "type": "object", like so:

{
  "schema": {
    "type":"object",
    "definitions": {
      "base": {
        "properties": {
          "name": { "type":"string", "default":"hello world!" }
        }
        "required": ["name"],
      }
    },
    "allOf": [
      { "$ref": "#/definitions/base" },
      {
        "properties": {
          "foo": { "type":"boolean", "default":false }
        }
      }
    ] 
  }
}

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

No branches or pull requests

2 participants