Skip to content

Commit 92c1b72

Browse files
committed
Fix #1075: Added server.title() hasTitle() functions
- title(): returns the server title string or undefined - hasTitle: returns boolean indicating if title exists - added the unit tests for the respective functions - tested the code by building, ensuring changes in esm, cjs
1 parent ac03bb3 commit 92c1b72

File tree

6 files changed

+46
-1
lines changed

6 files changed

+46
-1
lines changed

packages/multi-parser/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"test": "npm run test:unit",
3333
"test:unit": "cross-env CI=true jest --coverage",
3434
"lint": "eslint --max-warnings 0 --config ../../.eslintrc --ignore-path ../../.eslintignore .",
35-
"lint:fix": "eslint --max-warnings 0 --config .../../eslintrc --ignore-path ../../.eslintignore . --fix",
35+
"lint:fix": "eslint --max-warnings 0 --config ../../.eslintrc --ignore-path ../../.eslintignore . --fix",
3636
"generate:readme:toc": "markdown-toc -i \"../../README.md\"",
3737
"generate:assets": "npm run generate:readme:toc",
3838
"bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION",

packages/parser/src/models/server.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export interface ServerInterface extends BaseModel, DescriptionMixinInterface, B
1212
host(): string;
1313
hasPathname(): boolean;
1414
pathname(): string | undefined;
15+
title(): string | undefined;
16+
hasTitle(): boolean;
1517
protocol(): string;
1618
protocolVersion(): string | undefined;
1719
hasProtocolVersion(): boolean;

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

+8
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ export class Server extends BaseModel<v2.ServerObject, { id: string }> implement
4949
return url.pathname;
5050
}
5151

52+
title(): string | undefined {
53+
return this._json.title;
54+
}
55+
56+
hasTitle(): boolean {
57+
return !!this._json.title;
58+
}
59+
5260
protocol(): string {
5361
return this._json.protocol;
5462
}

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+
title?: string;
4445
protocolVersion?: string;
4546
description?: string;
4647
variables?: Record<string, ServerVariableObject>;

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

+17
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { SecurityRequirement } from '../../../src/models/v2/security-requirement
1616

1717
const doc = {
1818
development: {
19+
title: 'mqtt development server',
1920
protocol: 'mqtt',
2021
protocolVersion: '1.0.0',
2122
url: 'development.gigantic-server.com',
@@ -37,6 +38,22 @@ describe('Server Model', function () {
3738
});
3839
});
3940

41+
describe('.title()', function () {
42+
it('should return title', function () {
43+
expect(docItem.title()).toMatch(doc.development.title);
44+
});
45+
});
46+
47+
describe('.hasTitle()', function () {
48+
it('should return true if title is present', function () {
49+
expect(docItem.hasTitle()).toBeTruthy();
50+
});
51+
52+
it('should return false if title is missing', function () {
53+
expect(emptyItem.hasTitle()).toBeFalsy();
54+
});
55+
});
56+
4057
describe('protocol()', function () {
4158
it('should return protocol ', function () {
4259
expect(docItem.protocol()).toMatch(doc.development.protocol);

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

+17
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+
title: 'rabbitmq production server',
2122
pathname: '/production',
2223
protocol: 'amqp',
2324
protocolVersion: '1.0.0',
@@ -51,6 +52,22 @@ describe('Server Model', function () {
5152
});
5253
});
5354

55+
describe('.title()', function () {
56+
it('should return title', function () {
57+
expect(docItem.title()).toEqual(doc.production.title);
58+
});
59+
});
60+
61+
describe('.hasTitle()', function () {
62+
it('should return true if title is present', function () {
63+
expect(docItem.hasTitle()).toBeTruthy();
64+
});
65+
66+
it('should return false if title is missing', function () {
67+
expect(emptyItem.hasTitle()).toBeFalsy();
68+
});
69+
});
70+
5471
describe('protocol()', function () {
5572
it('should return protocol ', function () {
5673
expect(docItem.protocol()).toEqual(doc.production.protocol);

0 commit comments

Comments
 (0)