UI5 / UI5/openui5

Enum: several key-value pairs not identical

Open
#4,201 1 comment 0 reactions 1 assignee View on GitHub

@50gY is already working on this.

Since Jan 31, 2025.

bug in progress
Dominant language
JavaScript
Stars
3.3k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Problem

According to the documentation topic Defining Control Properties, there are specific restrictions when defining a new enum type:

  • The value for each key must be a string literal, equal to the key itself.
  • [...] only keys and values of type string are supported.
...

Apart from the above documented restrictions; when assigning enum values declaratively in XML, JSON (e.g. manifest.json), or HTML (data-*), the actual enum values visible in the source code must be passed instead of the keys. This leads to issues like #1703 where the documented key name "Put" was attempted but the actual expected value is "PUT".

While the real values can be accessed and assigned via sap.ui.define / require in JS, it is difficult to do so declaratively in XML or JSON. Developers would have to inspect the source framework code to discover the actual enum values since only the keys are visible in the API reference. Additionally, non-ManagedObject properties, such as the roundingMode in formatOptions, are not validated either unlike in https://github.com/SAP/openui5/issues/2166.

Findings

Here are public enum types that I've looped through and that do not align with the above documented restrictions:[^1]

OpenUI5

SAPUI5

  • CA-UI5-CUX

    sap/cux/home/library.NewsType

  • CA-UI5-VTK

    sap/ui/vk/CameraFOVBindingType

    sap/ui/vk/CameraProjectionType

    sap/ui/vk/DrawerToolbarButton

    sap/ui/vk/ObjectType

    sap/ui/vk/SelectionMode

    sap/ui/vk/VisibilityMode

    sap/ui/vk/ZoomTo

  • GA-GTF-VBZ

    sap/ui/vbm/library.ClusterInfoType

  • CA-UI5-CMP

    sap/ui/comp/library.smartchart.SelectionMode

    sap/ui/comp/library.smartfield.ControlContextType

    sap/ui/comp/library.smartfield.ControlProposalType

    sap/ui/comp/library.smartfilterbar.SelectOptionSign

    sap/ui/comp/library.TextArrangementType

  • CA-UI5-SC

    sap/suite/ui/commons/library.CalculationBuilderFunctionType

    sap/suite/ui/commons/library.SelectionModes

  • CA-UI5-RUL

    sap/rules/ui/library.DecisionTableFormat

    sap/rules/ui/library.RuleHitPolicy

    sap/rules/ui/library.RuleType

  • CA-UI5-CTR-GNT

    sap/gantt/library.config.TimeUnit

    sap/gantt/library.def.filter.ColorMatrixValue

    sap/gantt/library.def.filter.MorphologyOperator

    sap/gantt/library.shape.ext.rls.RelationshipType

    sap/gantt/library.shape.ShapeCategory

  • LOD-ANA-FLY-DF

    sap/sac/df/types/DocumentsSupportType

    sap/sac/df/types/SortDirection

    sap/sac/df/types/SortType

  • BI-CVM

    sap/chart/data/MeasureSemantics

    sap/chart/library.MessageId

    sap/chart/library.SelectionBehavior

    sap/chart/library.SelectionMode

  • BI-CVM-UI5

    sap/viz/ui5/format/ChartFormatter.DefaultPattern

Similar issues / fixes in the past

Ideas to reduce future issues?

  • UI5 linter detecting faulty enum definitions
  • Future fatal logging by DataType.registerEnum if the passed object contains faulty enum definitions
  • Allowing enums to be required and assigned in XML such as to ManagedObject properties and binding infos (Cf. https://x.com/wridgeu/status/1567955929051570178 by @wridgeu)
  • Downporting fixes
  • Adding a test to ensure future introduction of new enums comply with the documented restrictions

[^1]: Excluded from the search were the libs sap.apf, sap.ca.scfld.md, sap.fiori, sap.ui.demoapps, sap.ui.documentation, sap.ui.server.java, sap.ui.server.abap, sap.ui.support, sap.ushell_abap, themelib*, *.test*, *.tools*, and libs / enum types that are either deprecated or restricted. Types related to MockServer, jQuery, and test were also skipped. IllustratedMessageType is ignored too since the IllustratedMessage property illustrationType explicitly states that the illustration set name (e.g. sapIllus-) must be prepended.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.