diff --git a/lib/components/Method/method.html b/lib/components/Method/method.html new file mode 100644 index 00000000..ea00a532 --- /dev/null +++ b/lib/components/Method/method.html @@ -0,0 +1,7 @@ +
+

{{data.methodInfo.summary}}

+

{{data.method}} {{data.path}}

+

+ {{data.methodInfo.description}} +

+
diff --git a/lib/components/Method/method.js b/lib/components/Method/method.js new file mode 100644 index 00000000..885646ce --- /dev/null +++ b/lib/components/Method/method.js @@ -0,0 +1,36 @@ +'use strict'; + +import {Component, View, OnInit, CORE_DIRECTIVES} from 'angular2/angular2'; +import {SchemaManager} from '../../utils/SchemaManager'; +import {JsonPointer} from '../../utils/JsonPointer'; + +@Component({ + selector: 'method', + properties: ['pointer'], + lifecycle: [OnInit] +}) +@View({ + templateUrl: './lib/components/Method/method.html', + directives: [CORE_DIRECTIVES] +}) +export class Method { + constructor(schemaMgr) { + this.data = null; + this.schemaMgr = schemaMgr; + } + + onInit() { + this.extractData(); + } + + extractData() { + this.data = {}; + var methodInfo = this.schemaMgr.byPointer(this.pointer); + + this.data.method = JsonPointer.dirName(this.pointer); + this.data.path = JsonPointer.dirName(this.pointer, 2); + this.data.methodInfo = methodInfo; + //TODO: check and apply hooks to modify data + } +} +Method.parameters = [[SchemaManager]]; diff --git a/lib/components/MethodsList/methods-list.html b/lib/components/MethodsList/methods-list.html new file mode 100644 index 00000000..37846147 --- /dev/null +++ b/lib/components/MethodsList/methods-list.html @@ -0,0 +1,3 @@ +
+ +
diff --git a/lib/components/MethodsList/methods-list.js b/lib/components/MethodsList/methods-list.js new file mode 100644 index 00000000..560711fe --- /dev/null +++ b/lib/components/MethodsList/methods-list.js @@ -0,0 +1,41 @@ +'use strict'; + +import {Component, View, OnInit, CORE_DIRECTIVES} from 'angular2/angular2'; +import {SchemaManager} from '../../utils/SchemaManager'; +import {JsonPointer} from '../../utils/JsonPointer'; +import {methods as swaggerMethods} from '../../utils/swagger-defs'; +import {Method} from '../Method/method'; + +@Component({ + selector: 'methods-list', + properties: ['pointer'], + lifecycle: [OnInit] +}) +@View({ + templateUrl: './lib/components/MethodsList/methods-list.html', + directives: [CORE_DIRECTIVES, Method] +}) +export class MethodsList { + _name: string; + + constructor(schemaMgr) { + this.data = null; + this.schemaMgr = schemaMgr; + //this.pointer = pointer; + //this.extractData(); + } + + onInit() { + this.extractData(); + } + + extractData() { + this.data = {}; + var pathInfo = this.schemaMgr.byPointer(this.pointer); + + this.data.path = JsonPointer.dirName(this.pointer); + this.data.methods = Object.keys(pathInfo).filter((k) => swaggerMethods.has(k)); + //TODO: check and apply hooks to modify data + } +} +MethodsList.parameters = [[SchemaManager]]; diff --git a/lib/components/PathsList/paths-list.html b/lib/components/PathsList/paths-list.html new file mode 100644 index 00000000..3f316095 --- /dev/null +++ b/lib/components/PathsList/paths-list.html @@ -0,0 +1,3 @@ +
+ +
diff --git a/lib/components/PathsList/paths-list.js b/lib/components/PathsList/paths-list.js new file mode 100644 index 00000000..47164ed2 --- /dev/null +++ b/lib/components/PathsList/paths-list.js @@ -0,0 +1,30 @@ +'use strict'; + +import {Component, View, CORE_DIRECTIVES} from 'angular2/angular2'; +import {SchemaManager} from '../../utils/SchemaManager'; +import {MethodsList} from '../MethodsList/methods-list'; +import {JsonPointerEscapePipe} from '../../utils/pipes'; + +@Component({ + selector: 'paths-list' +}) +@View({ + templateUrl: './lib/components/PathsList/paths-list.html', + directives: [CORE_DIRECTIVES, MethodsList], + pipes: [JsonPointerEscapePipe] +}) +export class PathsList { + constructor(schemaMgr) { + this.data = null; + this.schema = schemaMgr.schema; + this.extractData(); + } + + extractData() { + this.data = {}; + this.data.paths = Object.keys(this.schema.paths) + + //TODO: check and apply hooks to modify data + } +} +PathsList.parameters = [[SchemaManager]] diff --git a/lib/components/Redoc/redoc.html b/lib/components/Redoc/redoc.html index d12e7c66..c8188c44 100644 --- a/lib/components/Redoc/redoc.html +++ b/lib/components/Redoc/redoc.html @@ -1 +1,2 @@ + diff --git a/lib/components/Redoc/redoc.js b/lib/components/Redoc/redoc.js index f5b5b4e6..d2c523ca 100644 --- a/lib/components/Redoc/redoc.js +++ b/lib/components/Redoc/redoc.js @@ -2,7 +2,8 @@ import {Component, View} from 'angular2/angular2'; import {SchemaManager} from '../../utils/SchemaManager'; -import {RedocInfo} from '../RedocInfo/redoc-info' +import {RedocInfo} from '../RedocInfo/redoc-info'; +import {PathsList} from '../PathsList/paths-list'; @Component({ selector: 'redoc', @@ -10,7 +11,7 @@ import {RedocInfo} from '../RedocInfo/redoc-info' }) @View({ templateUrl: './lib/components/Redoc/redoc.html', - directives: [RedocInfo] + directives: [RedocInfo, PathsList] }) export class Redoc { constructor(schemaMgr) { diff --git a/lib/utils/JsonPointer.js b/lib/utils/JsonPointer.js index eb0e9bc2..12d8a204 100644 --- a/lib/utils/JsonPointer.js +++ b/lib/utils/JsonPointer.js @@ -12,7 +12,10 @@ export class JsonPointer extends JsonPointerLib { * // returns subpath * new JsonPointerHelper.dirName('/path/0/subpath') */ - static dirName(pointer) { - return JsonPointer.parse(pointer).pop(); + static dirName(pointer, level=1) { + var tokens = JsonPointer.parse(pointer); + return tokens[tokens.length - (level)]; } } + +export default JsonPointer; diff --git a/lib/utils/SchemaManager.js b/lib/utils/SchemaManager.js index 0af1aa2a..905b7626 100644 --- a/lib/utils/SchemaManager.js +++ b/lib/utils/SchemaManager.js @@ -1,5 +1,6 @@ 'use strict'; import SwaggerParser from 'swagger-parser'; +import JsonPointer from './JsonPointer' export class SchemaManager { constructor() { @@ -38,7 +39,8 @@ export class SchemaManager { return this._schema; } - getByJsonPath(/* path */) { - //TODO: implement + byPointer(pointer) { + return JsonPointer.get(this._schema, pointer); } + }