diff --git a/.gitignore b/.gitignore index a058191b0..0f6235abf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules +.npm-cache .vscode .DS_Store /docs diff --git a/packages/parser/src/models/channel.ts b/packages/parser/src/models/channel.ts index 57f07ff35..f2f5cd3e5 100644 --- a/packages/parser/src/models/channel.ts +++ b/packages/parser/src/models/channel.ts @@ -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; diff --git a/packages/parser/src/models/v2/channel.ts b/packages/parser/src/models/v2/channel.ts index 8e994a4f3..9fd1ecb5e 100644 --- a/packages/parser/src/models/v2/channel.ts +++ b/packages/parser/src/models/v2/channel.ts @@ -39,6 +39,14 @@ export class Channel extends BaseModel) { expect(d3.tags().length).toEqual(0); }); }); -} \ No newline at end of file +} + diff --git a/packages/parser/test/models/v3/asyncapi.spec.ts b/packages/parser/test/models/v3/asyncapi.spec.ts index 85e28e371..d9838759a 100644 --- a/packages/parser/test/models/v3/asyncapi.spec.ts +++ b/packages/parser/test/models/v3/asyncapi.spec.ts @@ -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({ + 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() { diff --git a/packages/parser/test/parse.spec.ts b/packages/parser/test/parse.spec.ts index 8717011ee..d3d1e6d6b 100644 --- a/packages/parser/test/parse.spec.ts +++ b/packages/parser/test/parse.spec.ts @@ -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: