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.summary() and hasSummary() functions #1080

Open
wants to merge 2 commits 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
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/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 @@ -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;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should test the opposite as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like for a case where the summary isn't present?

});
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);
});
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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