Skip to content

Commit

Permalink
Fix asyncapi#1076: Added server.summary() hasSummary() functions
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
AlexiusTatius committed Feb 1, 2025
1 parent ac03bb3 commit a2edb9f
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/parser/src/models/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import type { SecurityRequirementsInterface } from './security-requirements';
export interface ServerInterface extends BaseModel, DescriptionMixinInterface, BindingsMixinInterface, ExtensionsMixinInterface, TagsMixinInterface {
id(): string
url(): string;
summary(): string | undefined;
hasSummary(): boolean;
host(): string;
hasPathname(): boolean;
pathname(): string | undefined;
Expand Down
8 changes: 8 additions & 0 deletions packages/parser/src/models/v2/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ export class Server extends BaseModel<v2.ServerObject, { id: string }> implement
url(): string {
return this._json.url;
}

summary(): string | undefined {
return this._json.summary;
}

hasSummary(): boolean {
return !!this._json.summary;
}

host(): string {
const url = new URL(this.url());
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/src/models/v3/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class Server extends CoreModel<v3.ServerObject, { id: string }> implement
id(): string {
return this._meta.id;
}

url(): string {
let host = this.host();
if (!host.endsWith('/')) {
Expand Down
1 change: 1 addition & 0 deletions packages/parser/src/spec-types/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type ServersObject = Record<string, ServerObject>;
export interface ServerObject extends SpecificationExtensions {
url: string;
protocol: string;
summary?: string;
protocolVersion?: string;
description?: string;
variables?: Record<string, ServerVariableObject>;
Expand Down
16 changes: 16 additions & 0 deletions packages/parser/test/models/v2/server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { SecurityRequirement } from '../../../src/models/v2/security-requirement
const doc = {
development: {
protocol: 'mqtt',
summary: 'mqtt development server is summary',
protocolVersion: '1.0.0',
url: 'development.gigantic-server.com',
variables: {
Expand All @@ -43,6 +44,21 @@ describe('Server Model', function () {
});
});

describe('.summary()', function () {
it('should return value', function () {
expect(docItem.summary()).toEqual(doc.development.summary);
});
});

describe('.hasSummary()', function () {
it('should return true if summary is present', function () {
expect(docItem.hasSummary()).toEqual(true);
});
it('should return false if summary is missing', function () {
expect(emptyItem.hasSummary()).toEqual(false);
});
});

describe('.hasProtocolVersion()', function () {
it('should return true if protocolVersion is not missing', function () {
expect(docItem.hasProtocolVersion()).toBeTruthy();
Expand Down
16 changes: 16 additions & 0 deletions packages/parser/test/models/v3/server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { xParserObjectUniqueId } from '../../../src/constants';
const doc = {
production: {
host: 'rabbitmq.in.mycompany.com:5672',
summary: 'rabbitmq production server is summary',
pathname: '/production',
protocol: 'amqp',
protocolVersion: '1.0.0',
Expand Down Expand Up @@ -45,6 +46,21 @@ describe('Server Model', function () {
});
});

describe('.summary()', function () {
it('should return value', function () {
expect(docItem.summary()).toEqual(doc.production.summary);
});
});

describe('.hasSummary()', function () {
it('should return true if summary is present', function () {
expect(docItem.hasSummary()).toEqual(true);
});
it('should return false if summary is missing', function () {
expect(emptyItem.hasSummary()).toEqual(false);
});
});

describe('.host()', function () {
it('should return value', function () {
expect(docItem.host()).toEqual(doc.production.host);
Expand Down

0 comments on commit a2edb9f

Please sign in to comment.