Hanlde empty discriminator

This commit is contained in:
Roman Hotsiy 2016-04-13 15:46:41 +03:00
parent 6d2a49fb13
commit 823c0e60c5
5 changed files with 13 additions and 7 deletions

View File

@ -11,7 +11,7 @@
<table *ngIf="!schema.isTrivial" class="params-wrap" [ngClass]="{'params-array': schema._isArray}">
<!-- <caption> {{_displayType}} </caption> -->
<template ngFor [ngForOf]="schema.properties" #prop="$implicit" #last="last">
<tr class="param" [ngClass]="{'last': last, 'discriminator': prop.isDiscriminator, 'complex': prop._pointer}">
<tr class="param" [ngClass]="{'last': last, 'discriminator': prop.isDiscriminator && !derivedEmtpy, 'complex': prop._pointer}">
<td class="param-name">
<span class="param-name-content">{{prop._name}}</span>
</td>
@ -44,10 +44,10 @@
</td>
</tr>
</template>
<tr *ngIf="schema.derived.length" class="param-wrap discriminator-wrap">
<tr *ngIf="schema.derived.length" class="param-wrap discriminator-wrap" [ngClass]="{'empty': derivedEmtpy}">
<td colspan="2">
<div class="derived-schema" *ngFor="#derived of schema.derived" [ngClass]="{active: derived.active}">
<json-schema [childFor]="pointer" pointer="{{derived.$ref}}" [final]="derived.final" class="discriminator-part">
<json-schema *ngIf="!derived.empty" [childFor]="pointer" pointer="{{derived.$ref}}" [final]="derived.final" class="discriminator-part">
</json-schema>
</div>
</td>

View File

@ -27,6 +27,8 @@ export default class JsonSchema extends BaseComponent {
subSchema.active = false;
});
subClass.active = true;
this.derivedEmtpy = false;
if (subClass.empty) this.derivedEmtpy = true;
}
unwrapArray(schema) {
@ -54,13 +56,13 @@ export default class JsonSchema extends BaseComponent {
runInjectors(schema, schema, schema._pointer || this.pointer);
schema.derived = schema.derived || [];
if (schema.derived.length) schema.derived[0].active = true;
if (!schema.isTrivial) {
this.prepareObjectPropertiesData(schema);
}
this.schema = schema;
if (schema.derived.length) this.selectDerived(schema.derived[0]);
}
prepareObjectPropertiesData(schema) {

View File

@ -141,7 +141,7 @@ json-schema[nesteven="true"] {
}
}
.discriminator-wrap > td {
.discriminator-wrap:not(.empty) > td {
//border-left: $line-border;
padding: 0;
position: relative;

View File

@ -179,7 +179,11 @@ export default class SchemaManager {
});
if (idx < 0) continue;
res.push({name: defName, $ref: `#/definitions/${defName}`});
let empty = false;
if (subTypes.length === 1) {
empty = true;
}
res.push({name: defName, $ref: `#/definitions/${defName}`, empty});
}
return res;
}

View File

@ -238,7 +238,7 @@ describe('Utils', () => {
let deriveDefs = schemaMgr.findDerivedDefinitions('#/definitions/Pet');
deriveDefs.should.be.instanceof(Array);
deriveDefs.should.not.be.empty();
deriveDefs.should.be.deepEqual([{name: 'Cat', $ref: '#/definitions/Cat'}, {name: 'Dog', $ref: '#/definitions/Dog'}]);
deriveDefs.should.be.deepEqual([{name: 'Cat', empty: false, $ref: '#/definitions/Cat'}, {name: 'Dog', empty: false, $ref: '#/definitions/Dog'}]);
});
it('should return emtpy array for definitions that dont have discriminator', () => {