From 1dd6a9fbdd36842a8f6b357b1fdcc7fd570aa9de Mon Sep 17 00:00:00 2001 From: Jon Ursenbach Date: Fri, 17 Dec 2021 10:53:55 -0800 Subject: [PATCH] feat: adding accessors for operation summary and description (#562) * feat: adding accessors for operation summary and description * feat: trimming summary and description before returning it --- __tests__/operation.test.ts | 22 ++++++++++++++++++++++ src/operation.ts | 8 ++++++++ 2 files changed, 30 insertions(+) diff --git a/__tests__/operation.test.ts b/__tests__/operation.test.ts index 1d3841d0b..36fe33e4e 100644 --- a/__tests__/operation.test.ts +++ b/__tests__/operation.test.ts @@ -22,6 +22,28 @@ describe('#constructor', () => { }); }); +describe('#getSummary()', () => { + it('should return a summary if present', () => { + expect(Oas.init(petstore).operation('/pet/findByTags', 'get').getSummary()).toBe('Finds Pets by tags'); + }); + + it('should return nothing if not present', () => { + expect(Oas.init(referenceSpec).operation('/2.0/users/{username}', 'get').getSummary()).toBeUndefined(); + }); +}); + +describe('#getDescription()', () => { + it('should return a description if present', () => { + expect(Oas.init(petstore).operation('/pet/findByTags', 'get').getDescription()).toBe( + 'Muliple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.' + ); + }); + + it('should return nothing if not present', () => { + expect(Oas.init(referenceSpec).operation('/2.0/users/{username}', 'get').getDescription()).toBeUndefined(); + }); +}); + describe('#getContentType()', () => { it('should return the content type on an operation', () => { expect(Oas.init(petstore).operation('/pet', 'post').getContentType()).toBe('application/json'); diff --git a/src/operation.ts b/src/operation.ts index 9f365e33b..72fa1f862 100644 --- a/src/operation.ts +++ b/src/operation.ts @@ -75,6 +75,14 @@ export default class Operation { this.callbackExamples = undefined; } + getSummary(): string { + return this.schema?.summary ? this.schema.summary.trim() : undefined; + } + + getDescription(): string { + return this.schema?.description ? this.schema.description.trim() : undefined; + } + getContentType(): string { if (this.contentType) { return this.contentType;