Skip to content

Commit

Permalink
Merge branch 'openapiExtension' of https://github.com/cap-js/openapi
Browse files Browse the repository at this point in the history
…into openapiExtension
  • Loading branch information
RoshniNaveenaS committed Nov 11, 2024
2 parents fdbbb9c + f113919 commit 124423d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).

## Version 1.0.7 - 17.10.2024

### Fixed

- Removed duplicates in `tags`.


### Fixed

- Multiple protocols for a service now renders multiple openapi documents.
Expand Down
26 changes: 14 additions & 12 deletions lib/compile/csdl2openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,18 +549,20 @@ module.exports.csdl2openapi = function (
* @return {Array} The list of tags
*/
function getTags(container) {
const tags = [];
// all entity sets and singletons
Object.keys(container).filter(name => isIdentifier(name) && container[name].$Type).forEach(child => {
const type = modelElement(container[child].$Type) || {};
const tag = {
name: type[voc.Common.Label] || child
};
const description = container[child][voc.Core.Description] || type[voc.Core.Description];
if (description) tag.description = description;
tags.push(tag);
})
return tags.sort(function (pre, next) { return pre.name.localeCompare(next.name) });
const tags = new Map();
// all entity sets and singletons
Object.keys(container)
.filter(name => isIdentifier(name) && container[name].$Type)
.forEach(child => {
const type = modelElement(container[child].$Type) || {};
const tag = {
name: type[voc.Common.Label] || child
};
const description = container[child][voc.Core.Description] || type[voc.Core.Description];
if (description) tag.description = description;
tags.set(tag.name, tag);
});
return Array.from(tags.values()).sort((pre, next) => pre.name.localeCompare(next.name));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions test/lib/compile/csdl2openapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ describe('Edge cases', function () {
};
const openapi = lib.csdl2openapi(csdl, {});
assert.deepStrictEqual(openapi, expected, 'Empty CSDL document');
})

});
it('omit unused types', function () {
const csdl = {
$Reference: { dummy: { '$Include': [{ '$Namespace': 'Org.OData.Core.V1', '$Alias': 'Core' }] } },
Expand Down
33 changes: 33 additions & 0 deletions test/lib/compile/openapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,39 @@ describe('OpenAPI export', () => {
expect(filesFound).toMatchObject(new Set(['.odata', '.rest']));
});

test('Check for tags object having any duplicate entries ', () => {
const csn = cds.compile.to.csn(`
namespace my.sample;
service CatalogService {
@title: 'Auditable Fields'
aspect Auditable {
createdAt : Timestamp;
createdBy : String;
modifiedAt : Timestamp;
modifiedBy : String;
}
entity Products : Auditable {
key ID : UUID;
name : String;
description : String;
price : Decimal(10, 2);
}
entity Orders : Auditable {
key ID : UUID;
orderDate : Date;
totalAmount : Decimal(10, 2);
product : Association to Products;
}
}
`);

const openAPI = toOpenApi(csn);
expect(openAPI).toBeDefined();
expect(openAPI.tags.length).toBe(1);
});

test('multiple services', () => {
const csn = cds.compile.to.csn(`
service A {entity E { key ID : UUID; };};
Expand Down

0 comments on commit 124423d

Please sign in to comment.