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 Jan 31, 2025
1 parent ac03bb3 commit 711e6e0
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 4 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: 1 addition & 1 deletion packages/parser/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const config: Config.InitialOptions = {

// Test spec file resolution pattern
// Matches parent folder `__tests__` and filename
// should contain `test` or `spec`.
// should contain `btest` or `spec`.
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$',
// Module file extensions for importing
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"eslint-plugin-github": "^4.3.7",
"eslint-plugin-security": "^1.5.0",
"eslint-plugin-sonarjs": "^0.15.0",
"jest": "^29.0.2",
"jest": "^29.7.0",
"markdown-toc": "^1.2.0",
"path-browserify": "^1.0.1",
"puppeteer": "^17.1.1",
Expand Down
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
7 changes: 7 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,13 @@ 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
1 change: 0 additions & 1 deletion packages/parser/src/models/v3/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ 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
1 change: 1 addition & 0 deletions packages/parser/src/spec-types/v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type ServersObject = Record<string, ServerObject | ReferenceObject>;
export interface ServerObject extends SpecificationExtensions {
host: string;
protocol: string;
summary?: string;
pathname?: string;
protocolVersion?: string;
description?: string;
Expand Down
13 changes: 13 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,18 @@ 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);
});
});

describe('.hasProtocolVersion()', function () {
it('should return true if protocolVersion is not missing', function () {
expect(docItem.hasProtocolVersion()).toBeTruthy();
Expand Down
13 changes: 13 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,18 @@ 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);
});
});

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

0 comments on commit 711e6e0

Please sign in to comment.