Skip to content

Commit

Permalink
Merge branch 'main' into OpenAPICompile
Browse files Browse the repository at this point in the history
  • Loading branch information
RoshniNaveenaS authored Oct 15, 2024
2 parents f97701e + 7de0ae1 commit e9cdfc4
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 35 deletions.
19 changes: 3 additions & 16 deletions lib/compile/csdl2openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,25 +277,15 @@ module.exports.csdl2openapi = function (
description = containerSchema[voc.Core.LongDescription];
}
else {
description = ('This service is located at [' + serviceRoot + '/]('
+ serviceRoot.replace(/\(/g, '%28').replace(/\)/g, '%29') + '/)');
description = "Use @Core.LongDescription: '...' on your CDS service to provide a meaningful description.";
}
description += (diagram ? getResourceDiagram(csdl, entityContainer) : '');
let title;
if (entityContainer && entityContainer[voc.Common.Label]) {
title = entityContainer[voc.Common.Label];
}
else if (entityContainer && entityContainer[voc.Core.Description]) {
title = entityContainer[voc.Core.Description];
}
else if (containerSchema && containerSchema[voc.Core.Description]) {
title = containerSchema[voc.Core.Description];
}
else if (csdl.$EntityContainer) {
title = 'Service for namespace ' + namespace;
}
else {
title = 'OData CSDL document';
title = "Use @title: '...' on your CDS service to provide a meaningful title.";
}
return {
title: title,
Expand Down Expand Up @@ -462,11 +452,8 @@ module.exports.csdl2openapi = function (
else if (containerSchema && containerSchema[voc.Core.Description]) {
shortText = containerSchema[voc.Core.Description];
}
else if (csdl.$EntityContainer) {
shortText = 'Service for namespace ' + namespace;
}
else {
shortText = 'OData CSDL document';
shortText = "Use @Core.Description: '...' on your CDS service to provide a meaningful short text.";
}
return shortText;
}
Expand Down
14 changes: 7 additions & 7 deletions test/lib/compile/csdl2openapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ describe('Edge cases', function () {
const expected = {
openapi: '3.0.2',
info: {
title: 'OData CSDL document',
title: "Use @title: '...' on your CDS service to provide a meaningful title.",
description: '',
version: ''
},
paths: {},
'x-odata-version': '4.01',
'x-sap-api-type': 'ODATAV4',
'x-sap-shortText': 'OData CSDL document',
'x-sap-shortText': "Use @Core.Description: '...' on your CDS service to provide a meaningful short text.",
components: { schemas: {} }
};
const openapi = lib.csdl2openapi(csdl, {});
Expand All @@ -120,14 +120,14 @@ describe('Edge cases', function () {
const expected = {
openapi: '3.0.2',
info: {
title: 'OData CSDL document',
title: "Use @title: '...' on your CDS service to provide a meaningful title.",
description: '',
version: ''
},
paths: {},
'x-odata-version': '4.01',
'x-sap-api-type': 'ODATAV4',
'x-sap-shortText': 'OData CSDL document',
'x-sap-shortText': "Use @Core.Description: '...' on your CDS service to provide a meaningful short text.",
components: {
schemas: {},
}
Expand Down Expand Up @@ -163,13 +163,13 @@ describe('Edge cases', function () {
const expected = {
openapi: "3.0.2",
info: {
title: 'OData CSDL document',
title: "Use @title: '...' on your CDS service to provide a meaningful title.",
description: "",
version: "",
},
"x-odata-version": "4.01",
"x-sap-api-type": "ODATAV4",
"x-sap-shortText": "OData CSDL document",
"x-sap-shortText": "Use @Core.Description: '...' on your CDS service to provide a meaningful short text.",
paths: {},
components: {
schemas: {},
Expand Down Expand Up @@ -1991,7 +1991,7 @@ see [Expand](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-prot
assert.deepStrictEqual(actual.paths['/roots/act'].post, expected.paths['/roots/act'].post, 'POST /roots/act');
assert.deepStrictEqual(actual.info.description.split("\n"),
[
"This service is located at [https://localhost/service-root/](https://localhost/service-root/)",
"Use @Core.LongDescription: '...' on your CDS service to provide a meaningful description.",
"",
"## Entity Data Model",
"![ER Diagram](https://yuml.me/diagram/class/[root{bg:lightslategray}],[root]->[other],[other{bg:lightslategray}],[act{bg:lawngreen}]->[root],[act{bg:lawngreen}]in->[root],[others%20{bg:lawngreen}]++-*>[other],[roots%20{bg:lawngreen}]++-*>[root])",
Expand Down
13 changes: 11 additions & 2 deletions test/lib/compile/data/TripPin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"$Version": "4.0",
"$Reference": {
"https://sap.github.io/odata-vocabularies/vocabularies/Common.xml": {
"$Include": [
{
"$Namespace": "com.sap.vocabularies.Common.v1"
}
]
},
"https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Core.V1.json": {
"$Include": [
{
Expand Down Expand Up @@ -445,7 +452,9 @@
"ResetDataSource": {
"$Action": "Microsoft.OData.SampleService.Models.TripPin.ResetDataSource"
},
"@Org.OData.Core.V1.Description": "TripPin service is a sample service for OData V4."
"@com.sap.vocabularies.Common.v1.Label": "TripPin service is a sample service for OData V4.",
"@Org.OData.Core.V1.Description": "TripPin service is a sample service for OData V4.",
"@Org.OData.Core.V1.LongDescription": "This service is located at [https://services.odata.org/V4/(S(cnbm44wtbc1v5bgrlek5lpcc))/TripPinServiceRW/](https://services.odata.org/V4/%28S%28cnbm44wtbc1v5bgrlek5lpcc%29%29/TripPinServiceRW/)"
},
"$Annotations": {
"Microsoft.OData.SampleService.Models.TripPin.DefaultContainer": {
Expand Down Expand Up @@ -486,4 +495,4 @@
}
},
"$EntityContainer": "Microsoft.OData.SampleService.Models.TripPin.DefaultContainer"
}
}
13 changes: 12 additions & 1 deletion test/lib/compile/data/annotations.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"$Version": "4.01",
"$Reference": {
"https://sap.github.io/odata-vocabularies/vocabularies/Common.xml": {
"$Include": [
{
"$Alias": "Common",
"$Namespace": "com.sap.vocabularies.Common.v1"
}
]
},
"https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Core.V1.json": {
"$Include": [
{
Expand Down Expand Up @@ -156,6 +164,9 @@
},
"Container": {
"$Kind": "EntityContainer",
"@Common.Label": "Service for namespace Supported.Annotations",
"@Core.Description": "Service for namespace Supported.Annotations",
"@Core.LongDescription": "This service is located at [https://localhost/service-root/](https://localhost/service-root/)",
"@Capabilities.BatchSupported": false,
"AllSet": {
"$Collection": true,
Expand Down Expand Up @@ -488,4 +499,4 @@
}
},
"$EntityContainer": "Supported.Annotations.Container"
}
}
22 changes: 21 additions & 1 deletion test/lib/compile/data/authorization.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
{
"$Version": "4.0",
"$Reference": {
"https://sap.github.io/odata-vocabularies/vocabularies/Common.xml": {
"$Include": [
{
"$Alias": "Common",
"$Namespace": "com.sap.vocabularies.Common.v1"
}
]
},
"https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Core.V1.json": {
"$Include": [
{
"$Namespace": "Org.OData.Core.V1",
"$Alias": "Core",
"@Core.DefaultNamespace": true
}
]
},
"https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Authorization.V1.json": {
"$Include": [
{
Expand All @@ -24,6 +41,9 @@
},
"Container": {
"$Kind": "EntityContainer",
"@Common.Label": "Service for namespace auth.example",
"@Core.Description": "Service for namespace auth.example",
"@Core.LongDescription": "This service is located at [https://localhost/service-root/](https://localhost/service-root/)",
"People": {
"$Collection": true,
"$Type": "self.Person"
Expand Down Expand Up @@ -122,4 +142,4 @@
}
},
"$EntityContainer": "auth.example.Container"
}
}
13 changes: 12 additions & 1 deletion test/lib/compile/data/containment.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"$Version": "4.01",
"$Reference": {
"https://sap.github.io/odata-vocabularies/vocabularies/Common.xml": {
"$Include": [
{
"$Alias": "Common",
"$Namespace": "com.sap.vocabularies.Common.v1"
}
]
},
"https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Core.V1.json": {
"$Include": [
{
Expand Down Expand Up @@ -231,6 +239,9 @@
},
"Container": {
"$Kind": "EntityContainer",
"@Common.Label": "Service for namespace Containment",
"@Core.Description": "Service for namespace Containment",
"@Core.LongDescription": "This service is located at [https://localhost/service-root/](https://localhost/service-root/)",
"@Capabilities.BatchSupported": false,
"Wholes": {
"$Collection": true,
Expand Down Expand Up @@ -371,4 +382,4 @@
}
},
"$EntityContainer": "Containment.Container"
}
}
10 changes: 9 additions & 1 deletion test/lib/compile/data/csdl-16.1.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"$Version": "4.01",
"$Reference": {
"https://sap.github.io/odata-vocabularies/vocabularies/Common.xml": {
"$Include": [
{ "$Alias": "Common", "$Namespace": "com.sap.vocabularies.Common.v1" }
]
},
"https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Core.V1.json": {
"$Include": [
{
Expand Down Expand Up @@ -164,6 +169,9 @@
],
"DemoService": {
"$Kind": "EntityContainer",
"@Common.Label": "Service for namespace ODataDemo",
"@Core.Description": "Service for namespace ODataDemo",
"@Core.LongDescription": "This service is located at [https://localhost/service-root/](https://localhost/service-root/)",
"Products": {
"$Collection": true,
"$Type": "ODataDemo.Product",
Expand Down Expand Up @@ -208,4 +216,4 @@
}
},
"$EntityContainer": "ODataDemo.DemoService"
}
}
13 changes: 12 additions & 1 deletion test/lib/compile/data/custom-parameters.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"$Version": "4.01",
"$Reference": {
"https://sap.github.io/odata-vocabularies/vocabularies/Common.xml": {
"$Include": [
{
"$Alias": "Common",
"$Namespace": "com.sap.vocabularies.Common.v1"
}
]
},
"https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Capabilities.V1.json": {
"$Include": [
{
Expand Down Expand Up @@ -98,6 +106,9 @@
],
"box": {
"$Kind": "EntityContainer",
"@Common.Label": "Service for namespace custom.parameters",
"@Core.Description": "Service for namespace custom.parameters",
"@Core.LongDescription": "This service is located at [https://localhost/service-root/](https://localhost/service-root/)",
"@Capabilities.KeyAsSegmentSupported": true,
"ents": {
"$Collection": true,
Expand Down Expand Up @@ -483,4 +494,4 @@
}
},
"$EntityContainer": "custom.parameters.box"
}
}
9 changes: 9 additions & 0 deletions test/lib/compile/data/descriptions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"$Version": "4.01",
"$Reference": {
"https://sap.github.io/odata-vocabularies/vocabularies/Common.xml": {
"$Include": [
{
"$Alias": "Common",
"$Namespace": "com.sap.vocabularies.Common.v1"
}
]
},
"https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Core.V1.json": {
"$Include": [
{
Expand Down Expand Up @@ -269,6 +277,7 @@
},
"$Annotations": {
"self.Default": {
"@Common.Label": "Container - Label",
"@Core.Description": "Container - Description",
"@Core.LongDescription": "Container - LongDescription"
},
Expand Down
4 changes: 2 additions & 2 deletions test/lib/compile/data/descriptions.openapi3.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"openapi": "3.0.2",
"info": {
"title": "Container - Description",
"title": "Container - Label",
"description": "Container - LongDescription\n\n## Entity Data Model\n![ER Diagram](https://yuml.me/diagram/class/[entity{bg:lightslategray}],[entity]++-*>[subEntity],[entity]-*>[entity],[subEntity{bg:lightslategray}],[functionimport_no_descriptions{bg:lawngreen}],[functionimport_ext{bg:lawngreen}],[functionimport{bg:lawngreen}],[actionimport_no_descriptions{bg:lawngreen}],[actionimport_ext{bg:lawngreen}],[actionimport{bg:lawngreen}],[single_ext%20{bg:lawngreen}]++->[entity],[single%20{bg:lawngreen}]++-0..1>[entity],[entities_ext%20{bg:lawngreen}]++-*>[entity],[entities%20{bg:lawngreen}]++-*>[entity])\n\n### Legend\n![Legend](https://yuml.me/diagram/plain;dir:TB;scale:60/class/[External.Type{bg:whitesmoke}],[ComplexType],[EntityType{bg:lightslategray}],[EntitySet/Singleton/Operation{bg:lawngreen}])",
"version": "0.0.1"
},
Expand Down Expand Up @@ -3635,4 +3635,4 @@
}
}
}
}
}
5 changes: 2 additions & 3 deletions test/lib/compile/openapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,10 @@ describe('OpenAPI export', () => {
);
let openapi = toOpenApi(csn, { service: 'A' });
expect(openapi).toMatchObject({ servers: [{ url: '/a' }] });
expect(openapi.info.description).toMatch(/\/a/i)
expect(openapi.info.description).toBe("Use @Core.LongDescription: '...' on your CDS service to provide a meaningful description.")

openapi = toOpenApi(csn, { service: 'A', 'openapi:url': 'http://foo.bar:8080' });
expect(openapi).toMatchObject({ servers: [{ url: 'http://foo.bar:8080' }] });
expect(openapi.info.description).toMatch(/http:\/\/foo.bar:8080/i)

openapi = toOpenApi(csn, { service: 'A', 'openapi:url': 'http://foo.bar:8080//${service-path}/foo' });
expect(openapi).toMatchObject({ servers: [{ url: 'http://foo.bar:8080/a/foo' }] });
Expand Down Expand Up @@ -392,4 +391,4 @@ describe('OpenAPI export', () => {
expect(openAPI.externalDocs.url).toBe('https://help.sap.com/docs/product/123.html');
}
);
});
});

0 comments on commit e9cdfc4

Please sign in to comment.