Skip to content

Commit 8997714

Browse files
Merge pull request #32 from cap-js/addDefaults
Adding default title and version
2 parents b5ff469 + b8c0fe4 commit 8997714

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
66

77
## Version 1.0.3 - TBD
88

9+
### Added
10+
11+
- Added defaults for `@AsyncAPI.SchemaVersion` and `@AsyncAPI.Title`.
12+
913
### Changed
1014

1115
- Replaced `console.warn` statements with `cds.debug` logs for warning messages.

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)