mirror of
https://github.com/Redocly/redoc.git
synced 2025-01-30 17:44:07 +03:00
Sort discriminator buttons according to the enum order, fixes #39
This commit is contained in:
parent
b92ebe388b
commit
6b4f1b564e
|
@ -22,7 +22,7 @@
|
||||||
<span class="param-range" *ngIf="prop._range"> {{prop._range}} </span>
|
<span class="param-range" *ngIf="prop._range"> {{prop._range}} </span>
|
||||||
</span>
|
</span>
|
||||||
<span *ngIf="prop.required" class="param-required">Required</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>
|
<span *ngFor="#enumItem of prop.enum" class="enum-value {{enumItem.type}}"> {{enumItem.val | json}} </span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -63,6 +63,22 @@ export default class JsonSchema extends BaseComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.schema = schema;
|
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);
|
this.selectDerived(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +102,6 @@ export default class JsonSchema extends BaseComponent {
|
||||||
propertySchema.isDiscriminator = (schema.discriminator === prop);
|
propertySchema.isDiscriminator = (schema.discriminator === prop);
|
||||||
if (propertySchema.isDiscriminator) {
|
if (propertySchema.isDiscriminator) {
|
||||||
discriminatorFieldIdx = idx;
|
discriminatorFieldIdx = idx;
|
||||||
propertySchema.enum = null;
|
|
||||||
}
|
}
|
||||||
return propertySchema;
|
return propertySchema;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user