diff --git a/lib/components/ApiInfo/api-info.ts b/lib/components/ApiInfo/api-info.ts index 00a301c6..946b6ff2 100644 --- a/lib/components/ApiInfo/api-info.ts +++ b/lib/components/ApiInfo/api-info.ts @@ -12,7 +12,7 @@ import { OptionsService, MenuService } from '../../services/index'; export class ApiInfo extends BaseComponent implements OnInit { info: any = {}; specUrl: String; - constructor(specMgr:SpecManager, private optionsService: OptionsService) { + constructor(specMgr: SpecManager, private optionsService: OptionsService) { super(specMgr); } diff --git a/lib/components/SecurityDefinitions/security-definitions.scss b/lib/components/SecurityDefinitions/security-definitions.scss index a587e985..37974052 100644 --- a/lib/components/SecurityDefinitions/security-definitions.scss +++ b/lib/components/SecurityDefinitions/security-definitions.scss @@ -10,7 +10,7 @@ h2, h3 { } :host h2 { - margin-top: 40px; + padding-top: 40px; } h3 { diff --git a/lib/components/SecurityDefinitions/security-definitions.ts b/lib/components/SecurityDefinitions/security-definitions.ts index b5cd30fc..0515540f 100644 --- a/lib/components/SecurityDefinitions/security-definitions.ts +++ b/lib/components/SecurityDefinitions/security-definitions.ts @@ -2,7 +2,7 @@ import { Component, ChangeDetectionStrategy, OnInit, HostListener } from '@angular/core'; import { SpecManager, BaseComponent } from '../base'; -import { ComponentParser } from '../../services/'; +import { ComponentParser } from '../../services/component-parser.service'; const AUTH_TYPES = { 'oauth2': 'OAuth2', diff --git a/lib/services/menu.service.spec.ts b/lib/services/menu.service.spec.ts index a1cc6059..68797fd0 100644 --- a/lib/services/menu.service.spec.ts +++ b/lib/services/menu.service.spec.ts @@ -98,6 +98,7 @@ describe('Menu service', () => { selector: 'test-app', template: `
+
` }) diff --git a/lib/services/menu.service.ts b/lib/services/menu.service.ts index 8db4542c..db7180f4 100644 --- a/lib/services/menu.service.ts +++ b/lib/services/menu.service.ts @@ -141,10 +141,11 @@ export class MenuService { let ptr = decodeURIComponent(hash.substr(namespace.length + 1)); if (namespace === 'operation') { $el = this.getMethodElByOperId(ptr); - } else if (namespace === 'tag'){ + } else if (namespace === 'tag') { let sectionId = ptr.split('/')[0]; ptr = ptr.substr(sectionId.length) || null; sectionId = namespace + (sectionId ? '/' + sectionId : ''); + $el = this.getMethodElByPtr(ptr, sectionId); } else { $el = this.getMethodElByPtr(null, namespace + '/' + ptr); } diff --git a/lib/utils/md-renderer.ts b/lib/utils/md-renderer.ts index 3c89bd67..114a2d71 100644 --- a/lib/utils/md-renderer.ts +++ b/lib/utils/md-renderer.ts @@ -4,8 +4,6 @@ import { Injectable } from '@angular/core'; import * as slugify from 'slugify'; import * as Remarkable from 'remarkable'; -import { SecurityDefinitions } from '../components/'; - declare var Prism: any; const md = new Remarkable({ html: true, @@ -28,15 +26,12 @@ interface HeadersHandler { @Injectable() export class MdRenderer { + public firstLevelHeadings: string[] = []; + private _origRules:any = {}; private _preProcessors:Function[] = []; - public firstLevelHeadings: string[] = []; constructor(private raw: boolean = false) { - // TODO - if (!raw) { - this.addPreprocessor(SecurityDefinitions.insertTagIntoDescription); - } } addPreprocessor(p: Function) { diff --git a/lib/utils/pipes.ts b/lib/utils/pipes.ts index dfe9b95e..47dc5f49 100644 --- a/lib/utils/pipes.ts +++ b/lib/utils/pipes.ts @@ -4,7 +4,7 @@ import { Pipe, PipeTransform } from '@angular/core'; import { DomSanitizer } from '@angular/platform-browser'; import { isString, stringify, isBlank } from './helpers'; import JsonPointer from './JsonPointer'; -import { MdRenderer} from './'; +import { MdRenderer } from './'; import { JsonFormatter } from './JsonFormatterPipe'; declare var Prism: any; diff --git a/lib/utils/spec-manager.ts b/lib/utils/spec-manager.ts index 283d82e3..0b0d5806 100644 --- a/lib/utils/spec-manager.ts +++ b/lib/utils/spec-manager.ts @@ -5,7 +5,7 @@ import { JsonPointer } from './JsonPointer'; import { parse as urlParse, resolve as urlResolve } from 'url'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; -import { MdRenderer } from './'; +import { MdRenderer } from './md-renderer'; export class SpecManager { public _schema: any = {}; @@ -77,6 +77,10 @@ export class SpecManager { preprocess() { let mdRender = new MdRenderer(); if (!this._schema.info.description) this._schema.info.description = ''; + if (this._schema.securityDefinitions) { + let SecurityDefinitions = require('../components/').SecurityDefinitions; + mdRender.addPreprocessor(SecurityDefinitions.insertTagIntoDescription); + } this._schema.info['x-redoc-html-description'] = mdRender.renderMd(this._schema.info.description); this._schema.info['x-redoc-markdown-headers'] = mdRender.firstLevelHeadings; } diff --git a/tests/spec-bundle.js b/tests/spec-bundle.js index 15692b94..e82fbfb0 100644 --- a/tests/spec-bundle.js +++ b/tests/spec-bundle.js @@ -22,11 +22,14 @@ var TestBed = require('@angular/core/testing').TestBed; var ErrorHandler = require('@angular/core').ErrorHandler; var BrowserDynamicTestingModule = require('@angular/platform-browser-dynamic/testing').BrowserDynamicTestingModule; var platformBrowserDynamicTesting = require('@angular/platform-browser-dynamic/testing').platformBrowserDynamicTesting; -var services = require('../lib/services/index'); + var SpecManager = require('../lib/utils/spec-manager').SpecManager; +var services = require('../lib/services/index'); var REDOC_PIPES = require('../lib/utils/pipes').REDOC_PIPES; -var REDOC_COMMON_DIRECTIVES = require('../lib/shared/components/index').REDOC_COMMON_DIRECTIVES; -var REDOC_DIRECTIVES = require('../lib/components/index').REDOC_DIRECTIVES; +var sharedComponents = require('../lib/shared/components/'); +var REDOC_COMMON_DIRECTIVES = sharedComponents.REDOC_COMMON_DIRECTIVES; +var components = require('../lib/components/'); +var REDOC_DIRECTIVES = components.REDOC_DIRECTIVES; TestBed.initTestEnvironment( BrowserDynamicTestingModule, @@ -43,10 +46,18 @@ beforeEach(function() { services.MenuService, services.WarningsService, services.OptionsService, - { provide: ErrorHandler, useClass: services.CustomErrorHandler } + services.ComponentParser, + services.ContentProjector, + { provide: ErrorHandler, useClass: services.CustomErrorHandler }, + { provide: services.COMPONENT_PARSER_ALLOWED, useValue: { 'security-definitions': components.SecurityDefinitions }} ], declarations: [REDOC_PIPES, REDOC_DIRECTIVES, REDOC_COMMON_DIRECTIVES] }); + TestBed.overrideModule(BrowserDynamicTestingModule, { + set: { + entryComponents: [ sharedComponents.DynamicNg2Wrapper, components.SecurityDefinitions ] + }, + }); });