Skip to content

Commit 45859d6

Browse files
feat: add support for title and summary for the v3 spec (#1191)
1 parent 009aedc commit 45859d6

5 files changed

Lines changed: 82 additions & 0 deletions

File tree

.changeset/pretty-owls-draw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@asyncapi/parser": patch
3+
---
4+
5+
feat: add support for title and summary for the v3 spec

packages/parser/src/spec-types/v3.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export interface ServerObject extends SpecificationExtensions {
4444
protocol: string;
4545
pathname?: string;
4646
protocolVersion?: string;
47+
title?: string;
48+
summary?: string;
4749
description?: string;
4850
variables?: Record<string, ServerVariableObject | ReferenceObject>;
4951
security?: Array<SecuritySchemeObject | ReferenceObject>;

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,26 @@ describe('AsyncAPIDocument model', function() {
245245
const d = new AsyncAPIDocument(doc);
246246
expect(d.allServers()).toBeInstanceOf(Servers);
247247
});
248+
249+
it('should expose server title and summary', function() {
250+
const doc = serializeInput<v3.AsyncAPIObject>({
251+
servers: {
252+
production: {
253+
host: 'example.com',
254+
protocol: 'https',
255+
title: 'Production Server',
256+
summary: 'Production environment server',
257+
},
258+
},
259+
});
260+
const d = new AsyncAPIDocument(doc);
261+
const server = d.allServers().all()[0];
262+
expect(server.id()).toEqual('production');
263+
expect(server.hasTitle()).toEqual(true);
264+
expect(server.title()).toEqual('Production Server');
265+
expect(server.hasSummary()).toEqual(true);
266+
expect(server.summary()).toEqual('Production environment server');
267+
});
248268
});
249269

250270
describe('.allChannels()', function() {

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,36 @@ const docItem = new Server(doc.production, { asyncapi: {} as any, pointer: '', i
3333
const emptyItem = new Server(serializeInput<v3.ServerObject>({}), { asyncapi: {} as any, pointer: '', id: '' });
3434

3535
describe('Server Model', function () {
36+
describe('.title() and .summary()', function () {
37+
it('should return title and summary from ServerObject', function () {
38+
const doc = serializeInput<v3.ServerObject>({
39+
host: 'example.com',
40+
protocol: 'https',
41+
title: 'Production Server',
42+
summary: 'Production environment server',
43+
});
44+
const d = new Server(doc, { asyncapi: {} as any, pointer: '/servers/production', id: 'production' });
45+
expect(d.hasTitle()).toEqual(true);
46+
expect(d.title()).toEqual('Production Server');
47+
expect(d.hasSummary()).toEqual(true);
48+
expect(d.summary()).toEqual('Production environment server');
49+
expect(d.json().title).toEqual('Production Server');
50+
expect(d.json().summary).toEqual('Production environment server');
51+
});
52+
53+
it('should return false and undefined when title and summary are absent', function () {
54+
const doc = serializeInput<v3.ServerObject>({
55+
host: 'example.com',
56+
protocol: 'https',
57+
});
58+
const d = new Server(doc, { asyncapi: {} as any, pointer: '/servers/production', id: 'production' });
59+
expect(d.hasTitle()).toEqual(false);
60+
expect(d.title()).toBeUndefined();
61+
expect(d.hasSummary()).toEqual(false);
62+
expect(d.summary()).toBeUndefined();
63+
});
64+
});
65+
3666
describe('.id()', function () {
3767
it('should return name if present', function () {
3868
expect(docItem.id()).toEqual('production');

packages/parser/test/parse.spec.ts

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

440+
it('should return server title and summary from allServers()', 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+
servers:
447+
production:
448+
host: example.com
449+
protocol: https
450+
title: Production Server
451+
summary: Production environment server
452+
channels: {}
453+
`);
454+
455+
expect(document).toBeDefined();
456+
expect(filterLastVersionDiagnostics(diagnostics).length === 0).toEqual(true);
457+
const server = document!.allServers().all()[0];
458+
expect(server.id()).toEqual('production');
459+
expect(server.hasTitle()).toEqual(true);
460+
expect(server.title()).toEqual('Production Server');
461+
expect(server.hasSummary()).toEqual(true);
462+
expect(server.summary()).toEqual('Production environment server');
463+
});
464+
440465
it('should not parse invalid v3 YAML document and give error in line 153 (#936)', async function () {
441466
const documentRaw = `asyncapi: 3.0.0
442467
info:

0 commit comments

Comments
 (0)