question
I yarn start
started a SAP Fiori Elements application locally, and observed an OData metadata request url in the network panel of the Chrome developer tool as follows:
http://localhost:8080/sap/opu/odata/sap/SEPMRA_PROD_MAN/$metadata?sap-value-list=none&sap-language=EN
How is the name of this OData service SEPMRA_PROD_MAN
determined at runtime?
Check out Component.js
the functions in the file Component._createManifestModels
:
We look at the variables mModels
and find that there are three fields:
where the value of the "" field comes from the field of the same name in the section manifest.json
of the file :models
dataSource
Points to the value of mainService
, and the latter uri
field is the url that initiates the OData metadata request when the Fiori Elements application is running:
In SAP UI5 application, manifest.json
file is an important configuration file. It acts as the application's descriptor, defining the application's metadata, models, services, i18n (internationalization), etc. We can think of it as a centralized configuration center, where all configurations are in one place, making the code easier to maintain and easier to understand.
In manifest.json
the file, dataSources
the section is a very important part, which defines how the application connects to the backend service. This area can declare one or more data sources, and each data source corresponds to a backend service. These services can be OData services or other types of services.
After we manifest.json
define the data source in the file, we can refer to the service by the name of the data source in other parts of the application without remembering the specific URL. The advantage of this is that if the service's URL changes, we only need to update it in one place, rather than having to search the entire codebase to find all the places where the service is used.
The following is an example of regions manifest.json
in a file :dataSources
{
"sap.app": {
"dataSources": {
"mainService": {
"uri": "/sap/opu/odata/sap/ZMAIN_SRV/",
"type": "OData",
"settings": {
"odataVersion": "2.0"
}
},
"secondService": {
"uri": "/sap/opu/odata/sap/ZSECOND_SRV/",
"type": "OData",
"settings": {
"odataVersion": "2.0"
}
}
}
}
}
In the above example, we defined two data sources named mainService
and secondService
. Each data source has a uri
property that defines the URL of the service. type
The attribute defines the type of service, here we are using OData service. settings
The object contains other configuration of the service, such as the version of OData.
After defining the data source, we can use this data source in other parts of the application. For example, we can models
define a model in a region and associate this model with a data source:
{
"sap.ui5": {
"models": {
"": {
"dataSource": "mainService",
"preload": true
},
"secondModel": {
"dataSource": "secondService",
"preload": true
}
}
}
}
In the above example, we defined two models, which are respectively associated with the two data sources we defined earlier. In this way, when we use these two models in the application, SAP UI5 will automatically use the corresponding data source to connect to the back-end service.
Summarize
In general, the fields manifest.json
in the file dataSources
are used to define how the application connects to the backend services. It centralizes the configuration of services in one place, making the code more maintainable and easier to understand.