Skip to content
Draft
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
.npm-cache
.vscode
.DS_Store
/docs
Expand Down
4 changes: 2 additions & 2 deletions packages/parser/src/models/channel.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { BaseModel } from './base';
import type { ChannelParametersInterface } from './channel-parameters';
import type { MessagesInterface } from './messages';
import type { BindingsMixinInterface, DescriptionMixinInterface, ExtensionsMixinInterface } from './mixins';
import type { BindingsMixinInterface, DescriptionMixinInterface, ExtensionsMixinInterface, TitleMixinInterface } from './mixins';
import type { OperationsInterface } from './operations';
import type { ServersInterface } from './servers';

export interface ChannelInterface extends BaseModel, BindingsMixinInterface, DescriptionMixinInterface, ExtensionsMixinInterface {
export interface ChannelInterface extends BaseModel, BindingsMixinInterface, DescriptionMixinInterface, ExtensionsMixinInterface, TitleMixinInterface {
id(): string;
address(): string | null | undefined;
servers(): ServersInterface;
Expand Down
8 changes: 8 additions & 0 deletions packages/parser/src/models/v2/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ export class Channel extends BaseModel<v2.ChannelObject, { id: string, address:
return description(this);
}

hasTitle(): boolean {
return false;
}

title(): string | undefined {
return undefined;
}

servers(): ServersInterface {
const servers: ServerInterface[] = [];
const allowedServers: string[] = this._json.servers || [];
Expand Down
3 changes: 2 additions & 1 deletion packages/parser/test/models/v2/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,5 @@ export function assertTags(model: Constructor<TagsMixinInterface>) {
expect(d3.tags().length).toEqual(0);
});
});
}
}

16 changes: 16 additions & 0 deletions packages/parser/test/models/v3/asyncapi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,22 @@ describe('AsyncAPIDocument model', function() {
const d = new AsyncAPIDocument(doc);
expect(d.allChannels()).toBeInstanceOf(Channels);
});

it('should expose channel title and hasTitle (#1067)', function() {
const doc = serializeInput<v3.AsyncAPIObject>({
channels: {
'user/signup': {
address: 'user/signup',
title: 'User signup channel',
},
},
});
const d = new AsyncAPIDocument(doc);
const channel = d.allChannels().all()[0];
expect(channel.id()).toEqual('user/signup');
expect(channel.hasTitle()).toEqual(true);
expect(channel.title()).toEqual('User signup channel');
});
});

describe('.allOperations()', function() {
Expand Down
20 changes: 20 additions & 0 deletions packages/parser/test/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,26 @@ describe('parse()', function () {
expect(filterLastVersionDiagnostics(diagnostics).length === 0).toEqual(true);
});

it('should return channel title from allChannels() (#1067)', async function () {
const { document, diagnostics } = await parser.parse(`
asyncapi: 3.0.0
info:
title: API
version: 1.0.0
channels:
user/signup:
address: user/signup
title: User signup channel
`);

expect(document).toBeDefined();
expect(filterLastVersionDiagnostics(diagnostics).length === 0).toEqual(true);
const channel = document!.allChannels().all()[0];
expect(channel.id()).toEqual('user/signup');
expect(channel.hasTitle()).toEqual(true);
expect(channel.title()).toEqual('User signup channel');
});

it('should not parse invalid v3 YAML document and give error in line 153 (#936)', async function () {
const documentRaw = `asyncapi: 3.0.0
info:
Expand Down
Loading