Skip to content

Commit 2e8631b

Browse files
Merge branch 'main' into release
2 parents 1fc8f07 + 76c8115 commit 2e8631b

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55
The format is based on [Keep a Changelog](http://keepachangelog.com/).
66

7+
## Version 1.0.3 - 12-03-2025
8+
9+
### Added
10+
11+
- Added defaults for `@AsyncAPI.SchemaVersion` and `@AsyncAPI.Title`.
12+
13+
### Changed
14+
15+
- Replaced `console.warn` statements with `cds.debug` logs for warning messages.
16+
717
## Version 1.0.2 - 15.07.2024
818

919
### Changed

lib/compile/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const getChannels = require('./channels');
55
const cds = require('@sap/cds/lib');
66
const { join } = require('path');
77
const messages = require("./message");
8+
const DEBUG = cds.debug('cds:asyncapi');
89
const presetMapping = {
910
'event_spec_version': 'x-sap-event-spec-version',
1011
'event_source': 'x-sap-event-source',
@@ -29,7 +30,7 @@ module.exports = function processor(csn, options = {}) {
2930
const ordNamespace = _getNamespace(cds.env.ord.namespace);
3031
const asyncapiNamespace = _getNamespace(envConf.application_namespace);
3132
if (ordNamespace !== asyncapiNamespace) {
32-
console.warn(messages.NAMESPACE_MISMATCH)
33+
DEBUG?.(messages.NAMESPACE_MISMATCH)
3334
}
3435
}
3536

@@ -157,7 +158,8 @@ function getInfoObject(serviceCsn, mergedPresetObject = undefined) {
157158
}
158159

159160
if (!serviceCsn['@AsyncAPI.SchemaVersion'] || !serviceCsn['@AsyncAPI.Title']) {
160-
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.`;
161163
}
162164

163165
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.',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cap-js/asyncapi",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "CAP tool for AsyncAPI",
55
"repository": {
66
"type": "git",

test/lib/compile/asyncapiMetadata.test.js

Lines changed: 12 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 () => {
@@ -94,4 +96,12 @@ describe('asyncapi export: presets and annotations', () => {
9496
const generatedAsyncAPI = toAsyncAPI(csn);
9597
expect(generatedAsyncAPI).toHaveProperty('x-sap-application-namespace','customer.cap-js-asyncapi')
9698
});
99+
test('Console warnings and errors are not used', async () => {
100+
const inputCDS = await read(join(baseInputPath, 'valid', 'presets.cds'));
101+
const csn = cds.compile.to.csn(inputCDS);
102+
const generatedAsyncAPI = toAsyncAPI(csn);
103+
104+
expect(generatedAsyncAPI).not.toHaveProperty('console.warn');
105+
expect(generatedAsyncAPI).not.toHaveProperty('console.error');
106+
});
97107
});

0 commit comments

Comments
 (0)