Merge commit '41dcaaafd0e4ee37f9018bd4f885c5e552617eda' into releases

This commit is contained in:
RedocBot 2016-07-15 21:32:35 +00:00 committed by travis@localhost
commit 1c17f94621
19 changed files with 84 additions and 96 deletions

View File

@ -46,6 +46,7 @@ $sub-schema-offset: ($bullet-size/2) + $bullet-margin;
border-radius: $border-radius; border-radius: $border-radius;
background-color: rgba($primary-color, .1); background-color: rgba($primary-color, .1);
margin-left: 6px; margin-left: 6px;
margin-right: 6px;
} }
.param-description { .param-description {

View File

@ -23,11 +23,15 @@ describe('Redoc components', () => {
fixture = builder.createSync(TestAppComponent); fixture = builder.createSync(TestAppComponent);
let debugEl = getChildDebugElement(fixture.debugElement, 'json-schema-lazy'); let debugEl = getChildDebugElement(fixture.debugElement, 'json-schema-lazy');
component = <JsonSchemaLazy>debugEl.componentInstance; component = <JsonSchemaLazy>debugEl.componentInstance;
spyOn(component, '_loadAfterSelf').and.stub(); spyOn(component, '_loadAfterSelf').and.callThrough();
spyOn(component.resolver, 'resolveComponent').and.returnValue({ then: () => {
return { catch: () => {/**/} };
}});
}); });
afterEach(() => { afterEach(() => {
component._loadAfterSelf.and.callThrough(); component._loadAfterSelf.and.callThrough();
component.resolver.resolveComponent.and.callThrough();
}); });
it('should init component', () => { it('should init component', () => {

View File

@ -34,7 +34,7 @@ export class JsonSchemaLazy implements OnDestroy, AfterViewInit {
} }
_loadAfterSelf() { _loadAfterSelf() {
// FIXME: get rid of DynamicComponentLoader as it is deprecated this.loaded = true;
return this.resolver.resolveComponent(JsonSchema).then(componentFactory => { return this.resolver.resolveComponent(JsonSchema).then(componentFactory => {
let contextInjector = this.location.parentInjector; let contextInjector = this.location.parentInjector;
let compRef = this.location.createComponent( let compRef = this.location.createComponent(
@ -55,7 +55,6 @@ export class JsonSchemaLazy implements OnDestroy, AfterViewInit {
if (this.pointer) { if (this.pointer) {
this._loadAfterSelf(); this._loadAfterSelf();
} }
this.loaded = true;
} }
// cache JsonSchema view // cache JsonSchema view
@ -73,7 +72,8 @@ export class JsonSchemaLazy implements OnDestroy, AfterViewInit {
return; return;
} }
insertAfter($element.cloneNode(true), this.elementRef.nativeElement); insertAfter($element.cloneNode(true), this.elementRef.nativeElement);
} ); this.loaded = true;
});
}); });
} else { } else {
cache[this.pointer] = this._loadAfterSelf(); cache[this.pointer] = this._loadAfterSelf();

View File

@ -31,8 +31,8 @@
'expanded': subSchema.visible 'expanded': subSchema.visible
}"> }">
<td class="param-name"> <td class="param-name">
<span class="param-name-wrap"> <span class="param-name-wrap" (click)="subSchema.toggle()">
<span (click)="subSchema.toggle()" class="param-name-content" >{{prop._name}}</span> <span class="param-name-content" >{{prop._name}}</span>
<svg *ngIf="prop._pointer" xmlns="http://www.w3.org/2000/svg" version="1.1" x="0" y="0" viewBox="0 0 24 24" xml:space="preserve"> <svg *ngIf="prop._pointer" xmlns="http://www.w3.org/2000/svg" version="1.1" x="0" y="0" viewBox="0 0 24 24" xml:space="preserve">
<polygon points="17.3 8.3 12 13.6 6.7 8.3 5.3 9.7 12 16.4 18.7 9.7 "/> <polygon points="17.3 8.3 12 13.6 6.7 8.3 5.3 9.7 12 16.4 18.7 9.7 "/>
</svg> </svg>
@ -62,8 +62,8 @@
</tr> </tr>
<tr class="param-schema" [ngClass]="{'param-array': prop._isArray, 'last': last}" [hidden]="!prop._pointer"> <tr class="param-schema" [ngClass]="{'param-array': prop._isArray, 'last': last}" [hidden]="!prop._pointer">
<td colspan="2"> <td colspan="2">
<zippy #subSchema title="test" [headless]="true" (open)="lazySchema.load()"> <zippy #subSchema title="Expand" [headless]="true" (open)="lazySchema.load()" [visible]="autoExpand">
<json-schema-lazy #lazySchema class="nested-schema" [pointer]="prop._pointer" [isArray]='prop._isArray' <json-schema-lazy #lazySchema [auto]="autoExpand" class="nested-schema" [pointer]="prop._pointer" [isArray]='prop._isArray'
[nestOdd]="!nestOdd" [isRequestSchema]="isRequestSchema"> [nestOdd]="!nestOdd" [isRequestSchema]="isRequestSchema">
</json-schema-lazy> </json-schema-lazy>
</zippy> </zippy>

View File

@ -69,6 +69,10 @@ $array-marker-line-height: 1.5;
} }
} }
zippy {
overflow: visible;
}
.zippy-content-wrap { .zippy-content-wrap {
padding: 0; padding: 0;
} }
@ -77,9 +81,10 @@ $array-marker-line-height: 1.5;
border-bottom: 0; border-bottom: 0;
} }
.param.complex > .param-name .param-name-content { .param.complex > .param-name .param-name-wrap {
font-weight: bold; font-weight: bold;
cursor: pointer; cursor: pointer;
color: $black;
} }
.param.complex > .param-name svg { .param.complex > .param-name svg {
@ -97,10 +102,13 @@ $array-marker-line-height: 1.5;
} }
.params-wrap { .params-wrap {
border-collapse: collapse;
width: 100%; width: 100%;
} }
table {
border-spacing: 0;
}
.params-wrap.params-array:before, .params-wrap.params-array:after { .params-wrap.params-array:before, .params-wrap.params-array:after {
display: block; display: block;
font-weight: $base-font-weight; font-weight: $base-font-weight;

View File

@ -28,6 +28,7 @@ export class JsonSchema extends BaseComponent {
@Input() childFor: string; @Input() childFor: string;
@Input() isRequestSchema: boolean; @Input() isRequestSchema: boolean;
normalizer: SchemaNormalizer; normalizer: SchemaNormalizer;
autoExpand = false;
constructor(specMgr:SpecManager, private _renderer: Renderer, private _elementRef: ElementRef) { constructor(specMgr:SpecManager, private _renderer: Renderer, private _elementRef: ElementRef) {
super(specMgr); super(specMgr);
@ -100,6 +101,8 @@ export class JsonSchema extends BaseComponent {
} }
return (propSchema && propSchema.type === 'object' && propSchema._pointer); return (propSchema && propSchema.type === 'object' && propSchema._pointer);
}); });
this.autoExpand = this.properties && this.properties.length === 1;
} }
trackByIdx(index: number, item: any): number { trackByIdx(index: number, item: any): number {

View File

@ -7,6 +7,10 @@
border-bottom: 1px solid rgba(127, 127, 127, 0.25); border-bottom: 1px solid rgba(127, 127, 127, 0.25);
} }
:host:last-of-type {
border-bottom: 0;
}
responses-list, params-list { responses-list, params-list {
display: block; display: block;
} }

View File

@ -142,14 +142,17 @@ api-logo {
} }
footer { footer {
position: relative;
text-align: right; text-align: right;
padding: 10px; padding: 10px 40px;
font-size: 15px; font-size: 15px;
background-color: white; margin-top: -35px;
color: white;
a {
color: white;
}
strong { strong {
font-size: 18px; font-size: 18px;
color: $headers-color;
} }
} }

View File

@ -12,7 +12,7 @@
<div class="header-description" [innerHtml]="header.description | marked"> </div> <div class="header-description" [innerHtml]="header.description | marked"> </div>
</div> </div>
</div> </div>
<header *ngIf="response.headers"> <header *ngIf="response.schema">
Response Schema Response Schema
</header> </header>
<json-schema-lazy #lazySchema pointer="{{response.schema ? response.pointer + '/schema' : null}}"> <json-schema-lazy #lazySchema pointer="{{response.schema ? response.pointer + '/schema' : null}}">

View File

@ -43,7 +43,21 @@ export class SchemaSample extends BaseComponent {
if (base.examples && base.examples['application/json']) { if (base.examples && base.examples['application/json']) {
sample = base.examples['application/json']; sample = base.examples['application/json'];
} else { } else {
let selectedDescendant;
this.componentSchema = this._normalizer.normalize(this.componentSchema, this.pointer); this.componentSchema = this._normalizer.normalize(this.componentSchema, this.pointer);
let discriminator = this.componentSchema.discriminator;
if (discriminator) {
let descendants = this.specMgr.findDerivedDefinitions(this.componentSchema._pointer || this.pointer);
if (descendants.length) {
// TODO: sync up with dropdown
selectedDescendant = descendants[0];
let descSchema = this.specMgr.byPointer(selectedDescendant.$ref);
this.componentSchema = this._normalizer.normalize(Object.assign({}, descSchema), selectedDescendant.$ref,
{omitParent: false});
}
}
if (this.fromCache()) { if (this.fromCache()) {
return; return;
} }
@ -54,6 +68,9 @@ export class SchemaSample extends BaseComponent {
} catch(e) { } catch(e) {
// no sample available // no sample available
} }
if (selectedDescendant) {
sample[discriminator] = selectedDescendant.name;
}
} }
this.cache(sample); this.cache(sample);
this.data.sample = sample; this.data.sample = sample;

View File

@ -21,7 +21,7 @@ import { ScrollService, Hash, MenuService, OptionsService } from '../../services
state('expanded', state('expanded',
style({ height: '*' })), style({ height: '*' })),
transition('collapsed <=> expanded', [ transition('collapsed <=> expanded', [
animate(200) animate('200ms ease')
]) ])
]) ])
], ],

View File

@ -221,7 +221,8 @@ export class SchemaHelper {
} }
static methodSummary(method) { static methodSummary(method) {
return method.summary || method.operationId || method.description.substring(0, 50); return method.summary || method.operationId ||
(method.description && method.description.substring(0, 50)) || '<no description>';
} }
static buildMenuTree(schema) { static buildMenuTree(schema) {

View File

@ -22,13 +22,14 @@ export class SchemaNormalizer {
constructor(private _schema:any) { constructor(private _schema:any) {
this._dereferencer = new SchemaDereferencer(_schema, this); this._dereferencer = new SchemaDereferencer(_schema, this);
} }
normalize(schema, ptr) { normalize(schema, ptr, opts:any ={}) {
opts.omitParent = opts.omitParent !== false;
if (schema['x-redoc-normalized']) return schema; if (schema['x-redoc-normalized']) return schema;
let res = SchemaWalker.walk(schema, ptr, (subSchema, ptr) => { let res = SchemaWalker.walk(schema, ptr, (subSchema, ptr) => {
let resolved = this._dereferencer.dereference(subSchema, ptr); let resolved = this._dereferencer.dereference(subSchema, ptr);
if (resolved.allOf) { if (resolved.allOf) {
resolved._pointer = resolved._pointer || ptr; resolved._pointer = resolved._pointer || ptr;
AllOfMerger.merge(resolved, resolved.allOf, {omitParent: true}); AllOfMerger.merge(resolved, resolved.allOf, {omitParent: opts.omitParent});
} }
return resolved; return resolved;
}); });

View File

@ -17,7 +17,7 @@
.dk-selected { .dk-selected {
color: $secondary-color; color: $secondary-color;
border-color: rgba($secondary-color, .5); border-color: rgba($secondary-color, .5);
padding: 0.15em 0.6em 0.2em 0.5em; padding: 0.15em 1.5em 0.2em 0.5em;
border-radius: $border-radius; border-radius: $border-radius;
} }
@ -52,7 +52,9 @@
margin-top: 0.2em; margin-top: 0.2em;
padding: 0; padding: 0;
border-radius: $border-radius; border-radius: $border-radius;
box-shadow: 0px 2px 4px 0px rgba(34, 36, 38, 0.12), 0px 2px 10px 0px rgba(34, 36, 38, 0.08) !important box-shadow: 0px 2px 4px 0px rgba(34, 36, 38, 0.12), 0px 2px 10px 0px rgba(34, 36, 38, 0.08) !important;
right: auto;
min-width: 100%;
} }
.dk-option { .dk-option {

View File

@ -10,6 +10,14 @@ $zippy-info-bg-color: rgba($zippy-info-color, .08);
$zippy-redirect-color: #263238; $zippy-redirect-color: #263238;
$zippy-redirect-bg-color: rgba($zippy-redirect-color, .08); $zippy-redirect-bg-color: rgba($zippy-redirect-color, .08);
:host {
// performance optimization
transform: translate3d(0, 0, 0);
backface-visibility: hidden;
overflow: hidden;
display: block;
}
.zippy-title { .zippy-title {
padding: 10px; padding: 10px;
border-radius: 2px; border-radius: 2px;
@ -98,8 +106,5 @@ span.zippy-indicator {
} }
.zippy-hidden > .zippy-content { .zippy-hidden > .zippy-content {
overflow: hidden; display: none;
visibility: hidden;
height: 0;
padding: 0;
} }

View File

@ -124,7 +124,7 @@ export class SpecManager {
if (!globalDefs[defName].allOf && if (!globalDefs[defName].allOf &&
!globalDefs[defName]['x-derived-from']) continue; !globalDefs[defName]['x-derived-from']) continue;
let subTypes = globalDefs[defName]['x-derived-from'] || let subTypes = globalDefs[defName]['x-derived-from'] ||
globalDefs[defName].allOf.map(subType => subType.$ref); globalDefs[defName].allOf.map(subType => subType._pointer || subType.$ref);
let idx = subTypes.findIndex(ref => ref === defPointer); let idx = subTypes.findIndex(ref => ref === defPointer);
if (idx < 0) continue; if (idx < 0) continue;

View File

@ -1,7 +1,7 @@
{ {
"name": "redoc", "name": "redoc",
"description": "Swagger-generated API Reference Documentation", "description": "Swagger-generated API Reference Documentation",
"version": "0.15.2", "version": "0.15.3",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/Rebilly/ReDoc" "url": "git://github.com/Rebilly/ReDoc"
@ -43,7 +43,7 @@
"json": "github:systemjs/plugin-json@^0.1.0", "json": "github:systemjs/plugin-json@^0.1.0",
"json-pointer": "npm:json-pointer@^0.3.0", "json-pointer": "npm:json-pointer@^0.3.0",
"json-schema-ref-parser": "npm:json-schema-ref-parser@^3.1.2", "json-schema-ref-parser": "npm:json-schema-ref-parser@^3.1.2",
"openapi-sampler": "npm:openapi-sampler@0.2.0", "openapi-sampler": "npm:openapi-sampler@^0.3.0",
"prismjs": "npm:prismjs@^1.3.0", "prismjs": "npm:prismjs@^1.3.0",
"remarkable": "npm:remarkable@^1.6.2", "remarkable": "npm:remarkable@^1.6.2",
"rxjs": "npm:rxjs@5.0.0-beta.6", "rxjs": "npm:rxjs@5.0.0-beta.6",
@ -60,10 +60,6 @@
"systemjs/plugin-json": "github:systemjs/plugin-json@^0.1.0" "systemjs/plugin-json": "github:systemjs/plugin-json@^0.1.0"
}, },
"overrides": { "overrides": {
"npm:openapi-sampler@0.2.0": {
"main": "src/openapi-sampler",
"format": "esm"
},
"npm:dropkickjs@2.1.8": { "npm:dropkickjs@2.1.8": {
"format": "global" "format": "global"
}, },
@ -72,6 +68,10 @@
"http": "stream-http", "http": "stream-http",
"https": "stream-http" "https": "stream-http"
} }
},
"npm:openapi-sampler@0.3.0": {
"main": "src/openapi-sampler",
"format": "esm"
} }
} }
}, },

View File

@ -1,58 +0,0 @@
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
class RollupNG2 {
constructor(options) {
this.options = options;
}
resolveId(id, from) {
if (id.startsWith('rxjs/')) {
return `${__dirname}/node_modules/rxjs-es/${id.replace('rxjs/', '')}.js`;
}
if(id.startsWith('@angular/core')){
if(id === '@angular/core'){
return `${__dirname}/node_modules/@angular/core/esm/index.js`;
}
return `${__dirname}/node_modules/@angular/core/esm/${id.split('@angular/core').pop()}.js`;
}
if(id.startsWith('@angular/common')){
if(id === '@angular/common'){
return `${__dirname}/node_modules/@angular/common/esm/index.js`;
}
return `${__dirname}/node_modules/@angular/common/esm/${id.split('@angular/common').pop()}.js`;
}
if(id.startsWith('@angular/platform-browser-dynamic')){
if(id === '@angular/platform-browser-dynamic'){
return `${__dirname}/node_modules/@angular/platform-browser-dynamic/esm/index.js`;
}
return `${__dirname}/node_modules/@angular/platform-browser-dynamic/esm/${id.split('@angular/platform-browser-dynamic').pop()}.js`;
}
if(id.startsWith('@angular/platform-browser')){
if(id === '@angular/platform-browser'){
return `${__dirname}/node_modules/@angular/platform-browser/esm/index.js`;
}
return `${__dirname}/node_modules/@angular/platform-browser/esm/${id.split('@angular/platform-browser').pop()}.js`;
}
}
}
const rollupNG2 = (config) => new RollupNG2(config);
export default {
entry: './.tmp-es/index.js',
dest: 'dist/vendor.es2015.js',
format: 'iife',
moduleName: 'ReDoc',
plugins: [
//typescript(),
rollupNG2(),
nodeResolve({ jsnext: true, main: true, browser: true }),
commonjs({
// non-CommonJS modules will be ignored, but you can also
// specifically include/exclude files
include: 'node_modules/**', // Default: undefined
exclude: [ 'node_modules/@angular/**', 'node_modules/rxjs/**', 'node_modules/rxjs-es/**' ], // Default: undefined
namedExports: { 'marked': ['marked'] } // Default: undefined
})
]
}

View File

@ -19,8 +19,8 @@ System.config({
"@angular/common": "npm:@angular/common@2.0.0-rc.4", "@angular/common": "npm:@angular/common@2.0.0-rc.4",
"@angular/compiler": "npm:@angular/compiler@2.0.0-rc.4", "@angular/compiler": "npm:@angular/compiler@2.0.0-rc.4",
"@angular/core": "npm:@angular/core@2.0.0-rc.4", "@angular/core": "npm:@angular/core@2.0.0-rc.4",
"@angular/platform-browser-dynamic": "npm:@angular/platform-browser-dynamic@2.0.0-rc.4",
"@angular/platform-browser": "npm:@angular/platform-browser@2.0.0-rc.4", "@angular/platform-browser": "npm:@angular/platform-browser@2.0.0-rc.4",
"@angular/platform-browser-dynamic": "npm:@angular/platform-browser-dynamic@2.0.0-rc.4",
"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",
"clean-css": "npm:clean-css@3.4.17", "clean-css": "npm:clean-css@3.4.17",
@ -33,7 +33,7 @@ System.config({
"json-formatter-js": "npm:json-formatter-js@0.2.0", "json-formatter-js": "npm:json-formatter-js@0.2.0",
"json-pointer": "npm:json-pointer@0.3.0", "json-pointer": "npm:json-pointer@0.3.0",
"json-schema-ref-parser": "npm:json-schema-ref-parser@3.1.2", "json-schema-ref-parser": "npm:json-schema-ref-parser@3.1.2",
"openapi-sampler": "npm:openapi-sampler@0.2.0", "openapi-sampler": "npm:openapi-sampler@0.3.0",
"prismjs": "npm:prismjs@1.3.0", "prismjs": "npm:prismjs@1.3.0",
"remarkable": "npm:remarkable@1.6.2", "remarkable": "npm:remarkable@1.6.2",
"rxjs": "npm:rxjs@5.0.0-beta.6", "rxjs": "npm:rxjs@5.0.0-beta.6",
@ -654,9 +654,6 @@ System.config({
"process": "github:jspm/nodelibs-process@0.1.2", "process": "github:jspm/nodelibs-process@0.1.2",
"util": "github:jspm/nodelibs-util@0.1.0" "util": "github:jspm/nodelibs-util@0.1.0"
}, },
"npm:openapi-sampler@0.2.0": {
"process": "github:jspm/nodelibs-process@0.1.2"
},
"npm:os-browserify@0.1.2": { "npm:os-browserify@0.1.2": {
"os": "github:jspm/nodelibs-os@0.1.0" "os": "github:jspm/nodelibs-os@0.1.0"
}, },