fix: resolve webhook

This commit is contained in:
Alex Varchuk 2021-05-25 14:18:55 +03:00
parent f6aea16e45
commit e4383ae40b
4 changed files with 15 additions and 16 deletions

View File

@ -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<OpenAPIPath>(path[operationName] || {})
operationInfo = resolvedOperationInfo
delete operationInfo.put
operationName = resolvedOperationInfo[Object.keys(resolvedOperationInfo)[0]]
let operationInfo = path[operationName];
if (path.$ref) {
const resolvedPath = parser.deref<OpenAPIPath>(path || {})
operationName = Object.keys(resolvedPath)[0]
operationInfo = resolvedPath[operationName]
}
let operationTags = operationInfo.tags;
let operationTags = operationInfo?.tags;
if (!operationTags || !operationTags.length) {
// empty tag

View File

@ -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<OpenAPIPath>(webhook[operationName] || {})
operationInfo = resolvedOperationInfo
operationName = resolvedOperationInfo[Object.keys(resolvedOperationInfo)[0]]
let operationInfo = webhook[operationName];
if (webhook.$ref) {
const resolvedWebhook = parser.deref<OpenAPIPath>(webhook || {});
operationName = Object.keys(resolvedWebhook)[0];
operationInfo = resolvedWebhook[operationName];
}
if (!operationInfo) continue;

View File

@ -58,6 +58,7 @@ export interface OpenAPIPath {
trace?: OpenAPIOperation;
servers?: OpenAPIServer[];
parameters?: Array<Referenced<OpenAPIParameter>>;
$ref?: string;
}
export interface OpenAPIXCodeSample {

View File

@ -56,6 +56,7 @@ const operationNames = {
patch: true,
delete: true,
options: true,
$ref: true,
};
export function isOperationName(key: string): boolean {