Fix broken order in discriminator dropdowns

This commit is contained in:
Roman Hotsiy 2016-08-30 21:29:56 +03:00
parent f66b194e3d
commit 2be02c5aa1
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0

View File

@ -53,6 +53,20 @@ export class JsonSchema extends BaseComponent implements OnInit {
initDescendants() {
this.descendants = this.specMgr.findDerivedDefinitions(this.normPointer);
if (!this.descendants.length) return;
let discriminator = this.schema.discriminator;
let discrProperty = this.schema._properties &&
this.schema._properties.filter((prop) => prop.name === discriminator)[0];
if (discrProperty && discrProperty.enum) {
let enumOrder = {};
discrProperty.enum.forEach((enumItem, idx) => {
enumOrder[enumItem.val] = idx;
});
this.schema._descendants.sort((a, b) => {
return enumOrder[a.name] > enumOrder[b.name] ? 1 : -1;
});
}
this.selectDescendant(0);
}