From 0cd4b644880c72f71c0bb797d960785448eab017 Mon Sep 17 00:00:00 2001 From: Yevhenii Hyzyla Date: Thu, 29 Apr 2021 21:32:06 +0300 Subject: [PATCH] Improve operational summary resolves #1270 Show path instead of in sidebar menu --- src/utils/__tests__/openapi.test.ts | 7 +++++++ src/utils/openapi.ts | 7 ++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/utils/__tests__/openapi.test.ts b/src/utils/__tests__/openapi.test.ts index 9e511259f1..7050f36f16 100644 --- a/src/utils/__tests__/openapi.test.ts +++ b/src/utils/__tests__/openapi.test.ts @@ -101,6 +101,13 @@ describe('Utils', () => { expect(getOperationSummary(operation as any).length).toBe(50); }); + it('Should return pathName if no summary, operationId, description', () => { + const operation = { + pathName: '/sandbox/test' + }; + expect(getOperationSummary(operation as any)).toBe('/sandbox/test'); + }); + it('Should return if no info', () => { const operation = { description: undefined, diff --git a/src/utils/openapi.ts b/src/utils/openapi.ts index e20dbef9d6..71af2572be 100644 --- a/src/utils/openapi.ts +++ b/src/utils/openapi.ts @@ -1,12 +1,12 @@ import { dirname } from 'path'; import * as URLtemplate from 'url-template'; +import { ExtendedOpenAPIOperation } from '../services'; import { FieldModel } from '../services/models'; import { OpenAPIParser } from '../services/OpenAPIParser'; import { OpenAPIEncoding, OpenAPIMediaType, - OpenAPIOperation, OpenAPIParameter, OpenAPIParameterStyle, OpenAPISchema, @@ -62,12 +62,13 @@ export function isOperationName(key: string): boolean { return key in operationNames; } -export function getOperationSummary(operation: OpenAPIOperation): string { +export function getOperationSummary(operation: ExtendedOpenAPIOperation): string { return ( operation.summary || operation.operationId || (operation.description && operation.description.substring(0, 50)) || - '' + operation.pathName || + '' ); }