Skip to content

Commit 1fc8f07

Browse files
authored
Merge pull request #27 from cap-js/main
Release 1.0.2
2 parents bc78ac2 + 37f9c50 commit 1fc8f07

File tree

7 files changed

+29
-7
lines changed

7 files changed

+29
-7
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ 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 - 15.07.2024
8+
9+
### Changed
10+
11+
- Changed default namespace from `sap.app` to `customer.<package-name>`
12+
- Changed default namespace regex making it compatible with ORD.
13+
714
## Version 1.0.1 - 14.05.2024
815

916
### Changed

CONTRIBUTING.md

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

33
## Code of Conduct
44

5-
All members of the project community must abide by the [Contributor Covenant, version 2.1](CODE_OF_CONDUCT.md).
5+
All members of the project community must abide by the [SAP Open Source Code of Conduct](https://github.com/cap-js/.github/blob/main/CODE_OF_CONDUCT.md).
66
Only by respecting each other we can develop a productive, collaborative community.
77
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting [a project maintainer](.reuse/dep5).
88

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(/^[@]/, "").replace(/[@/]/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).',

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cap-js/asyncapi",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "CAP tool for AsyncAPI",
55
"repository": {
66
"type": "git",
@@ -26,7 +26,7 @@
2626
"lint": "npx eslint ."
2727
},
2828
"peerDependencies": {
29-
"@sap/cds": ">=7.3"
29+
"@sap/cds": ">=7.6"
3030
},
3131
"devDependencies": {
3232
"jest": "^29",

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)