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"> <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">
[attr.tag]="method.tag"></method> <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> </div>

View File

@ -21,18 +21,20 @@ export default class MethodsList extends BaseComponent {
// duplicate methods // duplicate methods
let menuStructure = this.schemaMgr.buildMenuTree(); let menuStructure = this.schemaMgr.buildMenuTree();
let methods = Array.from(menuStructure.entries()) let tags = Array.from(menuStructure.entries())
.map((entry) => { .map((entry) => {
let [tag, methods] = entry; let [tag, {description, methods}] = entry;
// inject tag name into method info // inject tag name into method info
methods.forEach(method => { methods.forEach(method => {
method.tag = tag; method.tag = tag;
}); });
return methods; return {
}) name: tag,
// join arrays description: description,
.reduce((a, b) => a.concat(b)); methods: methods
this.data.methods = methods; };
});
this.data.tags = tags;
// TODO: check $ref field // TODO: check $ref field
} }
} }

View File

@ -121,7 +121,7 @@ export default class SideMenu extends BaseComponent {
prepareModel() { prepareModel() {
this.data = {}; this.data = {};
this.data.menu = Array.from(this.schemaMgr.buildMenuTree().entries()).map( 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 */ /* returns ES6 Map */
buildMenuTree() { buildMenuTree() {
let tag2MethodMapping = new Map(); 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; let paths = this._schema.paths;
for (let path of Object.keys(paths)) { for (let path of Object.keys(paths)) {
let methods = Object.keys(paths[path]).filter((k) => swaggerMethods.has(k)); 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 methodPointer = JsonPointer.compile(['paths', path, method]);
let methodSummary = methodInfo.summary; let methodSummary = methodInfo.summary;
for (let tag of tags) { for (let tag of tags) {
let tagMethods = tag2MethodMapping.get(tag); let tagDetails = tag2MethodMapping.get(tag);
if (!tagMethods) { if (!tagDetails) {
tagMethods = []; tagDetails = {};
tag2MethodMapping.set(tag, tagMethods); tag2MethodMapping.set(tag, tagDetails);
} }
if (!tagDetails.methods) tagDetails.methods = [];
tagMethods.push({pointer: methodPointer, summary: methodSummary}); tagDetails.methods.push({pointer: methodPointer, summary: methodSummary});
} }
} }
} }