Skip to content

Commit

Permalink
fix: use operation path if operation summary/description is not provi…
Browse files Browse the repository at this point in the history
…ded (#1596)

resolves #1270
  • Loading branch information
hyzyla committed Apr 29, 2021
1 parent d7a0a4d commit 4b072be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/utils/__tests__/openapi.test.ts
Expand Up @@ -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 <no summary> if no info', () => {
const operation = {
description: undefined,
Expand Down
7 changes: 4 additions & 3 deletions 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,
Expand Down Expand Up @@ -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)) ||
'<no summary>'
operation.pathName ||
'<no summary>'
);
}

Expand Down

0 comments on commit 4b072be

Please sign in to comment.