Fix #697 JSON Schema enum dropdown not working inside an array (#707)

* Fix #697 JSON Schema enum dropdown not working inside an array

* Make schema in unit test valid by adding `type: 'object'`
This commit is contained in:
Jos de Jong 2019-05-29 15:51:42 +02:00 committed by GitHub
parent f005c437db
commit 3ccdeeec40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 6 deletions

View File

@ -3,6 +3,11 @@
https://github.com/josdejong/jsoneditor
## not yet published, version 5.32.6
- Fixed #697: JSON Schema enum dropdown not working inside an array.
## 2019-04-27, version 5.32.5
- Fixed a bug in the JMESPath query wizard which didn't correctly handle

View File

@ -2659,12 +2659,6 @@ Node._findSchema = function (schema, schemaRefs, path) {
}
}
}
else if (childSchema.items && childSchema.items.properties) {
childSchema = childSchema.items.properties[key];
if (childSchema) {
foundSchema = Node._findSchema(childSchema, schemaRefs, nextPath);
}
}
else if (typeof key === 'string' && childSchema.properties) {
if (!(key in childSchema.properties)) {
foundSchema = null;

View File

@ -27,6 +27,34 @@ describe('Node', function () {
assert.strictEqual(Node._findSchema(schema, {}, path), schema.properties.child);
});
it('should find schema inside an array item', function () {
var schema = {
properties: {
job: {
type: 'array',
items: {
type: 'object',
properties: {
company: {
enum: ['test1', 'test2']
}
}
}
}
}
};
assert.strictEqual(Node._findSchema(schema, {}, []), schema);
assert.strictEqual(Node._findSchema(schema, {}, ['job']), schema.properties.job);
assert.strictEqual(Node._findSchema(schema, {}, ['job', 0]),
schema.properties.job.items);
assert.strictEqual(Node._findSchema(schema, {}, ['job', 0, 'company']),
schema.properties.job.items.properties.company);
});
it('should find schema within multi-level object properties', function () {
var schema = {
type: 'object',