Skip to content

Commit 711e6e0

Browse files
committed
Fix #1076: Added server.summary() hasSummary() functions
- summary(): Returns the server summary string or undefined - hasSummary(): Returns boolean indicating if summary exists - Added unit tests for the respective functions - Tested the code by building, ensuring changes in esm, cjs
1 parent ac03bb3 commit 711e6e0

File tree

10 files changed

+41
-4
lines changed

10 files changed

+41
-4
lines changed

package-lock.json

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/parser/jest.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const config: Config.InitialOptions = {
1818

1919
// Test spec file resolution pattern
2020
// Matches parent folder `__tests__` and filename
21-
// should contain `test` or `spec`.
21+
// should contain `btest` or `spec`.
2222
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$',
2323
// Module file extensions for importing
2424
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],

packages/parser/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"eslint-plugin-github": "^4.3.7",
8181
"eslint-plugin-security": "^1.5.0",
8282
"eslint-plugin-sonarjs": "^0.15.0",
83-
"jest": "^29.0.2",
83+
"jest": "^29.7.0",
8484
"markdown-toc": "^1.2.0",
8585
"path-browserify": "^1.0.1",
8686
"puppeteer": "^17.1.1",

packages/parser/src/models/server.ts

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import type { SecurityRequirementsInterface } from './security-requirements';
99
export interface ServerInterface extends BaseModel, DescriptionMixinInterface, BindingsMixinInterface, ExtensionsMixinInterface, TagsMixinInterface {
1010
id(): string
1111
url(): string;
12+
summary(): string | undefined;
13+
hasSummary(): boolean;
1214
host(): string;
1315
hasPathname(): boolean;
1416
pathname(): string | undefined;

packages/parser/src/models/v2/server.ts

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ export class Server extends BaseModel<v2.ServerObject, { id: string }> implement
3434
url(): string {
3535
return this._json.url;
3636
}
37+
summary(): string | undefined {
38+
return this._json.summary;
39+
}
40+
41+
hasSummary(): boolean {
42+
return !!this._json.summary;
43+
}
3744

3845
host(): string {
3946
const url = new URL(this.url());

packages/parser/src/models/v3/server.ts

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export class Server extends CoreModel<v3.ServerObject, { id: string }> implement
2626
id(): string {
2727
return this._meta.id;
2828
}
29-
3029
url(): string {
3130
let host = this.host();
3231
if (!host.endsWith('/')) {

packages/parser/src/spec-types/v2.ts

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export type ServersObject = Record<string, ServerObject>;
4141
export interface ServerObject extends SpecificationExtensions {
4242
url: string;
4343
protocol: string;
44+
summary?: string;
4445
protocolVersion?: string;
4546
description?: string;
4647
variables?: Record<string, ServerVariableObject>;

packages/parser/src/spec-types/v3.ts

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export type ServersObject = Record<string, ServerObject | ReferenceObject>;
4242
export interface ServerObject extends SpecificationExtensions {
4343
host: string;
4444
protocol: string;
45+
summary?: string;
4546
pathname?: string;
4647
protocolVersion?: string;
4748
description?: string;

packages/parser/test/models/v2/server.spec.ts

+13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { SecurityRequirement } from '../../../src/models/v2/security-requirement
1717
const doc = {
1818
development: {
1919
protocol: 'mqtt',
20+
summary: 'mqtt development server is summary',
2021
protocolVersion: '1.0.0',
2122
url: 'development.gigantic-server.com',
2223
variables: {
@@ -43,6 +44,18 @@ describe('Server Model', function () {
4344
});
4445
});
4546

47+
describe('.summary()', function () {
48+
it('should return value', function () {
49+
expect(docItem.summary()).toEqual(doc.development.summary);
50+
});
51+
});
52+
53+
describe('.hasSummary()', function () {
54+
it('should return true if summary is present', function () {
55+
expect(docItem.hasSummary()).toEqual(true);
56+
});
57+
});
58+
4659
describe('.hasProtocolVersion()', function () {
4760
it('should return true if protocolVersion is not missing', function () {
4861
expect(docItem.hasProtocolVersion()).toBeTruthy();

packages/parser/test/models/v3/server.spec.ts

+13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { xParserObjectUniqueId } from '../../../src/constants';
1818
const doc = {
1919
production: {
2020
host: 'rabbitmq.in.mycompany.com:5672',
21+
summary: 'rabbitmq production server is summary',
2122
pathname: '/production',
2223
protocol: 'amqp',
2324
protocolVersion: '1.0.0',
@@ -45,6 +46,18 @@ describe('Server Model', function () {
4546
});
4647
});
4748

49+
describe('.summary()', function () {
50+
it('should return value', function () {
51+
expect(docItem.summary()).toEqual(doc.production.summary);
52+
});
53+
});
54+
55+
describe('.hasSummary()', function () {
56+
it('should return true if summary is present', function () {
57+
expect(docItem.hasSummary()).toEqual(true);
58+
});
59+
});
60+
4861
describe('.host()', function () {
4962
it('should return value', function () {
5063
expect(docItem.host()).toEqual(doc.production.host);

0 commit comments

Comments
 (0)