Merge branch 'master' into releases

This commit is contained in:
RedocBot 2016-04-27 20:15:21 +00:00 committed by travis@localhost
commit 197c788a0c
12 changed files with 204 additions and 27 deletions

View File

@ -12,9 +12,11 @@
<input id="schema-url-input" value='http://rebilly.github.io/SwaggerTemplateRepo/swagger.yaml'> <input id="schema-url-input" value='http://rebilly.github.io/SwaggerTemplateRepo/swagger.yaml'>
<button type="submit"> Explore </button> <button type="submit"> Explore </button>
</form> </form>
<iframe src="https://ghbtns.com/github-btn.html?user=Rebilly&repo=ReDoc&type=star&count=true&size=large"
frameborder="0" scrolling="0" width="130px" height="30px"></iframe>
</nav> </nav>
<redoc scroll-y-offset="body > nav" spec-url='http://rebilly.github.io:80/SwaggerTemplateRepo/swagger.yaml'></redoc> <redoc scroll-y-offset="body > nav" spec-url='http://rebilly.github.io/SwaggerTemplateRepo/swagger.yaml'></redoc>
<!-- ReDoc built file with all dependencies included --> <!-- ReDoc built file with all dependencies included -->
<script src="main.js"> </script> <script src="main.js"> </script>

View File

@ -105,6 +105,13 @@ nav {
box-sizing: border-box; box-sizing: border-box;
} }
nav iframe {
margin: 10px 0;
position: absolute;
right: 0;
top: 0;
}
@media (min-width: 1000px) { @media (min-width: 1000px) {
nav header { nav header {
position: absolute; position: absolute;
@ -118,4 +125,8 @@ nav {
nav header { nav header {
display: none; display: none;
} }
nav iframe {
display: none;
}
} }

View File

@ -18,7 +18,7 @@ The information about API logo
| Field Name | Type | Description | | Field Name | Type | Description |
| :-------------- | :------: | :---------- | | :-------------- | :------: | :---------- |
| url | string | The URL pointing to the spec logo. MUST be in the format of a URL | url | string | The URL pointing to the spec logo. MUST be in the format of a URL
| backgroundColor | string | background color to be used. MUST be in [CSS color syntax](https://developer.mozilla.org/en/docs/Web/CSS/color) | | backgroundColor | string | background color to be used. MUST be RGB color in [hexadecimal format] (https://en.wikipedia.org/wiki/Web_colors#Hex_triplet)
###### x-logo example ###### x-logo example
@ -30,7 +30,7 @@ json
"title": "Swagger Petstore", "title": "Swagger Petstore",
"x-logo": { "x-logo": {
"url": "https://rebilly.github.io/ReDoc/petstore-logo.png", "url": "https://rebilly.github.io/ReDoc/petstore-logo.png",
"backgroundColor": "white" "backgroundColor": "#FFFFFF"
} }
} }
} }
@ -42,7 +42,7 @@ info:
title: "Swagger Petstore" title: "Swagger Petstore"
x-logo: x-logo:
url: "https://rebilly.github.io/ReDoc/petstore-logo.png" url: "https://rebilly.github.io/ReDoc/petstore-logo.png"
backgroundColor: "white" backgroundColor: "#FFFFFF"
``` ```

View File

@ -0,0 +1,37 @@
'use strict';
import {Component, EventEmitter, ElementRef} from 'angular2/core';
import {CORE_DIRECTIVES} from 'angular2/common';
import DropKick from 'Robdel12/DropKick';
import 'Robdel12/DropKick/build/css/dropkick.css!css';
@Component({
selector: 'dropdown',
events: ['change'],
template: `
<select (change)=onChange($event.target.value)>
<ng-content></ng-content>
</select>
`,
directives: [CORE_DIRECTIVES],
styleUrls: ['./lib/common/components/DropDown/dropdown.css']
})
@Reflect.metadata('parameters', [[ElementRef]])
export class DropDown {
constructor(elem) {
this.change = new EventEmitter();
this.elem = elem.nativeElement;
}
ngAfterContentInit() {
this.inst = new DropKick(this.elem.firstElementChild, {autoWidth: true});
}
onChange(value) {
this.change.next(value);
}
destroy() {
this.inst.dispose();
}
}

View File

@ -0,0 +1,70 @@
@import '../../styles/variables';
$silver: #666D71;
$background-silver: #EEEFEF;
$border: darken($background-silver, 2%);
:host {
.dk-select {
max-width: 100%;
font-family: $headers-font;
}
.dk-selected:after {
display: none;
}
// button
.dk-selected {
color: $silver;
border-color: $silver;
padding: 0.4em 0.9em 0.4em 0.4em;
border-radius: 0.4rem;
}
.dk-select-open-down .dk-selected {
border-radius: 0.4rem;
}
.dk-select-open-down .dk-selected, .dk-selected:focus, .dk-selected:hover {
border-color: $primary-color;
color: $primary-color;
}
// tick
.dk-selected:before {
border-top-color: $silver;
border-width: .35em .35em 0;
}
.dk-select-open-down .dk-selected:before,
.dk-select-open-up .dk-selected:before {
border-bottom-color: $primary-color;
border-width: 0 .35em .35em;
}
// items
.dk-select-multi:focus .dk-select-options,
.dk-select-open-down .dk-select-options,
.dk-select-open-up .dk-select-options {
border-color: $silver;
}
.dk-select-options {
margin-top: 0.2em;
border-radius: 0.4em;
}
.dk-option {
color: $black;
padding: 0.4em 0.4em;
&:hover {
background-color: $background-silver;
}
}
.dk-option-selected {
background-color: $background-silver;
}
}

View File

@ -14,7 +14,7 @@ var cache = {};
@Component({ @Component({
selector: 'json-schema-lazy', selector: 'json-schema-lazy',
inputs: ['pointer', 'auto'], inputs: ['pointer', 'auto', 'skipReadOnly'],
template: '', template: '',
directives: [CORE_DIRECTIVES] directives: [CORE_DIRECTIVES]
}) })
@ -38,7 +38,7 @@ export default class JsonSchemaLazy {
if (this.loaded) return; if (this.loaded) return;
if (this.pointer) { if (this.pointer) {
this.dcl.loadNextToLocation(JsonSchema, this.elementRef).then((compRef) => { this.dcl.loadNextToLocation(JsonSchema, this.elementRef).then((compRef) => {
compRef.instance.pointer = this.pointer; this.initComponent(compRef);
// trigger change detection // trigger change detection
compRef.hostView.changeDetectorRef.detectChanges(); compRef.hostView.changeDetectorRef.detectChanges();
}); });
@ -58,7 +58,7 @@ export default class JsonSchemaLazy {
// FIXME: get rid of dependency on selector // FIXME: get rid of dependency on selector
if ($element.querySelector('.discriminator-wrap')) { if ($element.querySelector('.discriminator-wrap')) {
this.dcl.loadNextToLocation(JsonSchema, this.elementRef).then((compRef) => { this.dcl.loadNextToLocation(JsonSchema, this.elementRef).then((compRef) => {
compRef.instance.pointer = this.pointer; this.initComponent(compRef);
compRef.hostView.changeDetectorRef.markForCheck(); compRef.hostView.changeDetectorRef.markForCheck();
}); });
return; return;
@ -68,13 +68,18 @@ export default class JsonSchemaLazy {
}); });
} else { } else {
cache[this.pointer] = this.dcl.loadNextToLocation(JsonSchema, this.elementRef).then((compRef) => { cache[this.pointer] = this.dcl.loadNextToLocation(JsonSchema, this.elementRef).then((compRef) => {
compRef.instance.pointer = this.pointer; this.initComponent(compRef);
compRef.hostView.changeDetectorRef.markForCheck(); compRef.hostView.changeDetectorRef.markForCheck();
return compRef; return compRef;
}); });
} }
} }
initComponent(compRef) {
compRef.instance.pointer = this.pointer;
compRef.instance.skipReadOnly = this.skipReadOnly;
}
ngAfterViewInit() { ngAfterViewInit() {
if (!this.auto) return; if (!this.auto) return;
this.loadCached(); this.loadCached();

View File

@ -22,24 +22,24 @@
<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>
<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">
<span>This field value determines the exact schema:</span> <span>This field value determines the exact schema:</span>
<ul> <dropdown (change)="selectDerived($event)">
<li *ngFor="#derived of schema.derived" <option *ngFor="#derived of schema.derived; #i=index"
(click)="selectDerived(derived)" [ngClass]="{active: derived.active}"> {{derived.name}} </li> [value]="i">{{derived.name}}</option>
</ul> </dropdown>
</div> </div>
</td> </td>
</tr> </tr>
<tr class="param-schema" [ngClass]="{'param-array': prop._isArray, 'last': last}" *ngIf="prop._pointer"> <tr class="param-schema" [ngClass]="{'param-array': prop._isArray, 'last': last}" *ngIf="prop._pointer">
<td colspan="2"> <td colspan="2">
<json-schema pointer="{{prop._pointer}}" [isArray]='prop._isArray' <json-schema class="nested-schema" pointer="{{prop._pointer}}" [isArray]='prop._isArray'
class="nested-schema" [nestOdd]="!nestOdd" [attr.nesteven]="!nestOdd"> [nestOdd]="!nestOdd" [skipReadOnly]="skipReadOnly" [attr.nesteven]="!nestOdd">
</json-schema> </json-schema>
</td> </td>
</tr> </tr>
@ -47,7 +47,8 @@
<tr *ngIf="schema.derived.length" class="param-wrap discriminator-wrap" [ngClass]="{'empty': derivedEmtpy}"> <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 *ngIf="!derived.empty" [childFor]="pointer" pointer="{{derived.$ref}}" [final]="derived.final" class="discriminator-part"> <json-schema class="discriminator-part" *ngIf="!derived.empty" [childFor]="pointer"
pointer="{{derived.$ref}}" [final]="derived.final" [skipReadOnly]="skipReadOnly">
</json-schema> </json-schema>
</div> </div>
</td> </td>

View File

@ -3,15 +3,15 @@
import {ElementRef} from 'angular2/core'; import {ElementRef} from 'angular2/core';
import {RedocComponent, BaseComponent, SchemaManager} from '../base'; import {RedocComponent, BaseComponent, SchemaManager} from '../base';
import {Tabs, Tab} from '../../common/components/Tabs/tabs'; import {DropDown} from '../../common/components/DropDown/dropdown';
import JsonPointer from '../../utils/JsonPointer'; import JsonPointer from '../../utils/JsonPointer';
@RedocComponent({ @RedocComponent({
selector: 'json-schema', selector: 'json-schema',
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, DropDown],
inputs: ['isArray', 'final', 'nestOdd', 'childFor'] inputs: ['isArray', 'final', 'nestOdd', 'childFor', 'skipReadOnly']
}) })
@Reflect.metadata('parameters', [[SchemaManager], [ElementRef]]) @Reflect.metadata('parameters', [[SchemaManager], [ElementRef]])
export default class JsonSchema extends BaseComponent { export default class JsonSchema extends BaseComponent {
@ -21,8 +21,9 @@ export default class JsonSchema extends BaseComponent {
this.final = false; this.final = false;
} }
selectDerived(subClass) { selectDerived(subClassIdx) {
if (subClass.active) return; let subClass = this.schema.derived[subClassIdx];
if (!subClass || subClass.active) return;
this.schema.derived.forEach((subSchema) => { this.schema.derived.forEach((subSchema) => {
subSchema.active = false; subSchema.active = false;
}); });
@ -62,7 +63,23 @@ export default class JsonSchema extends BaseComponent {
} }
this.schema = schema; this.schema = schema;
if (schema.derived.length) this.selectDerived(schema.derived[0]); 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);
} }
prepareObjectPropertiesData(schema) { prepareObjectPropertiesData(schema) {
@ -74,7 +91,8 @@ export default class JsonSchema extends BaseComponent {
let discriminatorFieldIdx = -1; let discriminatorFieldIdx = -1;
let props = Object.keys(schema.properties).map((prop, idx) => { let props = Object.keys(schema.properties).map((prop, idx) => {
let propertySchema = schema.properties[prop]; let propertySchema = schema.properties[prop];
let propPointer = JsonPointer.join(schema._pointer || this.pointer, ['properties', prop]); let propPointer = propertySchema._pointer ||
JsonPointer.join(schema._pointer || this.pointer, ['properties', prop]);
propertySchema = JsonSchema.injectPropertyData(propertySchema, prop, propPointer); propertySchema = JsonSchema.injectPropertyData(propertySchema, prop, propPointer);
// stop endless discriminator recursion // stop endless discriminator recursion
if (propertySchema._pointer === this.childFor) { if (propertySchema._pointer === this.childFor) {
@ -84,10 +102,12 @@ 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;
}); });
if (this.skipReadOnly) {
props = props.filter(prop => !prop.readOnly);
}
// Move discriminator field to the end of properties list // Move discriminator field to the end of properties list
if (discriminatorFieldIdx > -1) { if (discriminatorFieldIdx > -1) {
let discrProp = props.splice(discriminatorFieldIdx, 1); let discrProp = props.splice(discriminatorFieldIdx, 1);
@ -205,5 +225,22 @@ const injectors = {
injectTo._range = range; injectTo._range = range;
} }
} }
},
string: {
check: propertySchema => (propertySchema.type === 'string'),
inject: (injectTo, propertySchema = injectTo) => {
var range;
if (propertySchema.minLength && propertySchema.maxLength) {
range = `[ ${propertySchema.minLength} .. ${propertySchema.maxLength} ]`;
} else if (propertySchema.maxLength) {
range = '<= ' + propertySchema.maxLength;
} else if (propertySchema.minimum) {
range = '>= ' + propertySchema.minLength;
}
if (range) {
injectTo._range = range + ' characters';
}
}
} }
}; };

View File

@ -31,7 +31,7 @@
<div class="body-param-description" innerHtml="{{data.bodyParam.description | marked}}"></div> <div class="body-param-description" innerHtml="{{data.bodyParam.description | marked}}"></div>
<div> <div>
<br> <br>
<json-schema-lazy [auto]="true" pointer="{{data.bodyParam.pointer}}/schema"> <json-schema-lazy [skipReadOnly]="true" [auto]="true" pointer="{{data.bodyParam.pointer}}/schema">
</json-schema-lazy> </json-schema-lazy>
</div> </div>
</div> </div>

View File

@ -192,12 +192,19 @@ export class BaseComponent {
if (into.type === 'object' && subSchema.properties) { if (into.type === 'object' && subSchema.properties) {
into.properties || (into.properties = {}); into.properties || (into.properties = {});
Object.assign(into.properties, subSchema.properties); Object.assign(into.properties, subSchema.properties);
Object.keys(subSchema.properties).forEach(propName => {
if (!subSchema.properties[propName]._pointer) {
subSchema.properties[propName]._pointer = subSchema._pointer ?
JsonPointer.join(subSchema._pointer, ['properties', propName]) : null;
}
});
} }
if (into.type === 'object' && subSchema.required) { if (into.type === 'object' && subSchema.required) {
into.required || (into.required = []); into.required || (into.required = []);
into.required.push(...subSchema.required); into.required.push(...subSchema.required);
} }
// don't merge _pointer
subSchema._pointer = null;
defaults(into, subSchema); defaults(into, subSchema);
} }
into.allOf = null; into.allOf = null;

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.12", "version": "0.7.13",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/Rebilly/ReDoc" "url": "git://github.com/Rebilly/ReDoc"
@ -33,6 +33,7 @@
"jspm": { "jspm": {
"configFile": "system.config.js", "configFile": "system.config.js",
"dependencies": { "dependencies": {
"Robdel12/DropKick": "github:Robdel12/DropKick@^2.1.7",
"angular2": "npm:angular2@^2.0.0-beta.12", "angular2": "npm:angular2@^2.0.0-beta.12",
"es6-shim": "github:es-shims/es6-shim@^0.33.6", "es6-shim": "github:es-shims/es6-shim@^0.33.6",
"hint.css": "npm:hint.css@^2.2.1", "hint.css": "npm:hint.css@^2.2.1",
@ -53,6 +54,11 @@
"core-js": "npm:core-js@^1.2.6", "core-js": "npm:core-js@^1.2.6",
"css": "github:systemjs/plugin-css@^0.1.18", "css": "github:systemjs/plugin-css@^0.1.18",
"systemjs/plugin-json": "github:systemjs/plugin-json@^0.1.0" "systemjs/plugin-json": "github:systemjs/plugin-json@^0.1.0"
},
"overrides": {
"github:Robdel12/DropKick@2.1.7": {
"format": "global"
}
} }
}, },
"devDependencies": { "devDependencies": {

View File

@ -37,6 +37,7 @@ System.config({
}, },
map: { map: {
"Robdel12/DropKick": "github:Robdel12/DropKick@2.1.7",
"angular2": "npm:angular2@2.0.0-beta.12", "angular2": "npm:angular2@2.0.0-beta.12",
"babel": "npm:babel-core@5.8.34", "babel": "npm:babel-core@5.8.34",
"babel-runtime": "npm:babel-runtime@5.8.34", "babel-runtime": "npm:babel-runtime@5.8.34",