diff --git a/karma.conf.js b/karma.conf.js index 9966e216..e7c94a7a 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -39,7 +39,6 @@ module.exports = function (config) { //load angular dependencies and browser polyfills files: [ 'node_modules/zone.js/dist/zone.js', - 'node_modules/zone.js/dist/fake-async-test.js', 'node_modules/zone.js/dist/async-test.js', 'node_modules/zone.js/dist/jasmine-patch.js', 'node_modules/zone.js/dist/long-stack-trace-zone.js', diff --git a/lib/components/ApiInfo/api-info.spec.ts b/lib/components/ApiInfo/api-info.spec.ts index 5d0f26b4..acaebf1c 100644 --- a/lib/components/ApiInfo/api-info.spec.ts +++ b/lib/components/ApiInfo/api-info.spec.ts @@ -1,47 +1,32 @@ 'use strict'; import { getChildDebugElement } from '../../../tests/helpers'; -import { Component, provide } from '@angular/core'; +import { Component } from '@angular/core'; import { inject, async, - expect, - beforeEach, - beforeEachProviders, - it + TestComponentBuilder } from '@angular/core/testing'; -import { TestComponentBuilder } from '@angular/compiler/testing'; - import { ApiInfo } from './api-info'; import { SpecManager } from '../../utils/SpecManager'; -import { OptionsService } from '../../services/index'; describe('Redoc components', () => { describe('ApiInfo Component', () => { let builder; let component; let fixture; - beforeEachProviders(() => [ - provide(SpecManager, {useValue: new SpecManager()}), - provide(OptionsService, {useClass: OptionsService}) - ]); beforeEach(async(inject([TestComponentBuilder, SpecManager], (tcb, specMgr) => { builder = tcb; return specMgr.load('/tests/schemas/api-info-test.json'); }))); - beforeEach((done) => { - builder.createAsync(TestAppComponent).then(_fixture => { - fixture = _fixture; - component = getChildDebugElement(fixture.debugElement, 'api-info').componentInstance; - fixture.detectChanges(); - done(); - }, err => { - done.fail(err); - }); + beforeEach(() => { + fixture = builder.createSync(TestAppComponent); + component = getChildDebugElement(fixture.debugElement, 'api-info').componentInstance; + fixture.detectChanges(); }); @@ -54,7 +39,7 @@ describe('Redoc components', () => { it('should render api name and version', () => { let nativeElement = getChildDebugElement(fixture.debugElement, 'api-info').nativeElement; let headerElement = nativeElement.querySelector('h1'); - expect(headerElement).toHaveText('Swagger Petstore (1.0.0)'); + expect(headerElement.innerText).toContain('Swagger Petstore (v1.0.0)'); }); }); }); diff --git a/lib/components/ApiInfo/api-info.ts b/lib/components/ApiInfo/api-info.ts index 2a8c20bf..db5db8a0 100644 --- a/lib/components/ApiInfo/api-info.ts +++ b/lib/components/ApiInfo/api-info.ts @@ -18,5 +18,8 @@ export class ApiInfo extends BaseComponent { prepareModel() { this.data = this.componentSchema.info; this.specUrl = this.optionsService.options.specUrl; + if (parseInt(this.data.version.substring(0, 1)) !== NaN) { + this.data.version = 'v' + this.data.version; + } } } diff --git a/lib/components/ApiLogo/api-logo.spec.ts b/lib/components/ApiLogo/api-logo.spec.ts index e9a6fbf3..79484ff0 100644 --- a/lib/components/ApiLogo/api-logo.spec.ts +++ b/lib/components/ApiLogo/api-logo.spec.ts @@ -1,18 +1,14 @@ 'use strict'; import { getChildDebugElement } from '../../../tests/helpers'; -import {Component, provide} from '@angular/core'; +import { Component } from '@angular/core'; import { inject, async, - beforeEach, - beforeEachProviders, - it + TestComponentBuilder } from '@angular/core/testing'; -import { TestComponentBuilder } from '@angular/compiler/testing'; - import { ApiLogo } from './api-logo'; import { SpecManager } from '../../utils/SpecManager'; @@ -25,21 +21,15 @@ describe('Redoc components', () => { let specMgr; let schemaUrl = '/tests/schemas/api-info-test.json'; - beforeEachProviders(() => [ - provide(SpecManager, {useValue: new SpecManager()}) - ]); beforeEach(async(inject([TestComponentBuilder, SpecManager], (tcb, _specMgr) => { builder = tcb; specMgr = _specMgr; return specMgr.load(schemaUrl); }))); - beforeEach((done) => { - builder.createAsync(TestAppComponent).then(_fixture => { - fixture = _fixture; - component = getChildDebugElement(fixture.debugElement, 'api-logo').componentInstance; - fixture.detectChanges(); - done(); - }, err => done.fail(err)); + beforeEach(() => { + fixture = builder.createSync(TestAppComponent); + component = getChildDebugElement(fixture.debugElement, 'api-logo').componentInstance; + fixture.detectChanges(); }); diff --git a/lib/components/JsonSchema/json-schema-common.scss b/lib/components/JsonSchema/json-schema-common.scss index e2458f58..cef10416 100644 --- a/lib/components/JsonSchema/json-schema-common.scss +++ b/lib/components/JsonSchema/json-schema-common.scss @@ -87,6 +87,11 @@ $sub-schema-offset: ($bullet-size/2) + $bullet-margin; display: inline-block; } +.param-type-file { + font-weight: bold; + text-transform: capitalize; +} + /* tree */ // Bullet diff --git a/lib/components/JsonSchema/json-schema-lazy.spec.ts b/lib/components/JsonSchema/json-schema-lazy.spec.ts index d1026189..d5977d50 100644 --- a/lib/components/JsonSchema/json-schema-lazy.spec.ts +++ b/lib/components/JsonSchema/json-schema-lazy.spec.ts @@ -1,41 +1,33 @@ 'use strict'; import { getChildDebugElement } from '../../../tests/helpers'; -import { Component, provide } from '@angular/core'; +import { Component } from '@angular/core'; import { inject, - beforeEach, - beforeEachProviders, - it + TestComponentBuilder } from '@angular/core/testing'; -import { TestComponentBuilder } from '@angular/compiler/testing'; - - import { JsonSchemaLazy } from './json-schema-lazy'; -import { SpecManager } from '../../utils/SpecManager'; describe('Redoc components', () => { describe('JsonSchemaLazy Component', () => { let builder; let component; - let specMgr = new SpecManager(); let fixture; - beforeEachProviders(() => [ - provide(SpecManager, {useValue: specMgr}) - ]); - beforeEach(inject([TestComponentBuilder], (tcb, dcl) => { + + beforeEach(inject([TestComponentBuilder], (tcb) => { builder = tcb; })); - beforeEach((done) => { - builder.createAsync(TestAppComponent).then(_fixture => { - fixture = _fixture; - let debugEl = getChildDebugElement(fixture.debugElement, 'json-schema-lazy'); - component = debugEl.componentInstance; - spyOn(component, '_loadAfterSelf').and.callThrough(); - done(); - }, err => done.fail(err)); + beforeEach(() => { + fixture = builder.createSync(TestAppComponent); + let debugEl = getChildDebugElement(fixture.debugElement, 'json-schema-lazy'); + component = debugEl.componentInstance; + spyOn(component, '_loadAfterSelf').and.stub(); + }); + + afterEach(() => { + component._loadAfterSelf.and.callThrough(); }); it('should init component', () => { diff --git a/lib/components/JsonSchema/json-schema.html b/lib/components/JsonSchema/json-schema.html index 1d075bca..53ffa1f9 100644 --- a/lib/components/JsonSchema/json-schema.html +++ b/lib/components/JsonSchema/json-schema.html @@ -1,10 +1,14 @@ - file + file
- Produces: {{ schema._produces | json }} +
    +
  • {{type}}
  • +
- Consumes: {{ schema._consumes | json }} +
    +
  • {{type}}
  • +
diff --git a/lib/components/JsonSchema/json-schema.scss b/lib/components/JsonSchema/json-schema.scss index 0828feeb..d0eaae55 100644 --- a/lib/components/JsonSchema/json-schema.scss +++ b/lib/components/JsonSchema/json-schema.scss @@ -180,31 +180,16 @@ $array-marker-line-height: 1.5; } } -ul { - text-align: left; +ul, li { margin: 0; - padding: 0; - display: block; } -li { - margin: 0.5em 0.3em 0.2em 0; - font-family: $headers-font, $headers-font-family; - font-size: .929em; - line-height: .929em; - border: 0; - color: white; - padding: 2px 8px 4px 8px; - border-radius: $border-radius; - background-color: rgba($black, 0.3); - display: inline-block; - cursor: pointer; - - &:last-of-type { - margin-right: 0; - } - - &.active { - background-color: $primary-color; - } +ul { + list-style: none; + padding-left: 1em; +} + +li:before { + content: "- "; + font-weight: bold; } diff --git a/lib/components/JsonSchema/json-schema.spec.ts b/lib/components/JsonSchema/json-schema.spec.ts index 166658b9..962116f2 100644 --- a/lib/components/JsonSchema/json-schema.spec.ts +++ b/lib/components/JsonSchema/json-schema.spec.ts @@ -1,13 +1,10 @@ 'use strict'; -import { Component, provide } from '@angular/core'; +import { Component } from '@angular/core'; import { inject, - beforeEach, - beforeEachProviders, - it + TestComponentBuilder } from '@angular/core/testing'; -import { TestComponentBuilder } from '@angular/compiler/testing'; import { getChildDebugElement } from '../../../tests/helpers'; @@ -19,21 +16,17 @@ describe('Redoc components', () => { describe('JsonSchema Component', () => { let builder; let component; - let specMgr = new SpecManager(); let fixture; - beforeEachProviders(() => [ - provide(SpecManager, {useValue: specMgr}) - ]); - beforeEach(inject([TestComponentBuilder], (tcb) => { + let specMgr; + + beforeEach(inject([TestComponentBuilder, SpecManager], (tcb, _spec) => { builder = tcb; + specMgr = _spec; })); - beforeEach((done) => { - builder.createAsync(TestAppComponent).then(_fixture => { - fixture = _fixture; - let debugEl = getChildDebugElement(fixture.debugElement, 'json-schema'); - component = debugEl.componentInstance; - done(); - }, err => done.fail(err)); + beforeEach(() => { + fixture = builder.createSync(TestAppComponent); + let debugEl = getChildDebugElement(fixture.debugElement, 'json-schema'); + component = debugEl.componentInstance; }); it('should init component', () => { diff --git a/lib/components/Method/method.html b/lib/components/Method/method.html index adbf9284..333ceaa3 100644 --- a/lib/components/Method/method.html +++ b/lib/components/Method/method.html @@ -1,7 +1,7 @@

- {{data.methodInfo.summary}} + {{data.summary}}

{{tag}} diff --git a/lib/components/Method/method.scss b/lib/components/Method/method.scss index 1ddca717..75163437 100644 --- a/lib/components/Method/method.scss +++ b/lib/components/Method/method.scss @@ -38,7 +38,7 @@ responses-list, params-list { } .api-url { - color: rgba(#ffffff, .8); + color: rgba(#ffffff, .6); margin-left: 10px; margin-top: 2px; position: relative; diff --git a/lib/components/Method/method.spec.ts b/lib/components/Method/method.spec.ts index 699ed0da..21cdc51a 100644 --- a/lib/components/Method/method.spec.ts +++ b/lib/components/Method/method.spec.ts @@ -1,14 +1,11 @@ 'use strict'; -import { Component, provide } from '@angular/core'; +import { Component } from '@angular/core'; import { inject, async, - beforeEach, - beforeEachProviders, - it + TestComponentBuilder } from '@angular/core/testing'; -import { TestComponentBuilder } from '@angular/compiler/testing'; import { getChildDebugElement } from '../../../tests/helpers'; @@ -19,19 +16,16 @@ describe('Redoc components', () => { describe('Method Component', () => { let builder; let component; - beforeEachProviders(() => [ - provide(SpecManager, {useValue: new SpecManager()}) - ]); + beforeEach(async(inject([TestComponentBuilder, SpecManager], (tcb, specMgr) => { builder = tcb; return specMgr.load('/tests/schemas/extended-petstore.yml'); }))); - beforeEach((done) => { - builder.createAsync(TestAppComponent).then(fixture => { - component = getChildDebugElement(fixture.debugElement, 'method').componentInstance; - fixture.detectChanges(); - done(); - }, err => done.fail(err)); + + beforeEach(() => { + let fixture = builder.createSync(TestAppComponent); + component = getChildDebugElement(fixture.debugElement, 'method').componentInstance; + fixture.detectChanges(); }); diff --git a/lib/components/Method/method.ts b/lib/components/Method/method.ts index 23d54b14..781b2afe 100644 --- a/lib/components/Method/method.ts +++ b/lib/components/Method/method.ts @@ -8,6 +8,7 @@ import { ResponsesList } from '../ResponsesList/responses-list'; import { ResponsesSamples } from '../ResponsesSamples/responses-samples'; import { SchemaSample } from '../SchemaSample/schema-sample'; import { RequestSamples } from '../RequestSamples/request-samples'; +import { SchemaHelper } from '../../services/schema-helper.service'; @RedocComponent({ selector: 'method', @@ -31,6 +32,7 @@ export class Method extends BaseComponent { this.data.methodInfo = this.componentSchema; this.data.methodInfo.tags = this.filterMainTags(this.data.methodInfo.tags); this.data.bodyParam = this.findBodyParam(); + this.data.summary = SchemaHelper.methodSummary(this.componentSchema); if (this.componentSchema.operationId) { this.data.methodAnchor = 'operation/' + encodeURIComponent(this.componentSchema.operationId); } else { diff --git a/lib/components/MethodsList/methods-list.html b/lib/components/MethodsList/methods-list.html index 6d867af0..6f42f8b6 100644 --- a/lib/components/MethodsList/methods-list.html +++ b/lib/components/MethodsList/methods-list.html @@ -1,6 +1,6 @@
-
-
+
+

{{tag.name}}

diff --git a/lib/components/MethodsList/methods-list.spec.ts b/lib/components/MethodsList/methods-list.spec.ts index 9918761a..b8e6be02 100644 --- a/lib/components/MethodsList/methods-list.spec.ts +++ b/lib/components/MethodsList/methods-list.spec.ts @@ -1,14 +1,11 @@ 'use strict'; -import { Component, provide } from '@angular/core'; +import { Component } from '@angular/core'; import { inject, async, - beforeEach, - beforeEachProviders, - it + TestComponentBuilder } from '@angular/core/testing'; -import { TestComponentBuilder } from '@angular/compiler/testing'; import { getChildDebugElement } from '../../../tests/helpers'; @@ -21,20 +18,15 @@ describe('Redoc components', () => { let builder; let component; let fixture; - beforeEachProviders(() => [ - provide(SpecManager, {useValue: new SpecManager()}) - ]); + beforeEach(async(inject([TestComponentBuilder, SpecManager], (tcb, specMgr) => { builder = tcb; return specMgr.load('/tests/schemas/methods-list-component.json'); }))); - beforeEach((done) => { - builder.createAsync(TestAppComponent).then(_fixture => { - fixture = _fixture; - component = getChildDebugElement(fixture.debugElement, 'methods-list').componentInstance; - fixture.detectChanges(); - done(); - }, err => done.fail(err) ); + beforeEach(() => { + fixture = builder.createSync(TestAppComponent); + component = getChildDebugElement(fixture.debugElement, 'methods-list').componentInstance; + fixture.detectChanges(); }); diff --git a/lib/components/MethodsList/methods-list.ts b/lib/components/MethodsList/methods-list.ts index a919cdfe..d3dd6527 100644 --- a/lib/components/MethodsList/methods-list.ts +++ b/lib/components/MethodsList/methods-list.ts @@ -4,6 +4,7 @@ import { forwardRef } from '@angular/core'; import { RedocComponent, BaseComponent, SpecManager } from '../base'; import { Method } from '../Method/method'; import { EncodeURIComponentPipe } from '../../utils/pipes'; +import { SchemaHelper } from '../../services/index'; @RedocComponent({ selector: 'methods-list', @@ -24,21 +25,14 @@ export class MethodsList extends BaseComponent { // follow SwaggerUI behavior for cases when one method has more than one tag: // duplicate methods - let menuStructure = this.specMgr.buildMenuTree(); - let tags = Array.from(menuStructure.entries()) - .map((entry) => { - let [tag, {description, methods}] = entry; - // inject tag name into method info - methods = methods || []; - methods.forEach(method => { - method.tag = tag; - }); - return { - name: tag, - description: description, - methods: methods - }; + let tags = SchemaHelper.buildMenuTree(this.specMgr.schema); + tags.forEach(tagInfo => { + // inject tag name into method info + tagInfo.methods = tagInfo.methods || []; + tagInfo.methods.forEach(method => { + method.tag = tagInfo.name; }); + }); this.data.tags = tags; // TODO: check $ref field } @@ -46,4 +40,8 @@ export class MethodsList extends BaseComponent { trackByPointer(idx, el) { return el.pointer; } + + trackByTagName(idx, el) { + return el.name; + } } diff --git a/lib/components/Redoc/redoc.spec.ts b/lib/components/Redoc/redoc.spec.ts index 4ae11b74..0d278a70 100644 --- a/lib/components/Redoc/redoc.spec.ts +++ b/lib/components/Redoc/redoc.spec.ts @@ -1,15 +1,12 @@ 'use strict'; import { getChildDebugElement } from '../../../tests/helpers'; -import { Component, provide, ComponentRef } from '@angular/core'; +import { Component, ComponentRef } from '@angular/core'; import { BrowserDomAdapter } from '@angular/platform-browser/src/browser/browser_adapter'; import { inject, - async, - beforeEach, - beforeEachProviders, - it + async } from '@angular/core/testing'; import { TestComponentBuilder } from '@angular/compiler/testing'; @@ -24,40 +21,27 @@ describe('Redoc components', () => { describe('Redoc Component', () => { let builder; let specMgr; - beforeEachProviders(() => [ - provide(SpecManager, {useValue: new SpecManager()}), - ]); + beforeEach(async(inject([TestComponentBuilder, SpecManager, OptionsService], (tcb, _specMgr, _optsMgr) => { optsMgr = _optsMgr; builder = tcb; specMgr = _specMgr; + return specMgr.load('/tests/schemas/extended-petstore.yml'); }))); - beforeEach((done) => { - return specMgr.load('/tests/schemas/extended-petstore.yml') - .then(() => done()) - .catch(err => done.fail(err)); + + it('should init component', () => { + let fixture = builder.createSync(TestAppComponent); + let component = getChildDebugElement(fixture.debugElement, 'redoc').componentInstance; + expect(component).not.toBeNull(); + fixture.destroy(); }); - - it('should init component', (done) => { - builder.createAsync(TestAppComponent).then(fixture => { - let component = getChildDebugElement(fixture.debugElement, 'redoc').componentInstance; - expect(component).not.toBeNull(); - fixture.destroy(); - done(); - }, err => done.fail(err)); - }); - - it('should init components tree without errors', (done) => { - builder.createAsync(TestAppComponent).then(fixture => { - (() => fixture.detectChanges()).should.not.throw(); - fixture.destroy(); - done(); - }, err => { - return done.fail(err); - }); + it('should init components tree without errors', () => { + let fixture = builder.createSync(TestAppComponent); + (() => fixture.detectChanges()).should.not.throw(); + fixture.destroy(); }); }); @@ -74,7 +58,7 @@ describe('Redoc components', () => { }); it('should return promise', () => { - let res = Redoc.init(); + let res = Redoc.init().catch(() => {/**/}); res.should.be.instanceof(Promise); }); @@ -82,7 +66,7 @@ describe('Redoc components', () => { spyOn(Redoc, 'hideLoadingAnimation').and.callThrough(); spyOn(Redoc, 'displayError').and.callThrough(); let res = Redoc.init(); - return res.then(() => { + return res.catch(() => { expect(Redoc.hideLoadingAnimation).toHaveBeenCalled(); expect(Redoc.displayError).toHaveBeenCalled(); }); @@ -103,29 +87,25 @@ describe('Redoc components', () => { let builder; let fixture; let element; + let dom; let destroySpy; - let dom = new BrowserDomAdapter(); - beforeEachProviders(() => [ - provide(SpecManager, {useValue: new SpecManager()}), - provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}), - provide(OptionsService, {useValue: optsMgr}) - ]); - beforeEach(async(inject([TestComponentBuilder, SpecManager], (tcb, specMgr) => { + + beforeEach(async(inject([TestComponentBuilder, SpecManager, OptionsService, BrowserDomAdapter], + (tcb, specMgr, opts, _dom) => { builder = tcb; - return specMgr.load('/tests/schemas/methods-list-component.json'); + optsMgr = opts; + dom = _dom; + return specMgr.load('/tests/schemas/extended-petstore.yml'); }))); - beforeEach((done) => { - builder.createAsync(TestAppComponent).then(_fixture => { - fixture = _fixture; - element = getChildDebugElement(fixture.debugElement, 'methods-list').nativeElement; - destroySpy = jasmine.createSpy('spy'); - Redoc.appRef = >{ - destroy: destroySpy - }; - fixture.detectChanges(); - done(); - }, err => { throw err; }); + beforeEach(() => { + fixture = builder.createSync(TestAppComponent); + element = getChildDebugElement(fixture.debugElement, 'methods-list').nativeElement; + destroySpy = jasmine.createSpy('spy'); + Redoc.appRef = >{ + destroy: destroySpy + }; + fixture.detectChanges(); }); afterEach(()=> { diff --git a/lib/components/Redoc/redoc.ts b/lib/components/Redoc/redoc.ts index e523a4d3..6a6de353 100644 --- a/lib/components/Redoc/redoc.ts +++ b/lib/components/Redoc/redoc.ts @@ -79,10 +79,10 @@ export class Redoc extends BaseComponent implements AfterViewInit { Redoc.hideLoadingAnimation(); Redoc.appRef = appRef; console.log('ReDoc bootstrapped!'); - }, err => { - console.log(err); + }).catch(err => { Redoc.hideLoadingAnimation(); Redoc.displayError(err); + throw err; }); } @@ -97,7 +97,6 @@ export class Redoc extends BaseComponent implements AfterViewInit { } static displayError(err) { - console.log(err); let redocEl = dom.query('redoc'); if (!redocEl) return; let heading = 'Oops... ReDoc failed to render this spec'; diff --git a/lib/components/SideMenu/side-menu.html b/lib/components/SideMenu/side-menu.html index c0929bf8..8b7ee961 100644 --- a/lib/components/SideMenu/side-menu.html +++ b/lib/components/SideMenu/side-menu.html @@ -9,7 +9,8 @@