fix generator api parameters

This commit is contained in:
Vlad 2021-03-09 18:56:53 +03:00
parent 59a3045615
commit 46698078a0

View file

@ -52,20 +52,26 @@ class ApiGenerator {
apis: morph.SourceFile[] = []; apis: morph.SourceFile[] = [];
methods = ['patch', 'delete', 'post', 'get', 'put', 'head', 'options', 'trace'];
constructor(openapi: OpenApi) { constructor(openapi: OpenApi) {
this.openapi = openapi; this.openapi = openapi;
this.paths = openapi.paths; this.paths = openapi.paths;
this.serverUrl = openapi.servers[0].url; this.serverUrl = openapi.servers[0].url;
Object.keys(this.paths).forEach((pathKey) => { Object.keys(this.paths).forEach((pathKey) => {
Object.keys(this.paths[pathKey]).forEach((method) => { Object.keys(this.paths[pathKey]).filter((method) => this.methods.includes(method)).forEach((method) => {
const { const {
tags, operationId, parameters, responses, requestBody, security, "x-skip-web-api": skip tags, operationId, responses, requestBody, security, "x-skip-web-api": skip
} = this.paths[pathKey][method]; } = this.paths[pathKey][method];
const parameters = this.paths[pathKey][method].parameters || this.paths[pathKey].parameters;
const controller = toCamel((tags ? tags[0] : pathKey.split('/')[1])); const controller = toCamel((tags ? tags[0] : pathKey.split('/')[1]));
if (skip) { if (skip) {
return; return;
} }
if (!operationId) {
console.log(pathKey);
}
if (this.controllers[controller]) { if (this.controllers[controller]) {
this.controllers[controller][uncapitalize(operationId)] = { this.controllers[controller][uncapitalize(operationId)] = {
parameters, parameters,