mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 16:46:34 +03:00
Refactoring
Rename schemaMgr to specMgr fix error logs in tests
This commit is contained in:
parent
85d72d64e3
commit
003fba8651
|
@ -123,7 +123,7 @@ var JS_DEPS = argv.prod ? [
|
|||
]: [
|
||||
'lib/utils/browser-update.js',
|
||||
'node_modules/zone.js/dist/zone.js',
|
||||
//'node_modules/zone.js/dist/long-stack-trace-zone.js',
|
||||
'node_modules/zone.js/dist/long-stack-trace-zone.js',
|
||||
'node_modules/reflect-metadata/Reflect.js',
|
||||
'node_modules/babel-polyfill/dist/polyfill.js'
|
||||
];
|
||||
|
@ -145,7 +145,7 @@ gulp.task('concatDeps', ['concatPrism'], function() {
|
|||
.pipe(gulp.dest('.'))
|
||||
});
|
||||
|
||||
gulp.task('bundle', function bundle(done) {
|
||||
gulp.task('bundle', ['injectVersionFile'], function bundle(done) {
|
||||
mkdir('-p', 'dist');
|
||||
cp('lib/index.js', path.join(paths.tmp, paths.sourceEntryPoint));
|
||||
var builder = new Builder('./', 'system.config.js');
|
||||
|
@ -197,5 +197,6 @@ gulp.task('concatPrism', function() {
|
|||
// needs inlineTemplates run before to create .tmp/lib folder
|
||||
gulp.task('injectVersionFile', function() {
|
||||
var version = require('../../package.json').version;
|
||||
fs.writeFileSync(path.join(paths.tmp, 'lib/version.json'), JSON.stringify(version));
|
||||
var exportStatement = `export var redocVersion = "${version}"`;
|
||||
fs.writeFileSync(path.join(paths.tmp, 'lib/version.js'), exportStatement);
|
||||
})
|
||||
|
|
|
@ -8,6 +8,7 @@ gulp.task('prepare-test', function(cb) {
|
|||
'clean',
|
||||
'transpile',
|
||||
'concatPrism',
|
||||
'injectVersionFile',
|
||||
cb
|
||||
);
|
||||
})
|
||||
|
|
|
@ -53,7 +53,7 @@ module.exports = function (config) {
|
|||
loadFiles: ['.tmp/tests/setup.js', '.tmp/tests/helpers.js', '.tmp/lib/**/*.js',
|
||||
'.tmp/tests/unit/*.js'],
|
||||
serveFiles: ['tests/schemas/**/*.json','tests/schemas/**/*.yml', 'lib/**/*.html',
|
||||
'.tmp/lib/**/*.json', '.tmp/*js', '.tmp/lib/**/*.css']
|
||||
'.tmp/*js', '.tmp/lib/**/*.css']
|
||||
},
|
||||
|
||||
proxies: {
|
||||
|
|
|
@ -28,9 +28,9 @@ describe('Redoc components', () => {
|
|||
provide(OptionsService, {useClass: OptionsService})
|
||||
]);
|
||||
|
||||
beforeEach(async(inject([TestComponentBuilder, SpecManager], (tcb, schemaMgr) => {
|
||||
beforeEach(async(inject([TestComponentBuilder, SpecManager], (tcb, specMgr) => {
|
||||
builder = tcb;
|
||||
return schemaMgr.load('/tests/schemas/api-info-test.json');
|
||||
return specMgr.load('/tests/schemas/api-info-test.json');
|
||||
})));
|
||||
|
||||
beforeEach((done) => {
|
||||
|
|
|
@ -11,8 +11,8 @@ import { OptionsService } from '../../services/index';
|
|||
export class ApiInfo extends BaseComponent {
|
||||
data: any;
|
||||
specUrl: String;
|
||||
constructor(schemaMgr:SpecManager, private optionsService:OptionsService) {
|
||||
super(schemaMgr);
|
||||
constructor(specMgr:SpecManager, private optionsService:OptionsService) {
|
||||
super(specMgr);
|
||||
}
|
||||
|
||||
prepareModel() {
|
||||
|
|
|
@ -22,16 +22,16 @@ describe('Redoc components', () => {
|
|||
let builder;
|
||||
let component;
|
||||
let fixture;
|
||||
let schemaMgr;
|
||||
let specMgr;
|
||||
|
||||
let schemaUrl = '/tests/schemas/api-info-test.json';
|
||||
beforeEachProviders(() => [
|
||||
provide(SpecManager, {useValue: new SpecManager()})
|
||||
]);
|
||||
beforeEach(async(inject([TestComponentBuilder, SpecManager], (tcb, _schemaMgr) => {
|
||||
beforeEach(async(inject([TestComponentBuilder, SpecManager], (tcb, _specMgr) => {
|
||||
builder = tcb;
|
||||
schemaMgr = _schemaMgr;
|
||||
return schemaMgr.load(schemaUrl);
|
||||
specMgr = _specMgr;
|
||||
return specMgr.load(schemaUrl);
|
||||
})));
|
||||
beforeEach((done) => {
|
||||
builder.createAsync(TestAppComponent).then(_fixture => {
|
||||
|
|
|
@ -10,8 +10,8 @@ import {RedocComponent, BaseComponent, SpecManager} from '../base';
|
|||
export class ApiLogo extends BaseComponent {
|
||||
data:any = {};
|
||||
|
||||
constructor(schemaMgr:SpecManager) {
|
||||
super(schemaMgr);
|
||||
constructor(specMgr:SpecManager) {
|
||||
super(specMgr);
|
||||
}
|
||||
|
||||
prepareModel() {
|
||||
|
|
|
@ -21,7 +21,7 @@ describe('Redoc components', () => {
|
|||
describe('JsonSchemaLazy Component', () => {
|
||||
let builder;
|
||||
let component;
|
||||
let schemaMgr = new SpecManager();
|
||||
let specMgr = new SpecManager();
|
||||
let fixture;
|
||||
let loader;
|
||||
let appRefMock = {
|
||||
|
@ -31,7 +31,7 @@ describe('Redoc components', () => {
|
|||
hostView: { changeDetectorRef: {detectChanges : () => undefined} }
|
||||
};
|
||||
beforeEachProviders(() => [
|
||||
provide(SpecManager, {useValue: schemaMgr})
|
||||
provide(SpecManager, {useValue: specMgr})
|
||||
]);
|
||||
beforeEach(inject([TestComponentBuilder, DynamicComponentLoader], (tcb, dcl) => {
|
||||
builder = tcb;
|
||||
|
|
|
@ -8,10 +8,8 @@ import { JsonSchema } from './json-schema';
|
|||
import { OptionsService } from '../../services/options.service';
|
||||
import { SpecManager } from '../../utils/SpecManager';
|
||||
|
||||
|
||||
var cache = {};
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'json-schema-lazy',
|
||||
template: '',
|
||||
|
@ -22,23 +20,26 @@ export class JsonSchemaLazy implements OnDestroy, AfterViewInit {
|
|||
@Input() auto: boolean;
|
||||
@Input() isRequestSchema: boolean;
|
||||
loaded: boolean = false;
|
||||
constructor(private schemaMgr:SpecManager, private viewRef:ViewContainerRef, private elementRef:ElementRef,
|
||||
constructor(private specMgr:SpecManager, private viewRef:ViewContainerRef, private elementRef:ElementRef,
|
||||
private dcl:DynamicComponentLoader, private optionsService:OptionsService) {
|
||||
}
|
||||
|
||||
normalizePointer() {
|
||||
let schema = this.schemaMgr.byPointer(this.pointer);
|
||||
let schema = this.specMgr.byPointer(this.pointer);
|
||||
return schema && schema.$ref || this.pointer;
|
||||
}
|
||||
|
||||
_loadAfterSelf() {
|
||||
// FIXME: get rid of DynamicComponentLoader as it is deprecated
|
||||
return this.dcl.loadNextToLocation(JsonSchema, this.viewRef).then((compRef) => {
|
||||
return this.dcl.loadNextToLocation(JsonSchema, this.viewRef).then(compRef => {
|
||||
this.initComponent(compRef);
|
||||
if (compRef.changeDetectorRef) {
|
||||
compRef.changeDetectorRef.detectChanges();
|
||||
}
|
||||
return compRef;
|
||||
}, err => {
|
||||
console.log(err);
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -19,10 +19,10 @@ describe('Redoc components', () => {
|
|||
describe('JsonSchema Component', () => {
|
||||
let builder;
|
||||
let component;
|
||||
let schemaMgr = new SpecManager();
|
||||
let specMgr = new SpecManager();
|
||||
let fixture;
|
||||
beforeEachProviders(() => [
|
||||
provide(SpecManager, {useValue: schemaMgr})
|
||||
provide(SpecManager, {useValue: specMgr})
|
||||
]);
|
||||
beforeEach(inject([TestComponentBuilder], (tcb) => {
|
||||
builder = tcb;
|
||||
|
@ -38,21 +38,21 @@ describe('Redoc components', () => {
|
|||
|
||||
it('should init component', () => {
|
||||
component.pointer = '';
|
||||
(<any>schemaMgr)._schema = {type: 'object'};
|
||||
(<any>specMgr)._schema = {type: 'object'};
|
||||
fixture.detectChanges();
|
||||
expect(component).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should set isTrivial for non-object/array types', () => {
|
||||
component.pointer = '';
|
||||
(<any>schemaMgr)._schema = {type: 'string'};
|
||||
(<any>specMgr)._schema = {type: 'string'};
|
||||
fixture.detectChanges();
|
||||
component.schema.isTrivial.should.be.true();
|
||||
});
|
||||
|
||||
it('should use < * > notation for prop without type', () => {
|
||||
component.pointer = '';
|
||||
(<any>schemaMgr)._schema = {type: 'object', properties: {
|
||||
(<any>specMgr)._schema = {type: 'object', properties: {
|
||||
test: {}
|
||||
}};
|
||||
fixture.detectChanges();
|
||||
|
|
|
@ -24,9 +24,9 @@ export class JsonSchema extends BaseComponent {
|
|||
@Input() isRequestSchema: boolean;
|
||||
normalizer: SchemaNormalizer;
|
||||
|
||||
constructor(schemaMgr:SpecManager) {
|
||||
super(schemaMgr);
|
||||
this.normalizer = new SchemaNormalizer(schemaMgr);
|
||||
constructor(specMgr:SpecManager) {
|
||||
super(specMgr);
|
||||
this.normalizer = new SchemaNormalizer(specMgr);
|
||||
}
|
||||
|
||||
get normPointer() {
|
||||
|
|
|
@ -22,9 +22,9 @@ describe('Redoc components', () => {
|
|||
beforeEachProviders(() => [
|
||||
provide(SpecManager, {useValue: new SpecManager()})
|
||||
]);
|
||||
beforeEach(async(inject([TestComponentBuilder, SpecManager], (tcb, schemaMgr) => {
|
||||
beforeEach(async(inject([TestComponentBuilder, SpecManager], (tcb, specMgr) => {
|
||||
builder = tcb;
|
||||
return schemaMgr.load('/tests/schemas/extended-petstore.yml');
|
||||
return specMgr.load('/tests/schemas/extended-petstore.yml');
|
||||
})));
|
||||
beforeEach((done) => {
|
||||
builder.createAsync(TestAppComponent).then(fixture => {
|
||||
|
|
|
@ -19,13 +19,13 @@ import { RequestSamples } from '../RequestSamples/request-samples';
|
|||
export class Method extends BaseComponent {
|
||||
data:any;
|
||||
@Input() tag:string;
|
||||
constructor(schemaMgr:SpecManager) {
|
||||
super(schemaMgr);
|
||||
constructor(specMgr:SpecManager) {
|
||||
super(specMgr);
|
||||
}
|
||||
|
||||
prepareModel() {
|
||||
this.data = {};
|
||||
this.data.apiUrl = this.schemaMgr.apiUrl;
|
||||
this.data.apiUrl = this.specMgr.apiUrl;
|
||||
this.data.httpMethod = JsonPointer.baseName(this.pointer);
|
||||
this.data.path = JsonPointer.baseName(this.pointer, 2);
|
||||
this.data.methodInfo = this.componentSchema;
|
||||
|
@ -39,13 +39,13 @@ export class Method extends BaseComponent {
|
|||
}
|
||||
|
||||
filterMainTags(tags) {
|
||||
var tagsMap = this.schemaMgr.getTagsMap();
|
||||
var tagsMap = this.specMgr.getTagsMap();
|
||||
if (!tags) return [];
|
||||
return tags.filter(tag => tagsMap[tag] && tagsMap[tag]['x-traitTag']);
|
||||
}
|
||||
|
||||
findBodyParam() {
|
||||
let pathParams = this.schemaMgr.getMethodParams(this.pointer, true);
|
||||
let pathParams = this.specMgr.getMethodParams(this.pointer, true);
|
||||
let bodyParam = pathParams.find(param => param.in === 'body');
|
||||
return bodyParam;
|
||||
}
|
||||
|
|
|
@ -24,9 +24,9 @@ describe('Redoc components', () => {
|
|||
beforeEachProviders(() => [
|
||||
provide(SpecManager, {useValue: new SpecManager()})
|
||||
]);
|
||||
beforeEach(async(inject([TestComponentBuilder, SpecManager], (tcb, schemaMgr) => {
|
||||
beforeEach(async(inject([TestComponentBuilder, SpecManager], (tcb, specMgr) => {
|
||||
builder = tcb;
|
||||
return schemaMgr.load('/tests/schemas/methods-list-component.json');
|
||||
return specMgr.load('/tests/schemas/methods-list-component.json');
|
||||
})));
|
||||
beforeEach((done) => {
|
||||
builder.createAsync(TestAppComponent).then(_fixture => {
|
||||
|
|
|
@ -15,8 +15,8 @@ import { EncodeURIComponentPipe } from '../../utils/pipes';
|
|||
})
|
||||
export class MethodsList extends BaseComponent {
|
||||
data:any;
|
||||
constructor(schemaMgr:SpecManager) {
|
||||
super(schemaMgr);
|
||||
constructor(specMgr:SpecManager) {
|
||||
super(specMgr);
|
||||
}
|
||||
|
||||
prepareModel() {
|
||||
|
@ -24,7 +24,7 @@ export class MethodsList extends BaseComponent {
|
|||
// follow SwaggerUI behavior for cases when one method has more than one tag:
|
||||
// duplicate methods
|
||||
|
||||
let menuStructure = this.schemaMgr.buildMenuTree();
|
||||
let menuStructure = this.specMgr.buildMenuTree();
|
||||
let tags = Array.from<any>(menuStructure.entries())
|
||||
.map((entry) => {
|
||||
let [tag, {description, methods}] = entry;
|
||||
|
|
|
@ -20,13 +20,13 @@ export class ParamsList extends BaseComponent {
|
|||
|
||||
data:any;
|
||||
|
||||
constructor(schemaMgr:SpecManager) {
|
||||
super(schemaMgr);
|
||||
constructor(specMgr:SpecManager) {
|
||||
super(specMgr);
|
||||
}
|
||||
|
||||
prepareModel() {
|
||||
this.data = {};
|
||||
let paramsList = this.schemaMgr.getMethodParams(this.pointer, true);
|
||||
let paramsList = this.specMgr.getMethodParams(this.pointer, true);
|
||||
|
||||
paramsList = paramsList.map(paramSchema => {
|
||||
let propPointer = paramSchema._pointer;
|
||||
|
|
|
@ -23,19 +23,19 @@ let optsMgr:OptionsService;
|
|||
describe('Redoc components', () => {
|
||||
describe('Redoc Component', () => {
|
||||
let builder;
|
||||
let schemaMgr;
|
||||
let specMgr;
|
||||
beforeEachProviders(() => [
|
||||
provide(SpecManager, {useValue: new SpecManager()}),
|
||||
]);
|
||||
beforeEach(async(inject([TestComponentBuilder, SpecManager, OptionsService],
|
||||
(tcb, _schemaMgr, _optsMgr) => {
|
||||
(tcb, _specMgr, _optsMgr) => {
|
||||
optsMgr = _optsMgr;
|
||||
builder = tcb;
|
||||
schemaMgr = _schemaMgr;
|
||||
specMgr = _specMgr;
|
||||
})));
|
||||
|
||||
beforeEach((done) => {
|
||||
return schemaMgr.load('/tests/schemas/extended-petstore.yml')
|
||||
return specMgr.load('/tests/schemas/extended-petstore.yml')
|
||||
.then(() => done())
|
||||
.catch(err => done.fail(err));
|
||||
});
|
||||
|
@ -110,9 +110,9 @@ describe('Redoc components', () => {
|
|||
provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}),
|
||||
provide(OptionsService, {useValue: optsMgr})
|
||||
]);
|
||||
beforeEach(async(inject([TestComponentBuilder, SpecManager], (tcb, schemaMgr) => {
|
||||
beforeEach(async(inject([TestComponentBuilder, SpecManager], (tcb, specMgr) => {
|
||||
builder = tcb;
|
||||
return schemaMgr.load('/tests/schemas/methods-list-component.json');
|
||||
return specMgr.load('/tests/schemas/methods-list-component.json');
|
||||
})));
|
||||
|
||||
beforeEach((done) => {
|
||||
|
|
|
@ -16,7 +16,6 @@ import { SideMenu } from '../SideMenu/side-menu';
|
|||
import { StickySidebar } from '../../shared/components/index';
|
||||
import {SpecManager} from '../../utils/SpecManager';
|
||||
import { OptionsService, RedocEventsService } from '../../services/index';
|
||||
//import redocVersion from '../../version.js';
|
||||
|
||||
var dom = new BrowserDomAdapter();
|
||||
var _modeLocked = false;
|
||||
|
@ -48,6 +47,7 @@ export class Redoc extends BaseComponent implements AfterViewInit {
|
|||
|
||||
static hideLoadingAnimation() {
|
||||
let redocEl = dom.query('redoc');
|
||||
if (!redocEl) return;
|
||||
dom.addClass(redocEl, 'loading-remove');
|
||||
setTimeout(() => {
|
||||
dom.removeClass(redocEl, 'loading-remove');
|
||||
|
@ -99,6 +99,7 @@ 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';
|
||||
let details = err.message;
|
||||
let erroHtml = `<div class="redoc-error">
|
||||
|
@ -107,10 +108,6 @@ export class Redoc extends BaseComponent implements AfterViewInit {
|
|||
redocEl.innerHTML = erroHtml;
|
||||
}
|
||||
|
||||
// static get version() {
|
||||
// return redocVersion;
|
||||
// }
|
||||
|
||||
static destroy() {
|
||||
let el = dom.query('redoc');
|
||||
let elClone;
|
||||
|
@ -133,9 +130,9 @@ export class Redoc extends BaseComponent implements AfterViewInit {
|
|||
}
|
||||
}
|
||||
|
||||
constructor(schemaMgr: SpecManager, optionsMgr:OptionsService, elementRef:ElementRef,
|
||||
constructor(specMgr: SpecManager, optionsMgr:OptionsService, elementRef:ElementRef,
|
||||
public events:RedocEventsService) {
|
||||
super(schemaMgr);
|
||||
super(specMgr);
|
||||
this.element = elementRef.nativeElement;
|
||||
//parse options (top level component doesn't support inputs)
|
||||
optionsMgr.parseOptions( this.element );
|
||||
|
|
|
@ -25,8 +25,8 @@ export class RequestSamples extends BaseComponent {
|
|||
data: any;
|
||||
@Input() schemaPointer:string;
|
||||
@ViewChildren(Tabs) childQuery:QueryList<Tabs>;
|
||||
constructor(schemaMgr:SpecManager, public events:RedocEventsService) {
|
||||
super(schemaMgr);
|
||||
constructor(specMgr:SpecManager, public events:RedocEventsService) {
|
||||
super(specMgr);
|
||||
|
||||
this.selectedLang = this.events.samplesLanguageChanged;
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ function isNumeric(n) {
|
|||
export class ResponsesList extends BaseComponent {
|
||||
data: any;
|
||||
options: any;
|
||||
constructor(schemaMgr:SpecManager, optionsMgr:OptionsService) {
|
||||
super(schemaMgr);
|
||||
constructor(specMgr:SpecManager, optionsMgr:OptionsService) {
|
||||
super(specMgr);
|
||||
this.options = optionsMgr.options;
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ export class ResponsesList extends BaseComponent {
|
|||
resp.pointer = JsonPointer.join(this.pointer, respCode);
|
||||
if (resp.$ref) {
|
||||
let ref = resp.$ref;
|
||||
resp = this.schemaMgr.byPointer(resp.$ref);
|
||||
resp = this.specMgr.byPointer(resp.$ref);
|
||||
resp.pointer = ref;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,8 +25,8 @@ function hasExample(response) {
|
|||
})
|
||||
export class ResponsesSamples extends BaseComponent {
|
||||
data: any;
|
||||
constructor(schemaMgr:SpecManager) {
|
||||
super(schemaMgr);
|
||||
constructor(specMgr:SpecManager) {
|
||||
super(specMgr);
|
||||
}
|
||||
|
||||
prepareModel() {
|
||||
|
@ -44,7 +44,7 @@ export class ResponsesSamples extends BaseComponent {
|
|||
resp.pointer = JsonPointer.join(this.pointer, respCode);
|
||||
if (resp.$ref) {
|
||||
let ref = resp.$ref;
|
||||
resp = this.schemaMgr.byPointer(resp.$ref);
|
||||
resp = this.specMgr.byPointer(resp.$ref);
|
||||
resp.pointer = ref;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,10 +21,10 @@ export class SchemaSample extends BaseComponent {
|
|||
|
||||
private _normalizer:SchemaNormalizer;
|
||||
|
||||
constructor(schemaMgr:SpecManager, elementRef:ElementRef) {
|
||||
super(schemaMgr);
|
||||
constructor(specMgr:SpecManager, elementRef:ElementRef) {
|
||||
super(specMgr);
|
||||
this.element = elementRef.nativeElement;
|
||||
this._normalizer = new SchemaNormalizer(schemaMgr);
|
||||
this._normalizer = new SchemaNormalizer(specMgr);
|
||||
}
|
||||
|
||||
init() {
|
||||
|
|
|
@ -29,14 +29,14 @@ describe('Redoc components', () => {
|
|||
provide(SpecManager, {useValue: new SpecManager()})
|
||||
]);
|
||||
beforeEach(async(inject([TestComponentBuilder, SpecManager, OptionsService],
|
||||
(tcb, schemaMgr, opts) => {
|
||||
(tcb, specMgr, opts) => {
|
||||
builder = tcb;
|
||||
testOptions = opts;
|
||||
testOptions.options = {
|
||||
scrollYOffset: () => 0,
|
||||
scrollParent: window
|
||||
};
|
||||
return schemaMgr.load('/tests/schemas/extended-petstore.yml');
|
||||
return specMgr.load('/tests/schemas/extended-petstore.yml');
|
||||
})));
|
||||
|
||||
beforeEach((done) => {
|
||||
|
|
|
@ -35,10 +35,10 @@ export class SideMenu extends BaseComponent {
|
|||
activeItemCaption: string;
|
||||
options: any;
|
||||
data: any;
|
||||
constructor(schemaMgr:SpecManager, elementRef:ElementRef, private dom:BrowserDomAdapter,
|
||||
constructor(specMgr:SpecManager, elementRef:ElementRef, private dom:BrowserDomAdapter,
|
||||
private scrollService:ScrollService, private menuService:MenuService, private hash:Hash,
|
||||
optionsService:OptionsService, private detectorRef:ChangeDetectorRef) {
|
||||
super(schemaMgr);
|
||||
super(specMgr);
|
||||
this.$element = elementRef.nativeElement;
|
||||
|
||||
this.activeCatCaption = '';
|
||||
|
|
|
@ -5,20 +5,20 @@ import { BaseComponent } from '../components/base';
|
|||
|
||||
describe('Redoc components', () => {
|
||||
describe('BaseComponent', () => {
|
||||
let schemaMgr;
|
||||
let specMgr;
|
||||
let component;
|
||||
|
||||
beforeAll(() => {
|
||||
schemaMgr = new SpecManager();
|
||||
schemaMgr._schema = {tags: []};
|
||||
specMgr = new SpecManager();
|
||||
specMgr._schema = {tags: []};
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
component = new BaseComponent(schemaMgr);
|
||||
component = new BaseComponent(specMgr);
|
||||
});
|
||||
|
||||
it('should set instance properties', () => {
|
||||
component.schemaMgr.should.be.equal(schemaMgr);
|
||||
component.specMgr.should.be.equal(specMgr);
|
||||
//component.schema.should.be.of.type('object');
|
||||
expect(component.componentSchema).toBeNull();
|
||||
});
|
||||
|
@ -26,7 +26,7 @@ describe('Redoc components', () => {
|
|||
it('should set componentSchema based on pointer on ngOnInit', () => {
|
||||
component.pointer = '/tags';
|
||||
component.ngOnInit();
|
||||
component.componentSchema.should.be.deepEqual(schemaMgr._schema.tags);
|
||||
component.componentSchema.should.be.deepEqual(specMgr._schema.tags);
|
||||
});
|
||||
|
||||
it('should call prepareModel and init virtual methods after init', () => {
|
||||
|
|
|
@ -84,14 +84,14 @@ export class BaseComponent implements OnInit, OnDestroy {
|
|||
pointer: String;
|
||||
dereferencedCache = {};
|
||||
|
||||
constructor(public schemaMgr: SpecManager) {
|
||||
constructor(public specMgr: SpecManager) {
|
||||
}
|
||||
|
||||
/**
|
||||
* onInit method is run by angular2 after all component inputs are resolved
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.componentSchema = this.schemaMgr.byPointer(this.pointer || '');
|
||||
this.componentSchema = this.specMgr.byPointer(this.pointer || '');
|
||||
this.prepareModel();
|
||||
this.init();
|
||||
}
|
||||
|
|
|
@ -3,9 +3,12 @@ import 'dropkickjs/build/css/dropkick.css!css';
|
|||
import 'prismjs/themes/prism-dark.css!css';
|
||||
import 'hint.css/hint.base.css!css';
|
||||
import './components/Redoc/redoc-initial-styles.css!css';
|
||||
import { redocVersion } from './version.js';
|
||||
|
||||
import { Redoc } from './components/index';
|
||||
|
||||
Redoc.version = redocVersion;
|
||||
|
||||
export var init = Redoc.init;
|
||||
|
||||
window['Redoc'] = Redoc;
|
||||
|
|
|
@ -6,57 +6,54 @@ import {
|
|||
beforeEach,
|
||||
describe,
|
||||
beforeEachProviders,
|
||||
it
|
||||
it,
|
||||
async
|
||||
} from '@angular/core/testing';
|
||||
|
||||
import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||
|
||||
import { OptionsService } from './options.service';
|
||||
import { MenuService } from './menu.service';
|
||||
import { Hash } from './hash.service';
|
||||
import { ScrollService } from './scroll.service';
|
||||
import { RedocEventsService } from './events.service';
|
||||
import { MethodsList } from '../components/index';
|
||||
import { SpecManager } from '../utils/SpecManager';;
|
||||
|
||||
describe('Menu service', () => {
|
||||
let menu, hashService, scroll;
|
||||
let builder;
|
||||
let schemaMgr;
|
||||
let specMgr = new SpecManager();
|
||||
|
||||
beforeEachProviders(() => [
|
||||
provide(BrowserDomAdapter, {useClass: BrowserDomAdapter}),
|
||||
provide(OptionsService, {useClass: OptionsService}),
|
||||
provide(Hash, {useClass: Hash}),
|
||||
provide(ScrollService, {useClass: ScrollService}),
|
||||
provide(RedocEventsService, {useClass: RedocEventsService}),
|
||||
provide(SpecManager, {useClass: SpecManager})
|
||||
provide(BrowserDomAdapter, {useClass: BrowserDomAdapter}),
|
||||
provide(Hash, {useClass: Hash}),
|
||||
provide(ScrollService, {useClass: ScrollService}),
|
||||
provide(SpecManager, {useValue: new SpecManager()})
|
||||
]);
|
||||
|
||||
beforeEach(inject([Hash, ScrollService, SpecManager, TestComponentBuilder],
|
||||
(_hash, _scroll, _schemaMgr, tcb) => {
|
||||
beforeEach(async(inject([Hash, ScrollService, TestComponentBuilder, SpecManager],
|
||||
(_hash, _scroll, tcb, _specMgr) => {
|
||||
hashService = _hash;
|
||||
scroll = _scroll;
|
||||
schemaMgr = _schemaMgr;
|
||||
builder = tcb;
|
||||
}));
|
||||
specMgr = _specMgr;
|
||||
})));
|
||||
|
||||
|
||||
beforeEach((done) => {
|
||||
schemaMgr.load('/tests/schemas/extended-petstore.yml').then(() => {
|
||||
menu = new MenuService(hashService, scroll, schemaMgr);
|
||||
beforeEach(done => {
|
||||
specMgr.load('/tests/schemas/extended-petstore.yml').then(r => {
|
||||
done();
|
||||
}).catch((err) => done.fail(err));
|
||||
}).catch(e => {
|
||||
done.fail(e);
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach((done) => {
|
||||
builder.createAsync(TestAppComponent).then((fixture) => {
|
||||
beforeEach(done => {
|
||||
menu = new MenuService(hashService, scroll, specMgr);
|
||||
builder.createAsync(TestAppComponent).then(fixture => {
|
||||
fixture.detectChanges();
|
||||
done();
|
||||
}).catch((err) => done.fail(err));
|
||||
}).catch(err => done.fail(err) );
|
||||
});
|
||||
|
||||
|
||||
it('should run hashScroll when hash changed', (done) => {
|
||||
spyOn(menu, 'hashScroll').and.callThrough();
|
||||
hashService.changed.subscribe(() => {
|
||||
|
|
|
@ -19,10 +19,9 @@ export class MenuService {
|
|||
activeMethodIdx: number = -1;
|
||||
activeMethodPtr: string;
|
||||
|
||||
constructor(private hash:Hash, private scrollService:ScrollService, schemaMgr:SpecManager) {
|
||||
constructor(private hash:Hash, private scrollService:ScrollService, specMgr:SpecManager) {
|
||||
this.hash = hash;
|
||||
|
||||
this.categories = Array.from(schemaMgr.buildMenuTree().entries()).map(
|
||||
this.categories = Array.from(specMgr.buildMenuTree().entries()).map(
|
||||
el => ({name: el[0], description: el[1].description, methods: el[1].methods})
|
||||
);
|
||||
|
||||
|
|
|
@ -8,12 +8,12 @@ import {
|
|||
import { SpecManager } from '../utils/SpecManager';;
|
||||
|
||||
describe('Spec Helper', () => {
|
||||
let schemaMgr:SpecManager = new SpecManager();
|
||||
let normalizer = new SchemaNormalizer(schemaMgr);
|
||||
let specMgr:SpecManager = new SpecManager();
|
||||
let normalizer = new SchemaNormalizer(specMgr);
|
||||
|
||||
describe('Dereference', () => {
|
||||
beforeAll(done => {
|
||||
schemaMgr.load('/tests/schemas/base-component-dereference.json').then(
|
||||
specMgr.load('/tests/schemas/base-component-dereference.json').then(
|
||||
() => done()
|
||||
);
|
||||
});
|
||||
|
@ -23,7 +23,7 @@ describe('Spec Helper', () => {
|
|||
let pointer;
|
||||
beforeAll(() => {
|
||||
pointer = '/paths/test1/get/parameters/0';
|
||||
resolved = normalizer.normalize(schemaMgr.byPointer(pointer), pointer);
|
||||
resolved = normalizer.normalize(specMgr.byPointer(pointer), pointer);
|
||||
});
|
||||
|
||||
it('should not contain $ref property', () => {
|
||||
|
@ -41,7 +41,7 @@ describe('Spec Helper', () => {
|
|||
it('should insert correct definition instead of reference', () => {
|
||||
delete resolved.title;
|
||||
delete resolved._pointer;
|
||||
resolved.should.be.deepEqual(schemaMgr.schema.definitions.Simple);
|
||||
resolved.should.be.deepEqual(specMgr.schema.definitions.Simple);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -49,7 +49,7 @@ describe('Spec Helper', () => {
|
|||
let resolved;
|
||||
beforeAll(() => {
|
||||
let pointer = '/paths/test2/get/parameters/0';
|
||||
resolved = normalizer.normalize(schemaMgr.byPointer(pointer), pointer);
|
||||
resolved = normalizer.normalize(specMgr.byPointer(pointer), pointer);
|
||||
});
|
||||
|
||||
it('should not touch title if exist', () => {
|
||||
|
@ -68,11 +68,10 @@ describe('Spec Helper', () => {
|
|||
let resolved;
|
||||
beforeAll(() => {
|
||||
let pointer = '/paths/test3/get/parameters/0';
|
||||
resolved = normalizer.normalize(schemaMgr.byPointer(pointer), pointer);
|
||||
resolved = normalizer.normalize(specMgr.byPointer(pointer), pointer);
|
||||
});
|
||||
|
||||
it('should resolve array schema', () => {
|
||||
console.log(resolved);
|
||||
expect(resolved.$ref).toBeUndefined();
|
||||
expect(resolved.items.$ref).toBeUndefined();
|
||||
resolved.type.should.be.equal('array');
|
||||
|
@ -86,7 +85,7 @@ describe('Spec Helper', () => {
|
|||
let resolved;
|
||||
beforeAll(() => {
|
||||
let pointer = '/paths/test4/get/parameters/0';
|
||||
resolved = normalizer.normalize(schemaMgr.byPointer(pointer), pointer);
|
||||
resolved = normalizer.normalize(specMgr.byPointer(pointer), pointer);
|
||||
});
|
||||
|
||||
it('should resolve circular schema', () => {
|
||||
|
@ -103,7 +102,7 @@ describe('Spec Helper', () => {
|
|||
let resolved;
|
||||
beforeAll(() => {
|
||||
let pointer = '/paths/test5/get/parameters/0';
|
||||
resolved = normalizer.normalize(schemaMgr.byPointer(pointer), pointer);
|
||||
resolved = normalizer.normalize(specMgr.byPointer(pointer), pointer);
|
||||
});
|
||||
|
||||
it('should skip other fields', () => {
|
||||
|
@ -122,14 +121,14 @@ describe('Spec Helper', () => {
|
|||
|
||||
describe('mergeAllOf', () => {
|
||||
beforeAll((done) => {
|
||||
schemaMgr.load('tests/schemas/base-component-joinallof.json').then(() => done());
|
||||
specMgr.load('tests/schemas/base-component-joinallof.json').then(() => done());
|
||||
});
|
||||
|
||||
describe('Simple allOf merge', () => {
|
||||
let joined;
|
||||
beforeAll(() => {
|
||||
let pointer = '/definitions/SimpleAllOf';
|
||||
joined = normalizer.normalize(schemaMgr.byPointer(pointer), pointer);
|
||||
joined = normalizer.normalize(specMgr.byPointer(pointer), pointer);
|
||||
});
|
||||
|
||||
it('should remove $allOf field', () => {
|
||||
|
@ -155,7 +154,7 @@ describe('Spec Helper', () => {
|
|||
let joined;
|
||||
beforeAll(() => {
|
||||
let pointer = '/definitions/AllOfWithRef';
|
||||
joined = normalizer.normalize(schemaMgr.byPointer(pointer), pointer);
|
||||
joined = normalizer.normalize(specMgr.byPointer(pointer), pointer);
|
||||
});
|
||||
|
||||
it('should remove $allOf field', () => {
|
||||
|
@ -181,7 +180,7 @@ describe('Spec Helper', () => {
|
|||
let joined;
|
||||
beforeAll(() => {
|
||||
let pointer = '/definitions/AllOfWithOther';
|
||||
joined = normalizer.normalize(schemaMgr.byPointer(pointer), pointer);
|
||||
joined = normalizer.normalize(specMgr.byPointer(pointer), pointer);
|
||||
});
|
||||
|
||||
it('should remove $allOf field', () => {
|
||||
|
@ -212,19 +211,19 @@ describe('Spec Helper', () => {
|
|||
it('should merge properties and required when defined on allOf level', () => {
|
||||
let pointer = '/definitions/PropertiesOnAllOfLevel';
|
||||
let joined;
|
||||
(() => joined = normalizer.normalize(schemaMgr.byPointer(pointer), pointer)).should.not.throw();
|
||||
(() => joined = normalizer.normalize(specMgr.byPointer(pointer), pointer)).should.not.throw();
|
||||
Object.keys(joined.properties).length.should.be.equal(3);
|
||||
});
|
||||
|
||||
it('should throw when merging schemas with different types', () => {
|
||||
let pointer = '/definitions/BadAllOf1';
|
||||
(() => normalizer.normalize(schemaMgr.byPointer(pointer), pointer)).should.throw();
|
||||
(() => normalizer.normalize(specMgr.byPointer(pointer), pointer)).should.throw();
|
||||
});
|
||||
|
||||
it('should handle nested allOF', () => {
|
||||
let pointer = '/definitions/NestedAllOf';
|
||||
let joined;
|
||||
(() => joined = normalizer.normalize(schemaMgr.byPointer(pointer), pointer)).should.not.throw();
|
||||
(() => joined = normalizer.normalize(specMgr.byPointer(pointer), pointer)).should.not.throw();
|
||||
Object.keys(joined.properties).length.should.be.equal(4);
|
||||
Object.keys(joined.properties).should.be.deepEqual(['prop1', 'prop2', 'prop3', 'prop4']);
|
||||
joined.required.should.be.deepEqual(['prop1', 'prop3']);
|
||||
|
|
|
@ -3,23 +3,23 @@
|
|||
import { SpecManager } from '../../lib/utils/SpecManager';
|
||||
describe('Utils', () => {
|
||||
describe('Schema manager', () => {
|
||||
let schemaMgr;
|
||||
let specMgr;
|
||||
|
||||
beforeEach(() => {
|
||||
schemaMgr = new SpecManager();
|
||||
specMgr = new SpecManager();
|
||||
});
|
||||
|
||||
it('Should be a singleton', ()=> {
|
||||
(new SpecManager()).should.be.equal(schemaMgr);
|
||||
SpecManager.instance().should.be.equal(schemaMgr);
|
||||
(new SpecManager()).should.be.equal(specMgr);
|
||||
SpecManager.instance().should.be.equal(specMgr);
|
||||
});
|
||||
|
||||
it('load should return a promise', ()=> {
|
||||
schemaMgr.load('/tests/schemas/extended-petstore.yml').should.be.instanceof(Promise);
|
||||
specMgr.load('/tests/schemas/extended-petstore.yml').should.be.instanceof(Promise);
|
||||
});
|
||||
|
||||
it('load should reject promise for invalid url', (done)=> {
|
||||
schemaMgr.load('/nonexisting/schema.json').then(() => {
|
||||
specMgr.load('/nonexisting/schema.json').then(() => {
|
||||
throw new Error('Succees handler should not be called');
|
||||
}, () => {
|
||||
done();
|
||||
|
@ -27,7 +27,7 @@ describe('Utils', () => {
|
|||
});
|
||||
|
||||
it('load should resolve promise for valid url', (done)=> {
|
||||
schemaMgr.load('/tests/schemas/extended-petstore.yml').then(() => {
|
||||
specMgr.load('/tests/schemas/extended-petstore.yml').then(() => {
|
||||
done();
|
||||
}, () => {
|
||||
throw new Error('Error handler should not be called');
|
||||
|
@ -36,7 +36,7 @@ describe('Utils', () => {
|
|||
|
||||
describe('Schema manager basic functionality', ()=> {
|
||||
beforeAll(function (done) {
|
||||
schemaMgr.load('/tests/schemas/extended-petstore.yml').then(() => {
|
||||
specMgr.load('/tests/schemas/extended-petstore.yml').then(() => {
|
||||
done();
|
||||
}, () => {
|
||||
throw new Error('Error handler should not be called');
|
||||
|
@ -45,23 +45,23 @@ describe('Utils', () => {
|
|||
|
||||
|
||||
it('should contain non-empty schema', ()=> {
|
||||
schemaMgr.schema.should.be.an.Object();
|
||||
schemaMgr.schema.should.be.not.empty();
|
||||
specMgr.schema.should.be.an.Object();
|
||||
specMgr.schema.should.be.not.empty();
|
||||
});
|
||||
|
||||
it('should correctly init api url', ()=> {
|
||||
schemaMgr.apiUrl.should.be.equal('http://petstore.swagger.io/v2');
|
||||
specMgr.apiUrl.should.be.equal('http://petstore.swagger.io/v2');
|
||||
});
|
||||
|
||||
describe('byPointer method', () => {
|
||||
it('should return correct schema part', ()=> {
|
||||
let part = schemaMgr.byPointer('/tags/3');
|
||||
part.should.be.deepEqual(schemaMgr.schema.tags[3]);
|
||||
part.should.be.equal(schemaMgr.schema.tags[3]);
|
||||
let part = specMgr.byPointer('/tags/3');
|
||||
part.should.be.deepEqual(specMgr.schema.tags[3]);
|
||||
part.should.be.equal(specMgr.schema.tags[3]);
|
||||
});
|
||||
|
||||
it('should return null for incorrect pointer', ()=> {
|
||||
let part = schemaMgr.byPointer('/incorrect/pointer');
|
||||
let part = specMgr.byPointer('/incorrect/pointer');
|
||||
expect(part).toBeNull();
|
||||
});
|
||||
});
|
||||
|
@ -69,7 +69,7 @@ describe('Utils', () => {
|
|||
|
||||
describe('getTagsMap method', () => {
|
||||
beforeAll(function () {
|
||||
schemaMgr._schema = {
|
||||
specMgr._schema = {
|
||||
tags: [
|
||||
{name: 'tag1', description: 'info1'},
|
||||
{name: 'tag2', description: 'info2', 'x-traitTag': true}
|
||||
|
@ -78,7 +78,7 @@ describe('Utils', () => {
|
|||
});
|
||||
|
||||
it('should return correct tags map', () => {
|
||||
let tagsMap = schemaMgr.getTagsMap();
|
||||
let tagsMap = specMgr.getTagsMap();
|
||||
let expectedResult = {
|
||||
tag1: {description: 'info1', 'x-traitTag': false},
|
||||
tag2: {description: 'info2', 'x-traitTag': true}
|
||||
|
@ -87,8 +87,8 @@ describe('Utils', () => {
|
|||
});
|
||||
|
||||
it('should return empty array for non-specified tags', () => {
|
||||
delete schemaMgr._schema.tags;
|
||||
let tagsMap = schemaMgr.getTagsMap();
|
||||
delete specMgr._schema.tags;
|
||||
let tagsMap = specMgr.getTagsMap();
|
||||
tagsMap.should.be.empty();
|
||||
});
|
||||
});
|
||||
|
@ -121,8 +121,8 @@ describe('Utils', () => {
|
|||
let entries;
|
||||
|
||||
beforeAll(() => {
|
||||
schemaMgr._schema = suitSchema;
|
||||
menuTree = schemaMgr.buildMenuTree();
|
||||
specMgr._schema = suitSchema;
|
||||
menuTree = specMgr.buildMenuTree();
|
||||
entries = Array.from(menuTree.entries());
|
||||
});
|
||||
|
||||
|
@ -162,7 +162,7 @@ describe('Utils', () => {
|
|||
info.methods.should.be.an.Array();
|
||||
for (let methodInfo of info.methods) {
|
||||
methodInfo.should.have.properties(['pointer', 'summary']);
|
||||
let methSchema = schemaMgr.byPointer(methodInfo.pointer);
|
||||
let methSchema = specMgr.byPointer(methodInfo.pointer);
|
||||
expect(methSchema).not.toBeNull();
|
||||
if (methSchema.summary) {
|
||||
methSchema.summary.should.be.equal(methodInfo.summary);
|
||||
|
@ -174,7 +174,7 @@ describe('Utils', () => {
|
|||
|
||||
describe('getMethodParams method', () => {
|
||||
beforeAll((done) => {
|
||||
schemaMgr.load('/tests/schemas/schema-mgr-methodparams.json').then(() => {
|
||||
specMgr.load('/tests/schemas/schema-mgr-methodparams.json').then(() => {
|
||||
done();
|
||||
}, () => {
|
||||
done(new Error('Error handler should not be called'));
|
||||
|
@ -182,26 +182,26 @@ describe('Utils', () => {
|
|||
});
|
||||
|
||||
it('should propagate path parameters', () => {
|
||||
let params = schemaMgr.getMethodParams('/paths/test1/get');
|
||||
let params = specMgr.getMethodParams('/paths/test1/get');
|
||||
params.length.should.be.equal(2);
|
||||
params[0].name.should.be.equal('methodParam');
|
||||
params[1].name.should.be.equal('pathParam');
|
||||
});
|
||||
|
||||
it('should inject correct pointers', () => {
|
||||
let params = schemaMgr.getMethodParams('/paths/test1/get');
|
||||
let params = specMgr.getMethodParams('/paths/test1/get');
|
||||
params[0]._pointer.should.be.equal('/paths/test1/get/parameters/0');
|
||||
params[1]._pointer.should.be.equal('/paths/test1/parameters/0');
|
||||
});
|
||||
|
||||
it('should accept pointer directly to parameters', () => {
|
||||
let params = schemaMgr.getMethodParams('/paths/test1/get/parameters', true);
|
||||
let params = specMgr.getMethodParams('/paths/test1/get/parameters', true);
|
||||
expect(params).not.toBeNull();
|
||||
params.length.should.be.equal(2);
|
||||
});
|
||||
|
||||
it('should resolve path params from Parameters Definitions Object', () => {
|
||||
let params = schemaMgr.getMethodParams('/paths/test2/get', true);
|
||||
let params = specMgr.getMethodParams('/paths/test2/get', true);
|
||||
params.length.should.be.equal(2);
|
||||
params[0].name.should.be.equal('methodParam');
|
||||
params[1].name.should.be.equal('extParam');
|
||||
|
@ -209,21 +209,21 @@ describe('Utils', () => {
|
|||
});
|
||||
|
||||
it('should resolve method params from Parameters Definitions Object', () => {
|
||||
let params = schemaMgr.getMethodParams('/paths/test3/get', true);
|
||||
let params = specMgr.getMethodParams('/paths/test3/get', true);
|
||||
params.length.should.be.equal(1);
|
||||
params[0].name.should.be.equal('extParam');
|
||||
params[0]._pointer.should.be.equal('#/parameters/extparam');
|
||||
});
|
||||
|
||||
it('should throw for parameters other than array', () => {
|
||||
let func = () => schemaMgr.getMethodParams('/paths/test4/get', true);
|
||||
let func = () => specMgr.getMethodParams('/paths/test4/get', true);
|
||||
expect(func).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('findDerivedDefinitions method', () => {
|
||||
beforeAll((done) => {
|
||||
schemaMgr.load('/tests/schemas/extended-petstore.yml').then(() => {
|
||||
specMgr.load('/tests/schemas/extended-petstore.yml').then(() => {
|
||||
done();
|
||||
}, () => {
|
||||
done(new Error('Error handler should not be called'));
|
||||
|
@ -231,7 +231,7 @@ describe('Utils', () => {
|
|||
});
|
||||
|
||||
it('should find derived definitions for Pet', () => {
|
||||
let deriveDefs = schemaMgr.findDerivedDefinitions('#/definitions/Pet');
|
||||
let deriveDefs = specMgr.findDerivedDefinitions('#/definitions/Pet');
|
||||
deriveDefs.should.be.instanceof(Array);
|
||||
deriveDefs.should.not.be.empty();
|
||||
deriveDefs.should.be.deepEqual([
|
||||
|
@ -241,7 +241,7 @@ describe('Utils', () => {
|
|||
});
|
||||
|
||||
it('should return emtpy array for definitions that dont have discriminator', () => {
|
||||
let deriveDefs = schemaMgr.findDerivedDefinitions('#/definitions/Order');
|
||||
let deriveDefs = specMgr.findDerivedDefinitions('#/definitions/Order');
|
||||
deriveDefs.should.be.instanceof(Array);
|
||||
deriveDefs.should.be.empty();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user