Skip to content

Commit

Permalink
feat: adding accessors for operation summary and description (#562)
Browse files Browse the repository at this point in the history
* feat: adding accessors for operation summary and description

* feat: trimming summary and description before returning it
  • Loading branch information
erunion authored Dec 17, 2021
1 parent 1fb7c2e commit 1dd6a9f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
22 changes: 22 additions & 0 deletions __tests__/operation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
8 changes: 8 additions & 0 deletions src/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1dd6a9f

Please sign in to comment.