mirror of
https://github.com/Redocly/redoc.git
synced 2024-09-21 11:18:48 +03:00
Hanlde empty discriminator
This commit is contained in:
parent
6d2a49fb13
commit
823c0e60c5
|
@ -11,7 +11,7 @@
|
||||||
<table *ngIf="!schema.isTrivial" class="params-wrap" [ngClass]="{'params-array': schema._isArray}">
|
<table *ngIf="!schema.isTrivial" class="params-wrap" [ngClass]="{'params-array': schema._isArray}">
|
||||||
<!-- <caption> {{_displayType}} </caption> -->
|
<!-- <caption> {{_displayType}} </caption> -->
|
||||||
<template ngFor [ngForOf]="schema.properties" #prop="$implicit" #last="last">
|
<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">
|
<td class="param-name">
|
||||||
<span class="param-name-content">{{prop._name}}</span>
|
<span class="param-name-content">{{prop._name}}</span>
|
||||||
</td>
|
</td>
|
||||||
|
@ -44,10 +44,10 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</template>
|
</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">
|
<td colspan="2">
|
||||||
<div class="derived-schema" *ngFor="#derived of schema.derived" [ngClass]="{active: derived.active}">
|
<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>
|
</json-schema>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -27,6 +27,8 @@ export default class JsonSchema extends BaseComponent {
|
||||||
subSchema.active = false;
|
subSchema.active = false;
|
||||||
});
|
});
|
||||||
subClass.active = true;
|
subClass.active = true;
|
||||||
|
this.derivedEmtpy = false;
|
||||||
|
if (subClass.empty) this.derivedEmtpy = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unwrapArray(schema) {
|
unwrapArray(schema) {
|
||||||
|
@ -54,13 +56,13 @@ export default class JsonSchema extends BaseComponent {
|
||||||
runInjectors(schema, schema, schema._pointer || this.pointer);
|
runInjectors(schema, schema, schema._pointer || this.pointer);
|
||||||
|
|
||||||
schema.derived = schema.derived || [];
|
schema.derived = schema.derived || [];
|
||||||
if (schema.derived.length) schema.derived[0].active = true;
|
|
||||||
|
|
||||||
if (!schema.isTrivial) {
|
if (!schema.isTrivial) {
|
||||||
this.prepareObjectPropertiesData(schema);
|
this.prepareObjectPropertiesData(schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.schema = schema;
|
this.schema = schema;
|
||||||
|
if (schema.derived.length) this.selectDerived(schema.derived[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareObjectPropertiesData(schema) {
|
prepareObjectPropertiesData(schema) {
|
||||||
|
|
|
@ -141,7 +141,7 @@ json-schema[nesteven="true"] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.discriminator-wrap > td {
|
.discriminator-wrap:not(.empty) > td {
|
||||||
//border-left: $line-border;
|
//border-left: $line-border;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
|
@ -179,7 +179,11 @@ export default class SchemaManager {
|
||||||
});
|
});
|
||||||
if (idx < 0) continue;
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,7 +238,7 @@ describe('Utils', () => {
|
||||||
let deriveDefs = schemaMgr.findDerivedDefinitions('#/definitions/Pet');
|
let deriveDefs = schemaMgr.findDerivedDefinitions('#/definitions/Pet');
|
||||||
deriveDefs.should.be.instanceof(Array);
|
deriveDefs.should.be.instanceof(Array);
|
||||||
deriveDefs.should.not.be.empty();
|
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', () => {
|
it('should return emtpy array for definitions that dont have discriminator', () => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user