Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Multiple service support #2499

Open
wants to merge 50 commits into
base: main
Choose a base branch
from
Open

feat: Multiple service support #2499

wants to merge 50 commits into from

Conversation

broksy
Copy link
Contributor

@broksy broksy commented Oct 25, 2024

Adds support for multiple services and multiple annotations per service. Includes updates for multiple packages.

odata-service-writer

  • Added remove(basePath, service, fs?) to handle service related data removal from manifest.json and YAML files
  • Added optional parameter for generateMockserverConfig: overwrite (if true, then mockserver services and annotations are overwritten based on manifest dataSources), else dataSources for services and annotations from manifest are collected and appended to the existing mockserver data
  • Manifest template enhanced with support for annotations used as object or array to have backward compatibility

mockserver-config-writer

  • Added removeMockDataFolders(fs, basePath) to remove all mock data paths during running of removeMockserverConfig.

ui5-config

  • Added addServiceToMockserverMiddleware(dataSourceConfig, appRoot?, annotationsConfig = []) to add service to mockserver
  • Added removeServiceFromMockServerMiddleware(servicePath, annotationsPaths) to delete service from mockserver including annotations related to this service
  • Added removeBackendFromFioriToolsProxydMiddleware(backendUrl) to delete back from fiori-tools-proxy

create

  • Added another question whether user wants to overwrite existing services when interactive mode is used for command. If true, then mockserver services will be overwritten based on manifest dataSources and only when ui5-mock.yaml is available.

fiori-freestyle-writer

  • Since merge with main branch snapshots on Windows started to fail, I changed hardcoded '/'(Unix like separator) to sep (universal separator) from path module during template generation in processDestinationPath(filePath) in order to make replace work also on Windows like paths.

@broksy broksy requested review from a team as code owners October 25, 2024 15:54
Copy link

changeset-bot bot commented Oct 25, 2024

🦋 Changeset detected

Latest commit: 6da046a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 35 packages
Name Type
@sap-ux/mockserver-config-writer Minor
@sap-ux/odata-service-writer Minor
@sap-ux/ui5-config Minor
@sap-ux/create Minor
@sap-ux/fiori-elements-writer Patch
@sap-ux/fiori-freestyle-writer Patch
@sap-ux/odata-service-inquirer Patch
@sap-ux/generator-simple-fe Patch
@sap-ux/abap-deploy-config-inquirer Patch
@sap-ux/abap-deploy-config-writer Patch
@sap-ux/adp-tooling Patch
@sap-ux/app-config-writer Patch
@sap-ux/cards-editor-config-writer Patch
@sap-ux/cf-deploy-config-writer Patch
@sap-ux/deploy-tooling Patch
@sap-ux/environment-check Patch
@sap-ux/launch-config Patch
@sap-ux/project-access Patch
@sap-ux/telemetry Patch
@sap-ux/ui5-application-writer Patch
@sap-ux/ui5-library-reference-writer Patch
@sap-ux/ui5-library-writer Patch
@sap-ux/ui5-proxy-middleware Patch
@sap-ux/preview-middleware Patch
@sap-ux/annotation-generator Patch
@sap-ux/cap-config-writer Patch
@sap-ux/cards-editor-middleware Patch
@sap-ux/fe-fpm-writer Patch
@sap-ux/fiori-annotation-api Patch
@sap-ux/fiori-generator-shared Patch
@sap-ux/ui5-application-inquirer Patch
@sap-ux/ui5-library-reference-inquirer Patch
@sap-ux/ui5-library-reference-sub-generator Patch
@sap-ux/ui5-library-sub-generator Patch
@sap-ux/fe-fpm-cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@broksy broksy requested a review from a team as a code owner October 25, 2024 16:55
@broksy broksy added mockserver-config-writer @sap-ux/mockserver-config-writer odata-service-writer @sap-ux/odata-servier-writer ui5-config @sap-ux/ui5-config create @sap-ux/create labels Oct 25, 2024
@heimwege
Copy link
Contributor

heimwege commented Nov 6, 2024

You fix for the fiori-freestyle-writer issue has been addressed in #2532 as it was blocking other PRs as well

Copy link
Contributor

@heimwege heimwege left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments. Some improvement suggestions, some nit-picks (sorry for that), some type issues but no major issues

packages/mockserver-config-writer/src/app-info.ts Outdated Show resolved Hide resolved
packages/mockserver-config-writer/src/app-info.ts Outdated Show resolved Hide resolved
packages/odata-service-writer/src/data/defaults.ts Outdated Show resolved Hide resolved
packages/odata-service-writer/src/data/defaults.ts Outdated Show resolved Hide resolved
packages/odata-service-writer/src/delete.ts Outdated Show resolved Hide resolved
packages/odata-service-writer/src/index.ts Show resolved Hide resolved
packages/odata-service-writer/src/index.ts Outdated Show resolved Hide resolved
@broksy broksy requested a review from heimwege November 8, 2024 14:12
heimwege
heimwege previously approved these changes Nov 8, 2024
Copy link
Contributor

@heimwege heimwege left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • changeset ok
  • review comments addressed
  • test coverage is very good
  • did NOT test manually

heimwege
heimwege previously approved these changes Nov 12, 2024
Copy link
Contributor

@heimwege heimwege left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-approve

Copy link
Contributor

@johannes-kolbe johannes-kolbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @broksy - Review focused on:

  • Code review in general
  • odata-service-writer - generate command
    • adding services to ui5-local|ui5-mock.yaml
    • adding service to manifest.json
      • localUri path is not resolved to metadata.xml
      • first service in manifest should be sap.ui5/models/"": { … }, not sap.ui5/models/"serviceName"
  • Manual testing with tools-suite consumption
  • Did not test:
    • Deletion of services
    • Add command
    • CDS annotation scenario

);

// Create local copy of metadata and annotations
fs.write(join(webappPath, 'localService', 'metadata.xml'), prettifyXml(service.metadata, { indent: 4 }));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to work hardcoded for adding multiple services - Adding a new service would delete the old metadata.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 54a778d

"<%- localAnnotationsName %>"
<% } %>
]
<% if (locals.metadata) { %>,
"localUri": "localService/metadata.xml" <% } %><%if (version === '4') {%>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

localUri also has to be dynamically rendered. It is dependent on the folder the service is moved/generated to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in e5029f3

"uri": "/sap/opu/odata/IWFND/CATALOGSERVICE;v=2/Annotations(TechnicalName='<%- encodeURIComponent(annotation.technicalName) %>',Version='0001')/$value/",
"type": "ODataAnnotation",
"settings": {
"localUri": "localService/<%- annotation.technicalName %>.xml"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here with localUri

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in e5029f3

"uri": "/sap/opu/odata/IWFND/CATALOGSERVICE;v=2/Annotations(TechnicalName='<%- encodeURIComponent(annotations.technicalName) %>',Version='0001')/$value/",
"type": "ODataAnnotation",
"settings": {
"localUri": "localService/<%- annotations.technicalName %>.xml"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here with localUri

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in e5029f3

@broksy
Copy link
Contributor Author

broksy commented Nov 13, 2024

first service in manifest should be sap.ui5/models/"": { … }, not sap.ui5/models/"serviceName"

Currently it's up to consumer.
It's handled in enhanceData(service) in odata-service-writer package right before manifest enhancements.
If service param for generate has a model name then it's used, otherwise default '' is set and later used for manifest enhancements.

However, I can enhance setDefaultServiceModel to this:

    const models = manifest['sap.ui5']?.models;
    if (models) {
        // Filter dataSource models by dataSource property
        const servicesModels = Object.values(models).filter((model) => model.dataSource);
        // First one is being added
        if (servicesModels.length === 0) {
            service.model = '';
        } else {
            service.model = service.model ?? service.name;
        }
    } else {
        service.model = '';
    }

In such case it will always make sure that:

  1. '' will be used for first service
  2. service.model ?? service.name for next services

Done in 6da046a

Copy link

sonarcloud bot commented Nov 13, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
create @sap-ux/create mockserver-config-writer @sap-ux/mockserver-config-writer odata-service-writer @sap-ux/odata-servier-writer ui5-config @sap-ux/ui5-config
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants