Fix e2e tests + minor refactoring

This commit is contained in:
Roman Hotsiy 2016-09-01 09:53:42 +03:00
parent 34d8230f8b
commit d3ef8f003c
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
6 changed files with 19 additions and 10 deletions

View File

@ -46,7 +46,7 @@ export class JsonSchemaLazy implements OnDestroy, AfterViewInit {
}
load() {
if (this.optionsService.options.disableLazySchemas) return;
if (this.disableLazy) return;
if (this.loaded) return;
if (this.pointer) {
this._loadAfterSelf();

View File

@ -47,7 +47,8 @@ export class JsonSchema extends BaseComponent implements OnInit {
this.pointer = activeDescendant.$ref;
this.schema = this.specMgr.byPointer(this.pointer);
this.schema = this.normalizer.normalize(this.schema, this.normPointer, {omitParent: false});
this.schema = this.normalizer.normalize(this.schema, this.normPointer,
{resolved: true});
this.preprocessSchema();
}
@ -80,7 +81,7 @@ export class JsonSchema extends BaseComponent implements OnInit {
this.applyStyling();
this.schema = this.normalizer.normalize(this.schema, this.normPointer);
this.schema = this.normalizer.normalize(this.schema, this.normPointer, {resolved: true});
this.schema = SchemaHelper.unwrapArray(this.schema, this.normPointer);
this.initDescendants();
this.preprocessSchema();

View File

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

View File

@ -40,7 +40,6 @@ export class ParamsList extends BaseComponent implements OnInit {
if (paramsMap.body && paramsMap.body.length) {
let bodyParam = paramsMap.body[0];
bodyParam.pointer = bodyParam._pointer;
this.bodyParam = bodyParam;
paramsMap.body = undefined;
}

View File

@ -24,17 +24,20 @@ export class SchemaNormalizer {
this._dereferencer = new SchemaDereferencer(_schema, this);
}
normalize(schema, ptr, opts:any ={}) {
opts.omitParent = opts.omitParent !== false;
let hasPtr = !!schema.$ref;
if (opts.resolved && !hasPtr) this._dereferencer.visit(ptr);
if (schema['x-redoc-normalized']) return schema;
let res = SchemaWalker.walk(schema, ptr, (subSchema, ptr) => {
let resolved = this._dereferencer.dereference(subSchema, ptr);
if (resolved.allOf) {
resolved._pointer = resolved._pointer || ptr;
resolved = Object.assign({}, resolved);
AllOfMerger.merge(resolved, resolved.allOf, {omitParent: opts.omitParent});
AllOfMerger.merge(resolved, resolved.allOf);
}
return resolved;
});
if (opts.resolved && !hasPtr) this._dereferencer.exit(ptr);
res['x-redoc-normalized'] = true;
return res;
}
@ -88,12 +91,11 @@ class SchemaWalker {
}
class AllOfMerger {
static merge(into, schemas, opts) {
static merge(into, schemas) {
into['x-derived-from'] = [];
for (let i=0; i < schemas.length; i++) {
let subSchema = schemas[i];
into['x-derived-from'].push(subSchema._pointer);
if (opts && opts.omitParent && subSchema.discriminator) continue;
AllOfMerger.checkCanMerge(subSchema, into);
@ -177,6 +179,14 @@ class SchemaDereferencer {
constructor(private _spec: SpecManager, private normalizator: SchemaNormalizer) {
}
visit($ref) {
this._refCouner.visit($ref);
}
exit($ref) {
this._refCouner.exit($ref);
}
dereference(schema: Reference, pointer:string):any {
if (!schema || !schema.$ref) return schema;
window['derefCount'] = window['derefCount'] ? window['derefCount'] + 1 : 1;

View File

@ -91,7 +91,6 @@ if (process.env.JOB === 'e2e-guru') {
delete apisGuruList['googleapis.com:mirror']; // bad urls in images
delete apisGuruList['googleapis.com:discovery']; // non-string references
delete apisGuruList['clarify.io']; // non-string references
delete apisGuruList['clickmeter.com']; // some complex circular reference
//delete apisGuruList['pushpay.com']; // https://github.com/Rebilly/ReDoc/issues/30
delete apisGuruList['bbci.co.uk']; // too big