Merge branch 'master' into releases

This commit is contained in:
RedocBot 2016-04-13 12:51:17 +00:00 committed by travis@localhost
commit d211aaec6b
6 changed files with 37 additions and 12 deletions

View File

@ -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>
@ -28,7 +28,7 @@
</div> </div>
<div class="param-description" innerHtml="{{prop.description | marked}}"></div> <div class="param-description" innerHtml="{{prop.description | marked}}"></div>
<div class="discriminator-info" *ngIf="prop.isDiscriminator"> <div class="discriminator-info" *ngIf="prop.isDiscriminator">
This field value determines the exact schema: <span>This field value determines the exact schema:</span>
<ul> <ul>
<li *ngFor="#derived of schema.derived" <li *ngFor="#derived of schema.derived"
(click)="selectDerived(derived)" [ngClass]="{active: derived.active}"> {{derived.name}} </li> (click)="selectDerived(derived)" [ngClass]="{active: derived.active}"> {{derived.name}} </li>
@ -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 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>

View File

@ -11,7 +11,7 @@ import JsonPointer from '../../utils/JsonPointer';
templateUrl: './lib/components/JsonSchema/json-schema.html', templateUrl: './lib/components/JsonSchema/json-schema.html',
styleUrls: ['./lib/components/JsonSchema/json-schema.css'], styleUrls: ['./lib/components/JsonSchema/json-schema.css'],
directives: [JsonSchema, Tabs, Tab], directives: [JsonSchema, Tabs, Tab],
inputs: ['isArray', 'final', 'nestOdd'] inputs: ['isArray', 'final', 'nestOdd', 'childFor']
}) })
@Reflect.metadata('parameters', [[SchemaManager], [ElementRef]]) @Reflect.metadata('parameters', [[SchemaManager], [ElementRef]])
export default class JsonSchema extends BaseComponent { export default class JsonSchema extends BaseComponent {
@ -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) {
@ -74,9 +76,16 @@ export default class JsonSchema extends BaseComponent {
let propertySchema = schema.properties[prop]; let propertySchema = schema.properties[prop];
let propPointer = JsonPointer.join(schema._pointer || this.pointer, ['properties', prop]); let propPointer = JsonPointer.join(schema._pointer || this.pointer, ['properties', prop]);
propertySchema = JsonSchema.injectPropertyData(propertySchema, prop, propPointer); propertySchema = JsonSchema.injectPropertyData(propertySchema, prop, propPointer);
// stop endless discriminator recursion
if (propertySchema._pointer === this.childFor) {
propertySchema._pointer = null;
}
propertySchema.required = !!requiredMap[prop]; propertySchema.required = !!requiredMap[prop];
propertySchema.isDiscriminator = (schema.discriminator === prop); propertySchema.isDiscriminator = (schema.discriminator === prop);
if (propertySchema.isDiscriminator) discriminatorFieldIdx = idx; if (propertySchema.isDiscriminator) {
discriminatorFieldIdx = idx;
propertySchema.enum = null;
}
return propertySchema; return propertySchema;
}); });
// Move discriminator field to the end of properties list // Move discriminator field to the end of properties list

View File

@ -61,6 +61,12 @@ json-schema[nesteven="true"] {
> .params-wrap > .param:first-of-type > .param-name:before, > .params-wrap > .param:last-of-type > .param-name:after { > .params-wrap > .param:first-of-type > .param-name:before, > .params-wrap > .param:last-of-type > .param-name:after {
border-color: $side-menu-active-bg-color; border-color: $side-menu-active-bg-color;
} }
> .params-wrap > .param:last-of-type, > .params-wrap > .param.last {
> .param-name:after {
border-color: $side-menu-active-bg-color;
}
}
} }
.param.complex > .param-info { .param.complex > .param-info {
@ -128,9 +134,14 @@ json-schema[nesteven="true"] {
.discriminator-info { .discriminator-info {
font-weight: $regular; font-weight: $regular;
margin-bottom: 10px; margin-bottom: 10px;
> span {
font-size: 0.9em;
font-weight: $light;
}
} }
.discriminator-wrap > td { .discriminator-wrap:not(.empty) > td {
//border-left: $line-border; //border-left: $line-border;
padding: 0; padding: 0;
position: relative; position: relative;

View File

@ -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;
} }

View File

@ -1,7 +1,7 @@
{ {
"name": "redoc", "name": "redoc",
"description": "Swagger-generated API Reference Documentation", "description": "Swagger-generated API Reference Documentation",
"version": "0.7.11", "version": "0.7.12",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/Rebilly/ReDoc" "url": "git://github.com/Rebilly/ReDoc"
@ -15,7 +15,8 @@
"branch-release": "git reset --hard && branch-release", "branch-release": "git reset --hard && branch-release",
"unit": "gulp test", "unit": "gulp test",
"e2e": "gulp e2e", "e2e": "gulp e2e",
"deploy": "build/prepare_deploy.sh && deploy-to-gh-pages demo" "deploy": "build/prepare_deploy.sh && deploy-to-gh-pages demo",
"github-release": "gulp github-release"
}, },
"keywords": [ "keywords": [
"OpenAPI", "OpenAPI",

View File

@ -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', () => {