Skip to content

Commit a2cd748

Browse files
authored
Merge pull request #25 from cap-js/default-namespace
change default namespace
2 parents 61e2602 + 3795be2 commit a2cd748

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ 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.2
8+
9+
### Changed
10+
11+
- Changed default namespace from `sap.app` to `customer.<package-name>`
12+
713
## Version 1.0.1 - 14.05.2024
814

915
### Changed

lib/compile/config.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/compile/index.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const getMessageTraits = require('./components/messageTraits');
33
const { definitionsToMessages, nestedAnnotation } = require('./components/messages');
44
const getChannels = require('./channels');
55
const cds = require('@sap/cds/lib');
6+
const { join } = require('path');
67
const messages = require("./message");
7-
const defaultConfig = require("./config.json")
88
const presetMapping = {
99
'event_spec_version': 'x-sap-event-spec-version',
1010
'event_source': 'x-sap-event-source',
@@ -19,9 +19,20 @@ module.exports = function processor(csn, options = {}) {
1919
envConf = cds.env.export.asyncapi;
2020
}
2121
if (!cds.env?.export?.asyncapi?.application_namespace) {
22-
envConf["application_namespace"] = defaultConfig.application_namespace;
22+
const packageJson = require(join(cds.root,'package.json'));
23+
const appName = packageJson.name.replace(/\s/g, "-");
24+
envConf["application_namespace"] = `customer.${appName}`
2325
console.info(messages.APPLICATION_NAMESPACE);
2426
}
27+
28+
if (cds.env.ord?.namespace) {
29+
const ordNamespace = _getNamespace(cds.env.ord.namespace);
30+
const asyncapiNamespace = _getNamespace(envConf.application_namespace);
31+
if (ordNamespace !== asyncapiNamespace) {
32+
console.warn(messages.NAMESPACE_MISMATCH)
33+
}
34+
}
35+
2536
_serviceErrorHandling(csn, options);
2637

2738
const applicationNamespace = envConf.application_namespace;
@@ -249,3 +260,7 @@ function* _iterate(services, csn, applicationNamespace, presets) {
249260
yield [generatedAsyncAPI, { file: key }];
250261
}
251262
}
263+
264+
function _getNamespace(fullNamespace) {
265+
return fullNamespace.split('.').slice(0, 2).join('.');
266+
}

lib/compile/message.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const errorMessages = {
44
APPLICATION_NAMESPACE: 'Default application namespace is used.',
5+
NAMESPACE_MISMATCH: 'ORD and AsyncAPI namespaces should be same.',
56
TITLE_VERSION_MERGED: 'Preset for Title and Version info needs to be added when merged flag is used.',
67
NO_EVENTS: 'No events found in the service.',
78
TITLE_VERSION_ANNOTATIONS: 'Title and Version info annotations needs to be added to the service(s).',

test/lib/compile/asyncapiMetadata.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,6 @@ describe('asyncapi export: presets and annotations', () => {
9292
cds.env.export.asyncapi = {};
9393
const csn = cds.compile.to.csn(inputCDS);
9494
const generatedAsyncAPI = toAsyncAPI(csn);
95-
expect(generatedAsyncAPI).toHaveProperty('x-sap-application-namespace','sap.app')
95+
expect(generatedAsyncAPI).toHaveProperty('x-sap-application-namespace','customer.@cap-js/asyncapi')
9696
});
9797
});

0 commit comments

Comments
 (0)