mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-25 10:03:45 +03:00
Fix menu for cases method has more than one tag
This commit is contained in:
parent
e9c32993a7
commit
753cfdb8fd
|
@ -1,3 +1,4 @@
|
|||
<div *ng-for="#method of data.methods">
|
||||
<method pointer="{{pointer}}/{{method}}" attr.pointer="{{pointer}}/{{method}}"></method>
|
||||
<method [pointer]="method.pointer" [attr.pointer]="method.pointer"
|
||||
[attr.tag]="method.tag"></method>
|
||||
</div>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
import {RedocComponent, BaseComponent} from '../base';
|
||||
import {methods as swaggerMethods} from '../../utils/swagger-defs';
|
||||
import {Method} from '../Method/method';
|
||||
|
||||
@RedocComponent({
|
||||
|
@ -18,9 +17,22 @@ export class MethodsList extends BaseComponent {
|
|||
|
||||
prepareModel() {
|
||||
this.data = {};
|
||||
let pathInfo = this.componentSchema;
|
||||
// follow SwaggerUI behavior for cases when one method has more than one tag:
|
||||
// duplicate methods
|
||||
|
||||
this.data.methods = Object.keys(pathInfo).filter((k) => swaggerMethods.has(k));
|
||||
let menuStructure = this.schemaMgr.buildMenuTree();
|
||||
let methods = Array.from(menuStructure.entries())
|
||||
.map((entry) => {
|
||||
let [tag, methods] = entry;
|
||||
// inject tag name into method info
|
||||
methods.forEach(method => {
|
||||
method.tag = tag;
|
||||
});
|
||||
return methods;
|
||||
})
|
||||
// join arrays
|
||||
.reduce((a, b) => a.concat(b));
|
||||
this.data.methods = methods;
|
||||
// TODO: check $ref field
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
<div *ng-for="#path of data.paths">
|
||||
<methods-list pointer="/paths/{{path | jsonPointerEscape}}"></methods-list>
|
||||
</div>
|
|
@ -1,20 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
import {RedocComponent, BaseComponent} from '../base';
|
||||
import {MethodsList} from '../MethodsList/methods-list';
|
||||
|
||||
@RedocComponent({
|
||||
selector: 'paths-list',
|
||||
templateUrl: './lib/components/PathsList/paths-list.html',
|
||||
directives: [MethodsList]
|
||||
})
|
||||
export class PathsList extends BaseComponent {
|
||||
constructor(schemaMgr) {
|
||||
super(schemaMgr);
|
||||
}
|
||||
|
||||
prepareModel() {
|
||||
this.data = {};
|
||||
this.data.paths = Object.keys(this.componentSchema.paths);
|
||||
}
|
||||
}
|
|
@ -1,2 +1,2 @@
|
|||
<api-info> </api-info>
|
||||
<paths-list> </paths-list>
|
||||
<methods-list> </methods-list>
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
import {RedocComponent, BaseComponent} from '../base';
|
||||
import {SchemaManager} from '../../utils/SchemaManager';
|
||||
import {ApiInfo} from '../ApiInfo/api-info';
|
||||
import {PathsList} from '../PathsList/paths-list';
|
||||
import {MethodsList} from '../MethodsList/methods-list';
|
||||
|
||||
@RedocComponent({
|
||||
selector: 'redoc',
|
||||
providers: [SchemaManager],
|
||||
templateUrl: './lib/components/Redoc/redoc.html',
|
||||
directives: [ApiInfo, PathsList]
|
||||
directives: [ApiInfo, MethodsList]
|
||||
})
|
||||
export class Redoc extends BaseComponent {
|
||||
constructor(schemaMgr) {
|
||||
|
|
|
@ -2,15 +2,13 @@
|
|||
|
||||
import {RedocComponent, BaseComponent} from '../base';
|
||||
import {SchemaManager} from '../../utils/SchemaManager';
|
||||
import {methods as swaggerMethods} from '../../utils/swagger-defs';
|
||||
import {JsonPointer} from '../../utils/JsonPointer';
|
||||
import {SideMenuCat} from '../SideMenuCat/side-menu-cat';
|
||||
import {NgZone} from 'angular2/angular2';
|
||||
|
||||
const CHANGE = {
|
||||
NEXT : 1,
|
||||
BACK : -1,
|
||||
HOLD : 0
|
||||
INITIAL : 0
|
||||
};
|
||||
|
||||
@RedocComponent({
|
||||
|
@ -99,7 +97,8 @@ export class SideMenu extends BaseComponent {
|
|||
|
||||
getMethodEl() {
|
||||
let ptr = this.activeMethodPtr;
|
||||
return document.querySelector(`[pointer="${ptr}"]`);
|
||||
let tag = this.data.menu[this.activeCatIdx].name;
|
||||
return document.querySelector(`[pointer="${ptr}"][tag="${tag}"]`);
|
||||
}
|
||||
|
||||
scrollHandler() {
|
||||
|
@ -120,39 +119,13 @@ export class SideMenu extends BaseComponent {
|
|||
|
||||
prepareModel() {
|
||||
this.data = {};
|
||||
this.data.menu = Array.from(this.buildMenuTree().entries()).map(
|
||||
this.data.menu = Array.from(this.schemaMgr.buildMenuTree().entries()).map(
|
||||
el => ({name: el[0], methods: el[1]})
|
||||
);
|
||||
this.changeActive(CHANGE.HOLD);
|
||||
}
|
||||
|
||||
buildMenuTree() {
|
||||
let tag2MethodMapping = new Map();
|
||||
let paths = this.componentSchema.paths;
|
||||
for (let path of Object.keys(paths)) {
|
||||
let methods = Object.keys(paths[path]).filter((k) => swaggerMethods.has(k));
|
||||
for (let method of methods) {
|
||||
let methodInfo = paths[path][method];
|
||||
let tags = methodInfo.tags;
|
||||
|
||||
//TODO: mb need to do something cleverer
|
||||
if (!tags || !tags.length) {
|
||||
tags = ['[Other]'];
|
||||
}
|
||||
let methodPointer = JsonPointer.compile(['paths', path, method]);
|
||||
let methodSummary = methodInfo.summary;
|
||||
for (let tag of tags) {
|
||||
let tagMethods = tag2MethodMapping.get(tag);
|
||||
if (!tagMethods) {
|
||||
tagMethods = [];
|
||||
tag2MethodMapping.set(tag, tagMethods);
|
||||
}
|
||||
|
||||
tagMethods.push({pointer: methodPointer, summary: methodSummary});
|
||||
}
|
||||
}
|
||||
}
|
||||
return tag2MethodMapping;
|
||||
init() {
|
||||
this.changeActive(CHANGE.INITIAL);
|
||||
}
|
||||
}
|
||||
SideMenu.parameters.push([NgZone]);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
'use strict';
|
||||
import SwaggerParser from 'swagger-parser';
|
||||
import JsonPointer from './JsonPointer';
|
||||
import {methods as swaggerMethods} from './swagger-defs';
|
||||
|
||||
export class SchemaManager {
|
||||
constructor() {
|
||||
|
@ -47,4 +48,34 @@ export class SchemaManager {
|
|||
return res;
|
||||
}
|
||||
|
||||
/* returns ES6 Map */
|
||||
buildMenuTree() {
|
||||
let tag2MethodMapping = new Map();
|
||||
let paths = this._schema.paths;
|
||||
for (let path of Object.keys(paths)) {
|
||||
let methods = Object.keys(paths[path]).filter((k) => swaggerMethods.has(k));
|
||||
for (let method of methods) {
|
||||
let methodInfo = paths[path][method];
|
||||
let tags = methodInfo.tags;
|
||||
|
||||
//TODO: mb need to do something cleverer
|
||||
if (!tags || !tags.length) {
|
||||
tags = ['[Other]'];
|
||||
}
|
||||
let methodPointer = JsonPointer.compile(['paths', path, method]);
|
||||
let methodSummary = methodInfo.summary;
|
||||
for (let tag of tags) {
|
||||
let tagMethods = tag2MethodMapping.get(tag);
|
||||
if (!tagMethods) {
|
||||
tagMethods = [];
|
||||
tag2MethodMapping.set(tag, tagMethods);
|
||||
}
|
||||
|
||||
tagMethods.push({pointer: methodPointer, summary: methodSummary});
|
||||
}
|
||||
}
|
||||
}
|
||||
return tag2MethodMapping;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user