Skip to content

Commit a2edb9f

Browse files
committed
Fix asyncapi#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 a2edb9f

File tree

7 files changed

+46
-2
lines changed

7 files changed

+46
-2
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/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

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

3846
host(): string {
3947
const url = new URL(this.url());

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class Server extends CoreModel<v3.ServerObject, { id: string }> implement
2626
id(): string {
2727
return this._meta.id;
2828
}
29-
29+
3030
url(): string {
3131
let host = this.host();
3232
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/test/models/v2/server.spec.ts

+16
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,21 @@ 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+
it('should return false if summary is missing', function () {
58+
expect(emptyItem.hasSummary()).toEqual(false);
59+
});
60+
});
61+
4662
describe('.hasProtocolVersion()', function () {
4763
it('should return true if protocolVersion is not missing', function () {
4864
expect(docItem.hasProtocolVersion()).toBeTruthy();

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

+16
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,21 @@ 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+
it('should return false if summary is missing', function () {
60+
expect(emptyItem.hasSummary()).toEqual(false);
61+
});
62+
});
63+
4864
describe('.host()', function () {
4965
it('should return value', function () {
5066
expect(docItem.host()).toEqual(doc.production.host);

0 commit comments

Comments
 (0)