Skip to content

Commit e4a25cd

Browse files
authored
[CDSADAPTERS-2186] Fixed openapi filename issue when there's only one service in the CDL source (#59)
* Fixed openapi filename issue when there's only one service in the CDL source file * Update test cases to handle generator function in openAPI * Add changelog entry
1 parent 68ced01 commit e4a25cd

File tree

3 files changed

+170
-98
lines changed

3 files changed

+170
-98
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ 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+
8+
### Fixed
9+
10+
- Fixed the filename issue: when there is only one service in the CDL source, the OpenAPI document is now generated with the filename corresponding to the service name rather than the CDL source filename.
11+
712
## Version 1.1.1 - 13.12.2024
813

914
### Fixed
@@ -38,6 +43,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
3843

3944
- OpenAPI documents can now have `externalDocs` object provided through `@OpenAPI.externalDocs` annotation in the service level of CDS.
4045
- OpenAPI documents now throws warning if `securitySchemas` are not found.
46+
- Introduced --openapi:config-file option to incorporate all the options for cds compile command in a JSON configuration file, inline options take precedence over those defined in the configuration file.
4147

4248
## Version 1.0.6 - 23.09.2024
4349

@@ -90,4 +96,3 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
9096
### Added
9197

9298
- Initial release
93-
- Introduced --openapi:config-file option to incorporate all the options for cds compile command in a JSON configuration file, inline options take precedence over those defined in the configuration file.

lib/compile/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ module.exports = function processor(csn, options = {}) {
2020
openApiDocs = _getOpenApi(csdl, openApiOptions);
2121
}
2222

23-
if (Object.keys(openApiDocs).length == 1) {
24-
return openApiDocs[Object.keys(openApiDocs)[0]];
25-
}
26-
2723
return _iterate(openApiDocs);
2824
}
2925

@@ -50,6 +46,12 @@ function* _iterate(openApiDocs) {
5046
}
5147
}
5248

49+
function nameParts(qualifiedName) {
50+
const pos = qualifiedName.lastIndexOf('.');
51+
console.assert(pos > 0, 'Invalid qualified name ' + qualifiedName);
52+
return qualifiedName.substring(0, pos);
53+
}
54+
5355
function _getOpenApi(csdl, options, serviceName = "") {
5456
const openApiDocs = {};
5557
let filename;
@@ -68,6 +70,10 @@ function _getOpenApi(csdl, options, serviceName = "") {
6870

6971
const openapi = csdl2openapi.csdl2openapi(csdl, sOptions);
7072

73+
if(!serviceName) {
74+
serviceName= nameParts(csdl.$EntityContainer);
75+
}
76+
7177
if (protocols.length > 1) {
7278
filename = serviceName + "." + protocol;
7379
} else {

0 commit comments

Comments
 (0)