How to define annotations in manifest.json of SAP Fiori Elements application

In the SAP Fiori Elements application, the manifest.json file is the main configuration file of the application, which defines the metadata, models, services and other information of the application. Among them, the dataSources area is responsible for describing the data sources used by the application, such as OData services or other types of backend services. In the settings field of the dataSources area, we can define annotations, which are a way to describe OData service metadata, can enhance the semantics of the service, and can drive the automatic generation of UI.

Annotations are an important concept in SAP Fiori Elements. They provide a declarative way to define various characteristics of the UI, including but not limited to how fields are displayed, sorting, filtering, and so on.

Specifically, annotations can define:

  • Some attributes of the entity type, such as label, text, hint, etc.
  • Behavior of entity types such as createable, updatable, deleteable, etc.
  • The UI representation of entity types, such as tables, forms, lists, etc.
  • Relationships of entity types, such as navigation properties, associations, etc.

The way to define annotations in the settings of dataSources is roughly as follows:

"dataSources": {
    
    
    "mainService": {
    
    
        "uri": "/sap/opu/odata/sap/ZDEMO_C_SALESORDERITEM_CDS/",
        "type": "OData",
        "settings": {
    
    
            "annotations": ["annotations1", "annotations2"]
        }
    },
    "annotations1": {
    
    
        "uri": "/sap/opu/odata/IWFND/CATALOGSERVICE;v=2;mo/Annotations(TechnicalName='ZDEMO_ANNO_MDL',Version='0001')/$value",
        "type": "ODataAnnotation"
    },
    "annotations2": {
    
    
        "uri": "/sap/opu/odata/IWFND/CATALOGSERVICE;v=2;mo/Annotations(TechnicalName='ZDEMO_ANNO_UI',Version='0001')/$value",
        "type": "ODataAnnotation"
    }
}

In the above example, we defined two annotations, called "annotations1" and "annotations2", which respectively correspond to two data sources of ODataAnnotation type, and these two data sources point to two different annotation files. These annotation files are used to describe the metadata of the "mainService" data source (that is, the OData service).

For example, we can define a label for an entity type in the annotation file as follows:

<Annotations Target="ZDEMO_C_SALESORDERITEM_CDS.SalesOrderItem">
    <Annotation Term="com.sap.vocabularies.Common.v1.Label" String="Sales Order Item"/>
</Annotations>

This code defines the SalesOrderItem entity type with the label "Sales Order Item". In the UI of the Fiori Elements application, this label will be used as the display name of the entity type.

In this way, we can define complex business logic and user interface through annotations without writing a lot of front-end code. This greatly improves development efficiency, reduces development difficulty, and enables developers to focus more on implementing business logic rather than writing UI.

Guess you like

Origin blog.csdn.net/i042416/article/details/131833792