diff --git a/packages/odata-service-writer/templates/extend/manifest.json b/packages/odata-service-writer/templates/extend/manifest.json index a1e238280c..e09b3dea25 100644 --- a/packages/odata-service-writer/templates/extend/manifest.json +++ b/packages/odata-service-writer/templates/extend/manifest.json @@ -21,7 +21,7 @@ <% localAnnotationsName.forEach(function(localAnnotation, index) { %> "<%- localAnnotation %>"<% if (index < localAnnotationsName.length - 1){ %>,<% } %> <% }); %> - <% } else if (localAnnotationsName) { %> + <% } else if (localAnnotationsName && typeof localAnnotationsName === 'string') { %> "<%- localAnnotationsName %>" <% } %> <% } %> @@ -55,9 +55,9 @@ } <% } %> <% } %> - <% if (locals.localAnnotationsName && typeof localAnnotationsName !== 'undefined') { %>, - <% if (locals.localAnnotationsName && typeof localAnnotationsName !== 'undefined') { %> - <% if (Array.isArray(localAnnotationsName) && localAnnotationsName.length > 0) { %> + <% if (locals.localAnnotationsName && localAnnotationsName && (typeof localAnnotationsName === 'string' || (Array.isArray(localAnnotationsName) && localAnnotationsName.length > 0))) { %>, + <% if (locals.localAnnotationsName && localAnnotationsName && (typeof localAnnotationsName === 'string' || (Array.isArray(localAnnotationsName) && localAnnotationsName.length > 0))) { %> + <% if (Array.isArray(localAnnotationsName)) { %> <% localAnnotationsName.forEach(function(localAnnotation, index) { %> "<%- localAnnotation %>": { "type": "ODataAnnotation", @@ -67,14 +67,15 @@ } }<% if (index < localAnnotationsName.length - 1){ %>,<% } %> <% }); %> - <% } else if (localAnnotationsName) { %> + <% } else if (typeof localAnnotationsName === 'string') { %> "<%- localAnnotationsName %>": { "type": "ODataAnnotation", "uri": "annotations/<%- localAnnotationsName %>.xml", "settings": { "localUri": "annotations/<%- localAnnotationsName %>.xml" } - } <% } %> + } + <% } %> <% } %> <% } %> } diff --git a/packages/odata-service-writer/test/test-data/manifest-json/edmx-manifest-no-annotations.ts b/packages/odata-service-writer/test/test-data/manifest-json/edmx-manifest-no-annotations.ts new file mode 100644 index 0000000000..01e005056e --- /dev/null +++ b/packages/odata-service-writer/test/test-data/manifest-json/edmx-manifest-no-annotations.ts @@ -0,0 +1,30 @@ +export const expectedEdmxManifesNoAnnotations = { + 'sap.app': { + id: 'test.update.manifest', + dataSources: { + mainService: { + type: 'OData' + }, + aname: { + uri: '/a/path', + type: 'OData', + settings: { + annotations: [], + odataVersion: '2.0' + } + } + } + }, + 'sap.ui5': { + models: { + '': { + dataSource: 'mainService' + }, + amodel: { + dataSource: 'aname', + preload: true, + settings: {} + } + } + } +}; diff --git a/packages/odata-service-writer/test/unit/updates.test.ts b/packages/odata-service-writer/test/unit/updates.test.ts index 6a189bd9e1..c91b2da499 100644 --- a/packages/odata-service-writer/test/unit/updates.test.ts +++ b/packages/odata-service-writer/test/unit/updates.test.ts @@ -12,6 +12,7 @@ import { expectedEdmxManifestMultipleServices } from '../test-data/manifest-json import { expectedCdsManifest } from '../test-data/manifest-json/cap-manifest'; import { expectedEdmxManifestLocalAnnotation } from '../test-data/manifest-json/edmx-manifest-local-annotation'; // single local annotation import { expectedEdmxManifestLocalAnnotations } from '../test-data/manifest-json/edmx-manifest-local-annotations'; // multiple local annotations +import { expectedEdmxManifesNoAnnotations } from '../test-data/manifest-json/edmx-manifest-no-annotations'; // no any annotations import type { Package } from '@sap-ux/project-access'; jest.mock('ejs', () => ({ @@ -185,6 +186,41 @@ describe('updates', () => { expect(manifestJson).toEqual(expectedEdmxManifestLocalAnnotations); }); + test('Ensure manifest updates are updated as expected as in edmx projects without any annotations', async () => { + const testManifest = { + 'sap.app': { + id: 'test.update.manifest', + dataSources: { + 'mainService': { + type: 'OData' + } + } + }, + 'sap.ui5': { + models: { + '': { + dataSource: 'mainService' + } + } + } + }; + const service: OdataService = { + version: OdataVersion.v2, + client: '123', + model: 'amodel', + name: 'aname', + path: '/a/path', + type: ServiceType.EDMX, + annotations: [], // No remote annotations + localAnnotationsName: [] // No local annotations + }; + fs.writeJSON('./webapp/manifest.json', testManifest); + // Call updateManifest + await updateManifest('./', service, fs, join(__dirname, '../../templates')); + const manifestJson = fs.readJSON('./webapp/manifest.json'); + expect(manifestJson).toEqual(expectedEdmxManifesNoAnnotations); + }); + test('Ensure manifest updates are updated as expected as in edmx projects with multiple annotations', async () => { const testManifest = { 'sap.app': {