diff --git a/lib/components/JsonSchema/json-schema.ts b/lib/components/JsonSchema/json-schema.ts index 1d8acc4a..cee7aa64 100644 --- a/lib/components/JsonSchema/json-schema.ts +++ b/lib/components/JsonSchema/json-schema.ts @@ -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); }