Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): added server.title() and hasTitle() functions #1081

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/multi-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"test": "npm run test:unit",
"test:unit": "cross-env CI=true jest --coverage",
"lint": "eslint --max-warnings 0 --config ../../.eslintrc --ignore-path ../../.eslintignore .",
"lint:fix": "eslint --max-warnings 0 --config .../../eslintrc --ignore-path ../../.eslintignore . --fix",
"lint:fix": "eslint --max-warnings 0 --config ../../.eslintrc --ignore-path ../../.eslintignore . --fix",
"generate:readme:toc": "markdown-toc -i \"../../README.md\"",
"generate:assets": "npm run generate:readme:toc",
"bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION",
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 @@ -12,6 +12,8 @@ export interface ServerInterface extends BaseModel, DescriptionMixinInterface, B
host(): string;
hasPathname(): boolean;
pathname(): string | undefined;
title(): string | undefined;
hasTitle(): boolean;
protocol(): string;
protocolVersion(): string | undefined;
hasProtocolVersion(): boolean;
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 @@ -49,6 +49,14 @@ export class Server extends BaseModel<v2.ServerObject, { id: string }> implement
return url.pathname;
}

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

hasTitle(): boolean {
return !!this._json.title;
}

protocol(): string {
return this._json.protocol;
}
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;
title?: string;
protocolVersion?: string;
description?: string;
variables?: Record<string, ServerVariableObject>;
Expand Down
17 changes: 17 additions & 0 deletions packages/parser/test/models/v2/server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { SecurityRequirement } from '../../../src/models/v2/security-requirement

const doc = {
development: {
title: 'mqtt development server',
protocol: 'mqtt',
protocolVersion: '1.0.0',
url: 'development.gigantic-server.com',
Expand All @@ -37,6 +38,22 @@ describe('Server Model', function () {
});
});

describe('.title()', function () {
it('should return title', function () {
expect(docItem.title()).toMatch(doc.development.title);
});
});

describe('.hasTitle()', function () {
it('should return true if title is present', function () {
expect(docItem.hasTitle()).toBeTruthy();
});

it('should return false if title is missing', function () {
expect(emptyItem.hasTitle()).toBeFalsy();
});
});

describe('protocol()', function () {
it('should return protocol ', function () {
expect(docItem.protocol()).toMatch(doc.development.protocol);
Expand Down
17 changes: 17 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',
title: 'rabbitmq production server',
pathname: '/production',
protocol: 'amqp',
protocolVersion: '1.0.0',
Expand Down Expand Up @@ -51,6 +52,22 @@ describe('Server Model', function () {
});
});

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

describe('.hasTitle()', function () {
it('should return true if title is present', function () {
expect(docItem.hasTitle()).toBeTruthy();
});

it('should return false if title is missing', function () {
expect(emptyItem.hasTitle()).toBeFalsy();
});
});

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