Skip to content

Commit

Permalink
fix(oas): exclude description prop if undefined (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
chohmann authored Aug 2, 2023
1 parent 85c8b27 commit fe074de
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
53 changes: 53 additions & 0 deletions src/oas/__tests__/externalDocs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { toExternalDocs } from '../externalDocs';

describe('toExternalDocs', () => {
it.each([null, undefined, ['array'], 'string', 1])(
'returns empty object if supplied externalDocs is "%s"',
externalDocs => {
const actual = toExternalDocs(externalDocs);

expect(actual).toEqual({});
},
);

it.each([null, undefined, 1, ['array'], { object: 'type' }, '', ' '])(
'returns emtpy object if url is "%s"',
url => {
const externalDocs = {
url,
description: 'some description',
};

const actual = toExternalDocs(externalDocs);
expect(actual).toEqual({});
},
);

it.each([null, undefined, 1, ['array'], { object: 'type' }, '', ' '])(
'excludes description if it is "%s"',
description => {
const externalDocs = {
url: 'http://some.url',
description,
};

const actual = toExternalDocs(externalDocs);
expect(actual).toEqual({ externalDocs: { url: 'http://some.url' } });
},
);

it('includes both url and description if they are valid', () => {
const externalDocs = {
url: 'http://some.url',
description: 'some description',
};

const actual = toExternalDocs(externalDocs);
expect(actual).toEqual({
externalDocs: {
url: 'http://some.url',
description: 'some description',
},
});
});
});
5 changes: 4 additions & 1 deletion src/oas/externalDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ export function toExternalDocs(externalDocs: any): { externalDocs?: IExternalDoc
return {};
}

const description = getDescription(externalDocs);
const descriptionProp = description ? { description } : {};

return {
externalDocs: {
url,
description: getDescription(externalDocs),
...descriptionProp,
},
};
}
Expand Down

0 comments on commit fe074de

Please sign in to comment.