Enum: several key-value pairs not identical
@50gY is already working on this.
Since Jan 31, 2025.
- 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
-
CA-UI5-TBL
→ JS use only. Intended to be used in conjunction withsap/ui/table/library.SharedDomRefgetDomRef. -
CA-UI5-CTR
sap/ui/unified/library.CalendarIntervalTypewhereOneMonth!=="One Month".
(Btw.WeekandOneMonthare not public intentionally?)sap/ui/unified/FileUploaderHttpRequestMethod→ Fixed with:sap/m/library.DialogRoleTypec02d6ad→ JS use only.sap/m/library.LightBoxLoadingStates→ Only JS use found so far. However,sap/m/MessageBox.IconDataType.getType("sap.m.MessageBox.Icon")should not cause "Error: Valueundefinedfor enum type sap.m.MessageBox.Icon is not a string" → Fixed with:f5c05a0→ PlanningCalendar explicitly states thesap/m/library.PlanningCalendarBuiltInViewbuiltInViewscan be "specified by their keys." Using"OneMonth"works.sap/m/library.SharingMode→ Fixed with:sap/m/upload/UploaderHttpRequestMethod09e0b0e -
CA-UI5-MDC
https://github.com/SAP/openui5/issues/4206
→ Fixed with: https://github.com/SAP/openui5/commit/98bad43c108101257494c07ba73d0c02b86ccbb3
sap/ui/mdc/enums/FilterBarValidationStatussap/ui/mdc/enums/OperatorValueType -
CA-UI5-COR
→ JS use only. Bootstrap configsap/base/Log.Levelsap-ui-logLevelwith the key names already effective.→ JS use only.sap/ui/events/KeyCodes→ JS use only.sap/ui/core/mvc/XMLView.PreprocessorType→ Used bysap/ui/core/Popup.Docksap.ui.vk.ToggleMenuButton'smenuPositionand foreseeably by other ManagedObjects. → Fixed with:bff7b33→ JS use only.sap/ui/core/ws/ReadyState→ Only JS use found so far.sap/ui/core/ws/SapPcpWebSocket.SUPPORTED_PROTOCOLS→ Deprecated in legacy-free:sap/ui/model/analytics/odata4analytics.SortOrderab99f45→ JS use only.sap/ui/model/ChangeReason→ Fixed with:sap/ui/model/odata/UpdateMethodc569488
SAPUI5
-
CA-UI5-CUX
sap/cux/home/library.NewsType -
CA-UI5-VTK
sap/ui/vk/CameraFOVBindingTypesap/ui/vk/CameraProjectionTypesap/ui/vk/DrawerToolbarButtonsap/ui/vk/ObjectTypesap/ui/vk/SelectionModesap/ui/vk/VisibilityModesap/ui/vk/ZoomTo -
GA-GTF-VBZ
sap/ui/vbm/library.ClusterInfoType -
CA-UI5-CMP
sap/ui/comp/library.smartchart.SelectionModesap/ui/comp/library.smartfield.ControlContextTypesap/ui/comp/library.smartfield.ControlProposalTypesap/ui/comp/library.smartfilterbar.SelectOptionSignsap/ui/comp/library.TextArrangementType -
CA-UI5-SC
sap/suite/ui/commons/library.CalculationBuilderFunctionTypesap/suite/ui/commons/library.SelectionModes -
CA-UI5-RUL
sap/rules/ui/library.DecisionTableFormatsap/rules/ui/library.RuleHitPolicysap/rules/ui/library.RuleType -
CA-UI5-CTR-GNT
sap/gantt/library.config.TimeUnitsap/gantt/library.def.filter.ColorMatrixValuesap/gantt/library.def.filter.MorphologyOperatorsap/gantt/library.shape.ext.rls.RelationshipTypesap/gantt/library.shape.ShapeCategory -
LOD-ANA-FLY-DF
sap/sac/df/types/DocumentsSupportTypesap/sac/df/types/SortDirectionsap/sac/df/types/SortType -
BI-CVM
sap/chart/data/MeasureSemanticssap/chart/library.MessageIdsap/chart/library.SelectionBehaviorsap/chart/library.SelectionMode -
BI-CVM-UI5
sap/viz/ui5/format/ChartFormatter.DefaultPattern
Similar issues / fixes in the past
- https://github.com/SAP/openui5/issues/2169 (https://github.com/SAP/openui5/commit/7b6f6a19c75d185a27dae871e4eb8bb95ee2da70) (https://stackoverflow.com/a/43946624/5846045)
- https://github.com/SAP/openui5/issues/1759#issuecomment-412899129 (https://github.com/SAP/openui5/commit/c7e39e4f5793b4ce6a44bf38354bd3980761ed95)
- https://github.com/SAP/openui5/issues/1703
- https://github.com/SAP/openui5/commit/90b30ac7a720e6c1c0be2936ce39465cacd6464a
- https://github.com/SAP/openui5/commit/367b728d389f2789d3a2c84b088a16ad552944cb
Ideas to reduce future issues?
- UI5 linter detecting faulty enum definitions
- Future fatal logging by
DataType.registerEnumif 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.