From b22b8d2122dd42bcf81f8363f961aa185686c735 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Fri, 1 Jul 2016 17:24:59 +0300 Subject: [PATCH] Refactor menu generation + handle methods without tags --- lib/components/Method/method.html | 2 +- lib/components/Method/method.ts | 2 + lib/components/MethodsList/methods-list.html | 2 +- lib/components/MethodsList/methods-list.ts | 22 +++----- lib/components/SideMenu/side-menu.html | 3 +- lib/components/SideMenu/side-menu.scss | 4 ++ lib/services/menu.service.ts | 5 +- lib/services/schema-helper.service.ts | 54 ++++++++++++++++++++ lib/utils/SpecManager.ts | 47 ----------------- 9 files changed, 74 insertions(+), 67 deletions(-) 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.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 c9c873cf..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.ts b/lib/components/MethodsList/methods-list.ts index 0e9e11d4..0add692f 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 = name; }); + }); this.data.tags = tags; // TODO: check $ref field } 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 @@