From e4383ae40bd4642db650c4388ac9137d98470dc3 Mon Sep 17 00:00:00 2001 From: Alex Varchuk Date: Tue, 25 May 2021 14:18:55 +0300 Subject: [PATCH] fix: resolve webhook --- src/services/MenuBuilder.ts | 16 +++++++--------- src/services/models/Webhook.ts | 13 ++++++------- src/types/open-api.d.ts | 1 + src/utils/openapi.ts | 1 + 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/services/MenuBuilder.ts b/src/services/MenuBuilder.ts index 7aacf198..7a750d65 100644 --- a/src/services/MenuBuilder.ts +++ b/src/services/MenuBuilder.ts @@ -234,17 +234,15 @@ export class MenuBuilder { function getTags(parser: OpenAPIParser, paths: OpenAPIPaths, isWebhook?: boolean) { for (const pathName of Object.keys(paths)) { const path = paths[pathName]; - const operations = Object.keys(path); + const operations = Object.keys(path).filter(isOperationName); for (let operationName of operations) { - let operationInfo = isOperationName(operationName) && path[operationName]; - - if (!isOperationName(operationName) && path[operationName].$ref) { - const resolvedOperationInfo = parser.deref(path[operationName] || {}) - operationInfo = resolvedOperationInfo - delete operationInfo.put - operationName = resolvedOperationInfo[Object.keys(resolvedOperationInfo)[0]] + let operationInfo = path[operationName]; + if (path.$ref) { + const resolvedPath = parser.deref(path || {}) + operationName = Object.keys(resolvedPath)[0] + operationInfo = resolvedPath[operationName] } - let operationTags = operationInfo.tags; + let operationTags = operationInfo?.tags; if (!operationTags || !operationTags.length) { // empty tag diff --git a/src/services/models/Webhook.ts b/src/services/models/Webhook.ts index 6e8760f0..a1be7d39 100644 --- a/src/services/models/Webhook.ts +++ b/src/services/models/Webhook.ts @@ -17,14 +17,13 @@ export class WebhookModel { for (const webhookName of Object.keys(webhooks)) { const webhook = webhooks[webhookName]; - const operations = Object.keys(webhook); + const operations = Object.keys(webhook).filter(isOperationName); for (let operationName of operations) { - let operationInfo = isOperationName(operationName) && webhook[operationName]; - - if (!isOperationName(operationName) && webhook[operationName].$ref) { - const resolvedOperationInfo = parser.deref(webhook[operationName] || {}) - operationInfo = resolvedOperationInfo - operationName = resolvedOperationInfo[Object.keys(resolvedOperationInfo)[0]] + let operationInfo = webhook[operationName]; + if (webhook.$ref) { + const resolvedWebhook = parser.deref(webhook || {}); + operationName = Object.keys(resolvedWebhook)[0]; + operationInfo = resolvedWebhook[operationName]; } if (!operationInfo) continue; diff --git a/src/types/open-api.d.ts b/src/types/open-api.d.ts index 78b1b1aa..90ed467b 100644 --- a/src/types/open-api.d.ts +++ b/src/types/open-api.d.ts @@ -58,6 +58,7 @@ export interface OpenAPIPath { trace?: OpenAPIOperation; servers?: OpenAPIServer[]; parameters?: Array>; + $ref?: string; } export interface OpenAPIXCodeSample { diff --git a/src/utils/openapi.ts b/src/utils/openapi.ts index ae70b112..37dba679 100644 --- a/src/utils/openapi.ts +++ b/src/utils/openapi.ts @@ -56,6 +56,7 @@ const operationNames = { patch: true, delete: true, options: true, + $ref: true, }; export function isOperationName(key: string): boolean {