Sort discriminator buttons according to the enum order, fixes #39

This commit is contained in:
Roman Hotsiy 2016-04-20 22:04:30 +03:00
parent b92ebe388b
commit 6b4f1b564e
2 changed files with 17 additions and 2 deletions

View File

@ -22,7 +22,7 @@
<span class="param-range" *ngIf="prop._range"> {{prop._range}} </span>
</span>
<span *ngIf="prop.required" class="param-required">Required</span>
<div *ngIf="prop.enum" class="param-enum">
<div *ngIf="prop.enum && !prop.isDiscriminator" class="param-enum">
<span *ngFor="#enumItem of prop.enum" class="enum-value {{enumItem.type}}"> {{enumItem.val | json}} </span>
</div>
</div>

View File

@ -63,6 +63,22 @@ export default class JsonSchema extends BaseComponent {
}
this.schema = schema;
this.initDerived();
}
initDerived() {
if (!this.schema.derived.length) return;
let enumArr = this.schema.properties[this.schema.properties.length - 1].enum;
if (enumArr) {
let enumOrder = {};
enumArr.forEach((enumItem, idx) => {
enumOrder[enumItem.val] = idx;
});
this.schema.derived.sort((a, b) => {
return enumOrder[a.name] > enumOrder[b.name];
});
}
this.selectDerived(0);
}
@ -86,7 +102,6 @@ export default class JsonSchema extends BaseComponent {
propertySchema.isDiscriminator = (schema.discriminator === prop);
if (propertySchema.isDiscriminator) {
discriminatorFieldIdx = idx;
propertySchema.enum = null;
}
return propertySchema;
});