Skip to content

Commit d090301

Browse files
feat: enable title configuration in the v3 spec
1 parent 02f8bb1 commit d090301

4 files changed

Lines changed: 39 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
2+
.npm-cache
23
.vscode
34
.DS_Store
45
/docs

packages/parser/src/models/channel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { BaseModel } from './base';
22
import type { ChannelParametersInterface } from './channel-parameters';
33
import type { MessagesInterface } from './messages';
4-
import type { BindingsMixinInterface, DescriptionMixinInterface, ExtensionsMixinInterface } from './mixins';
4+
import type { BindingsMixinInterface, DescriptionMixinInterface, ExtensionsMixinInterface, TitleMixinInterface } from './mixins';
55
import type { OperationsInterface } from './operations';
66
import type { ServersInterface } from './servers';
77

8-
export interface ChannelInterface extends BaseModel, BindingsMixinInterface, DescriptionMixinInterface, ExtensionsMixinInterface {
8+
export interface ChannelInterface extends BaseModel, BindingsMixinInterface, DescriptionMixinInterface, ExtensionsMixinInterface, TitleMixinInterface {
99
id(): string;
1010
address(): string | null | undefined;
1111
servers(): ServersInterface;

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,22 @@ describe('AsyncAPIDocument model', function() {
269269
const d = new AsyncAPIDocument(doc);
270270
expect(d.allChannels()).toBeInstanceOf(Channels);
271271
});
272+
273+
it('should expose channel title and hasTitle (#1067)', function() {
274+
const doc = serializeInput<v3.AsyncAPIObject>({
275+
channels: {
276+
'user/signup': {
277+
address: 'user/signup',
278+
title: 'User signup channel',
279+
},
280+
},
281+
});
282+
const d = new AsyncAPIDocument(doc);
283+
const channel = d.allChannels().all()[0];
284+
expect(channel.id()).toEqual('user/signup');
285+
expect(channel.hasTitle()).toEqual(true);
286+
expect(channel.title()).toEqual('User signup channel');
287+
});
272288
});
273289

274290
describe('.allOperations()', function() {

packages/parser/test/parse.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,26 @@ describe('parse()', function () {
437437
expect(filterLastVersionDiagnostics(diagnostics).length === 0).toEqual(true);
438438
});
439439

440+
it('should return channel title from allChannels() (#1067)', async function () {
441+
const { document, diagnostics } = await parser.parse(`
442+
asyncapi: 3.0.0
443+
info:
444+
title: API
445+
version: 1.0.0
446+
channels:
447+
user/signup:
448+
address: user/signup
449+
title: User signup channel
450+
`);
451+
452+
expect(document).toBeDefined();
453+
expect(filterLastVersionDiagnostics(diagnostics).length === 0).toEqual(true);
454+
const channel = document!.allChannels().all()[0];
455+
expect(channel.id()).toEqual('user/signup');
456+
expect(channel.hasTitle()).toEqual(true);
457+
expect(channel.title()).toEqual('User signup channel');
458+
});
459+
440460
it('should not parse invalid v3 YAML document and give error in line 153 (#936)', async function () {
441461
const documentRaw = `asyncapi: 3.0.0
442462
info:

0 commit comments

Comments
 (0)