mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-10 19:06:34 +03:00
Added few basic components
This commit is contained in:
parent
aaa78d7c50
commit
3d1b529222
7
lib/components/Method/method.html
Normal file
7
lib/components/Method/method.html
Normal 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>
|
36
lib/components/Method/method.js
Normal file
36
lib/components/Method/method.js
Normal 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]];
|
3
lib/components/MethodsList/methods-list.html
Normal file
3
lib/components/MethodsList/methods-list.html
Normal file
|
@ -0,0 +1,3 @@
|
|||
<div *ng-for="#method of data.methods">
|
||||
<method pointer="{{pointer}}/{{method}}"></method>
|
||||
</div>
|
41
lib/components/MethodsList/methods-list.js
Normal file
41
lib/components/MethodsList/methods-list.js
Normal 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]];
|
3
lib/components/PathsList/paths-list.html
Normal file
3
lib/components/PathsList/paths-list.html
Normal file
|
@ -0,0 +1,3 @@
|
|||
<div *ng-for="#path of data.paths">
|
||||
<methods-list pointer="/paths/{{path | jsonPointerEscape}}"></methods-list>
|
||||
</div>
|
30
lib/components/PathsList/paths-list.js
Normal file
30
lib/components/PathsList/paths-list.js
Normal 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]]
|
|
@ -1 +1,2 @@
|
|||
<redoc-api-info> </redoc-api-info>
|
||||
<paths-list> </paths-list>
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user