Group methods by tag; add tag and description

This commit is contained in:
Roman Gotsiy 2015-10-28 23:22:12 +02:00
parent 0bfeafb2a8
commit 40ec886f7d
4 changed files with 29 additions and 16 deletions

View File

@ -1,4 +1,8 @@
<div class="methods">
<method *ng-for="#method of data.methods" [pointer]="method.pointer" [attr.pointer]="method.pointer"
<div class="tag" *ng-for="#tag of data.tags">
<h1> {{tag.name}} </h1>
<p *ng-if="tag.description" inner-html="{{ tag.description | marked }}"> </p>
<method *ng-for="#method of tag.methods" [pointer]="method.pointer" [attr.pointer]="method.pointer"
[attr.tag]="method.tag"></method>
</tag>
</div>

View File

@ -21,18 +21,20 @@ export default class MethodsList extends BaseComponent {
// duplicate methods
let menuStructure = this.schemaMgr.buildMenuTree();
let methods = Array.from(menuStructure.entries())
let tags = Array.from(menuStructure.entries())
.map((entry) => {
let [tag, methods] = entry;
let [tag, {description, 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;
return {
name: tag,
description: description,
methods: methods
};
});
this.data.tags = tags;
// TODO: check $ref field
}
}

View File

@ -121,7 +121,7 @@ export default class SideMenu extends BaseComponent {
prepareModel() {
this.data = {};
this.data.menu = Array.from(this.schemaMgr.buildMenuTree().entries()).map(
el => ({name: el[0], methods: el[1]})
el => ({name: el[0], description: el[1].description, methods: el[1].methods})
);
}

View File

@ -88,6 +88,13 @@ export default class SchemaManager {
/* returns ES6 Map */
buildMenuTree() {
let tag2MethodMapping = new Map();
let definedTags = this._schema.tags;
// add tags into map to preserve order
for (let tag of definedTags) {
tag2MethodMapping.set(tag.name, {description: tag.description});
}
let paths = this._schema.paths;
for (let path of Object.keys(paths)) {
let methods = Object.keys(paths[path]).filter((k) => swaggerMethods.has(k));
@ -102,13 +109,13 @@ export default class SchemaManager {
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);
let tagDetails = tag2MethodMapping.get(tag);
if (!tagDetails) {
tagDetails = {};
tag2MethodMapping.set(tag, tagDetails);
}
tagMethods.push({pointer: methodPointer, summary: methodSummary});
if (!tagDetails.methods) tagDetails.methods = [];
tagDetails.methods.push({pointer: methodPointer, summary: methodSummary});
}
}
}