codecombat / treema

jQuery plugin that generates HTML interfaces to edit JSON data defined by json-schema.
http://codecombat.github.io/treema/
MIT License
151 stars 36 forks source link

canAddProperty errors out if the schema has no properties field #50

Closed CatarinaPBressan closed 8 years ago

CatarinaPBressan commented 8 years ago

I have a schema that defines a certain object like this:

{
 "type": "object",
 "patternProperties": "<someRegex>",
 "additionalProperties": true
}

Notice that there's no properties field but there is a patternProperties field.

However, when I try to add an object to that node, treema errors out with Uncaught TypeError: Cannot read property '<property>' of undefined with the culprit being in the following generated check on the canAddProperty method (line 3097 on my file):

      if (this.workingSchema.properties[key] != null) {
        return true;
      }

I changed the above check to

      if (this.workingSchema.properties && this.workingSchema.properties[key] != null)

and it worked nicely. I don't coffescript so I can't send a PR with the fix.

sderickson commented 8 years ago

Thanks for pointing this out! Added a test and fixed that whole bit of logic.