'use strict'; import { forwardRef } from '@angular/core'; import { JsonPointer } from '../../utils/JsonPointer'; import { RedocComponent, BaseComponent } from '../base'; import { ParamsList, ResponsesList, ResponsesSamples, SchemaSample, RequestSamples } from '../index'; @RedocComponent({ selector: 'method', templateUrl: './lib/components/Method/method.html', styleUrls: ['./lib/components/Method/method.css'], directives: [ forwardRef(() => ParamsList), forwardRef(() => ResponsesList), forwardRef(() => ResponsesSamples), forwardRef(() => SchemaSample), forwardRef(() => RequestSamples)], inputs: ['tag'] }) export class Method extends BaseComponent { constructor(schemaMgr) { super(schemaMgr); } prepareModel() { this.data = {}; this.data.apiUrl = this.schemaMgr.apiUrl; this.data.httpMethod = JsonPointer.baseName(this.pointer); this.data.path = JsonPointer.baseName(this.pointer, 2); this.data.methodInfo = this.componentSchema; this.data.methodInfo.tags = this.filterMainTags(this.data.methodInfo.tags); this.data.bodyParam = this.findBodyParam(); if (this.componentSchema.operationId) { this.data.methodAnchor = 'operation/' + encodeURIComponent(this.componentSchema.operationId); } else { this.data.methodAnchor = 'tag/' + encodeURIComponent(this.tag + this.pointer); } } filterMainTags(tags) { var tagsMap = this.schemaMgr.getTagsMap(); if (!tags) return []; return tags.filter(tag => tagsMap[tag] && tagsMap[tag]['x-traitTag']); } findBodyParam() { let pathParams = this.schemaMgr.getMethodParams(this.pointer, true); let bodyParam = pathParams.find(param => param.in === 'body'); return bodyParam; } }