redoc/lib/components/Method/method.ts

60 lines
1.9 KiB
TypeScript
Raw Normal View History

2015-10-08 23:21:51 +03:00
'use strict';
import { Input, Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import JsonPointer from '../../utils/JsonPointer';
2016-08-22 12:12:13 +03:00
import { BaseComponent, SpecManager } from '../base';
import { SchemaHelper } from '../../services/schema-helper.service';
import { OptionsService } from '../../services/options.service';
2015-10-08 23:21:51 +03:00
2016-08-22 12:12:13 +03:00
@Component({
2015-10-08 23:21:51 +03:00
selector: 'method',
templateUrl: './method.html',
styleUrls: ['./method.css'],
changeDetection: ChangeDetectionStrategy.OnPush
2015-10-08 23:21:51 +03:00
})
2016-08-28 21:46:10 +03:00
export class Method extends BaseComponent implements OnInit {
2016-08-22 12:12:13 +03:00
@Input() pointer:string;
@Input() tag:string;
2016-08-22 12:12:13 +03:00
method:any;
constructor(specMgr:SpecManager, private optionsService: OptionsService) {
super(specMgr);
2015-10-08 23:21:51 +03:00
}
init() {
this.method = {};
if (this.optionsService.options.hideHostname) {
this.method.apiUrl = this.specMgr.basePath;
} else {
this.method.apiUrl = this.specMgr.apiUrl;
}
this.method.httpMethod = JsonPointer.baseName(this.pointer);
this.method.path = JsonPointer.baseName(this.pointer, 2);
this.method.info = this.componentSchema;
this.method.info.tags = this.filterMainTags(this.method.info.tags);
this.method.bodyParam = this.findBodyParam();
this.method.summary = SchemaHelper.methodSummary(this.componentSchema);
2016-02-07 17:10:32 +03:00
if (this.componentSchema.operationId) {
this.method.anchor = 'operation/' + encodeURIComponent(this.componentSchema.operationId);
2016-02-07 17:10:32 +03:00
} else {
2016-07-26 12:03:15 +03:00
this.method.anchor = this.tag + encodeURIComponent(this.pointer);
2016-02-07 17:10:32 +03:00
}
2015-10-25 14:26:38 +03:00
}
2015-11-17 02:34:13 +03:00
filterMainTags(tags) {
var tagsMap = this.specMgr.getTagsMap();
2016-01-15 18:08:25 +03:00
if (!tags) return [];
2015-12-01 01:29:01 +03:00
return tags.filter(tag => tagsMap[tag] && tagsMap[tag]['x-traitTag']);
2015-11-17 02:34:13 +03:00
}
2015-10-25 14:26:38 +03:00
findBodyParam() {
let pathParams = this.specMgr.getMethodParams(this.pointer, true);
2015-10-25 14:26:38 +03:00
let bodyParam = pathParams.find(param => param.in === 'body');
return bodyParam;
2015-10-08 23:21:51 +03:00
}
2016-08-28 21:46:10 +03:00
ngOnInit() {
this.preinit();
}
2015-10-08 23:21:51 +03:00
}