Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve operational summary #1596

Merged
merged 1 commit into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Improve operational summary
resolves #1270

Show path instead of <no summary> in sidebar menu
  • Loading branch information
hyzyla committed Apr 29, 2021
commit 0cd4b644880c72f71c0bb797d960785448eab017
7 changes: 7 additions & 0 deletions src/utils/__tests__/openapi.test.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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