Skip to content

Commit c95ab2a

Browse files
adding default title and version
1 parent b5ff469 commit c95ab2a

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

lib/compile/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ function getInfoObject(serviceCsn, mergedPresetObject = undefined) {
158158
}
159159

160160
if (!serviceCsn['@AsyncAPI.SchemaVersion'] || !serviceCsn['@AsyncAPI.Title']) {
161-
throw new Error(messages.TITLE_VERSION_ANNOTATIONS);
161+
serviceCsn['@AsyncAPI.SchemaVersion'] = '1.0.0';
162+
serviceCsn['@AsyncAPI.Title'] = `Use @title: '...' on your CDS service to provide a meaningful title.`;
162163
}
163164

164165
isVersionValid(serviceCsn['@AsyncAPI.SchemaVersion']);

lib/compile/message.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const errorMessages = {
55
NAMESPACE_MISMATCH: 'ORD and AsyncAPI namespaces should be same.',
66
TITLE_VERSION_MERGED: 'Preset for Title and Version info needs to be added when merged flag is used.',
77
NO_EVENTS: 'No events found in the service.',
8-
TITLE_VERSION_ANNOTATIONS: 'Title and Version info annotations needs to be added to the service(s).',
98
UNSUPPORTED_VERSION: 'The version value provided is unsupported.',
109
NO_SERVICES: 'There are no service definitions found in the given model(s).',
1110
MERGED_FLAG: 'Merged flag cannot be used with single service definition.',

test/lib/compile/asyncapiMetadata.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,12 @@ describe('asyncapi export: presets and annotations', () => {
8181
expect(() => toAsyncAPI(csn)).toThrowError("There are no service definitions found in the given model(s).");
8282
});
8383

84-
test('Negative test for version', async () => {
84+
test('Check for default title and version if not provided in the input', async () => {
8585
const inputCDS = await read(join(baseInputPath, 'invalid', 'noTitle.cds'));
8686
const csn = cds.compile.to.csn(inputCDS);
87-
expect(() => toAsyncAPI(csn)).toThrowError("Title and Version info annotations needs to be added to the service(s).");
87+
const generatedAsyncAPI = toAsyncAPI(csn);
88+
expect(generatedAsyncAPI).toHaveProperty('info.title', `Use @title: '...' on your CDS service to provide a meaningful title.`);
89+
expect(generatedAsyncAPI).toHaveProperty('info.version', '1.0.0');
8890
});
8991

9092
test('Test for application namespace', async () => {

0 commit comments

Comments
 (0)