Added few basic components

This commit is contained in:
Roman Gotsiy 2015-10-08 23:21:51 +03:00
parent aaa78d7c50
commit 3d1b529222
10 changed files with 133 additions and 6 deletions

View File

@ -0,0 +1,7 @@
<div>
<h2>{{data.methodInfo.summary}}</h2>
<p> <strong>{{data.method}}</strong> <code>{{data.path}}</code> </p>
<p class="description">
{{data.methodInfo.description}}
</p>
</div>

View File

@ -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]];

View File

@ -0,0 +1,3 @@
<div *ng-for="#method of data.methods">
<method pointer="{{pointer}}/{{method}}"></method>
</div>

View File

@ -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]];

View File

@ -0,0 +1,3 @@
<div *ng-for="#path of data.paths">
<methods-list pointer="/paths/{{path | jsonPointerEscape}}"></methods-list>
</div>

View File

@ -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]]

View File

@ -1 +1,2 @@
<redoc-api-info> </redoc-api-info>
<paths-list> </paths-list>

View File

@ -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) {

View File

@ -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;

View File

@ -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);
}
}