Skip to content

Commit 5388783

Browse files
committed
change default namespace
1 parent 61e2602 commit 5388783

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines 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).',

0 commit comments

Comments
 (0)