You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 or manifest.json, 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 #2166.
Findings
Here are public enum types that I've looped through and that do not align with the above documented restrictions:1
Adding a test to ensure future introduction of new enums comply with the documented restrictions
Footnotes
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. ↩
The text was updated successfully, but these errors were encountered:
Apart from the above documented restrictions; when assigning enum values declaratively in XML or manifest.json, the actual enum values visible in the source code must be passed instead of the keys
This is partially wrong: in XML, you have to use the key, not the value. This is by intention as developers should not be forced to look up values in the source code (see implementation of DataType#parseValue for enum types)
Use cases in the manifest (e.g. model settings as in #1703, but there are others, too) are not covered so far and we might have to re-consider our rules (see next paragraph).
By intention, not every enum in UI5 has to comply with the key === value rule, only when it is intended to be used as type for a managed property. For that reason, our internal metadata validation tool (not visible to the outside, therefore not linking it) checks enums once they are found in a managed property of control / element or other managed object. IMO this might apply to several of the above enums.
Unfortunately, the metadata validation is forcefully bypassed by several SAPUI5 libs. We are already in the process of enforcing its use (for other reasons than the enums).
Any existing enums that are used or foreseeable will be used in managed properties (or in the manifest, sigh) and which don't comply with the key === value constraint. need to be fixed.
P.S.: Not everyone can read the full content of the post on "X".
Problem
According to the documentation topic Defining Control Properties, there are specific restrictions when defining a new enum type:
Apart from the above documented restrictions; when assigning enum values declaratively in XML or
manifest.json
, 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 theroundingMode
informatOptions
, are not validated either unlike in #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
sap/ui/table/library.SharedDomRef
openui5/src/sap.ui.table/src/sap/ui/table/library.js
Lines 295 to 317 in 6717fc9
CA-UI5-CTR
sap/ui/unified/library.CalendarIntervalType
whereOneMonth
!=="One Month"
.(Btw.
Week
andOneMonth
are not public intentionally?)openui5/src/sap.ui.unified/src/sap/ui/unified/library.js
Lines 308 to 353 in 6717fc9
sap/ui/unified/FileUploaderHttpRequestMethod
openui5/src/sap.ui.unified/src/sap/ui/unified/FileUploaderHttpRequestMethod.js
Lines 9 to 31 in 6717fc9
sap/m/library.DialogRoleType
openui5/src/sap.m/src/sap/m/library.js
Lines 1266 to 1286 in c7d165e
sap/m/library.LightBoxLoadingStates
openui5/src/sap.m/src/sap/m/library.js
Lines 5160 to 5191 in 6717fc9
sap/m/MessageBox.Icon
openui5/src/sap.m/src/sap/m/MessageBox.js
Lines 169 to 181 in 6717fc9
sap/m/library.PlanningCalendarBuiltInView
openui5/src/sap.m/src/sap/m/library.js
Lines 1160 to 1201 in 64ee353
sap/m/library.SharingMode
openui5/src/sap.m/src/sap/m/library.js
Lines 5525 to 5543 in 64ee353
sap/m/upload/UploaderHttpRequestMethod
openui5/src/sap.m/src/sap/m/upload/UploaderHttpRequestMethod.js
Lines 9 to 31 in 64ee353
CA-UI5-MDC
sap/ui/mdc/enums/FilterBarValidationStatus
openui5/src/sap.ui.mdc/src/sap/ui/mdc/enums/FilterBarValidationStatus.js
Lines 9 to 50 in 64ee353
sap/ui/mdc/enums/OperatorValueType
openui5/src/sap.ui.mdc/src/sap/ui/mdc/enums/OperatorValueType.js
Lines 8 to 38 in 64ee353
sap/ui/mdc/enums/ReasonMode
openui5/src/sap.ui.mdc/src/sap/ui/mdc/enums/ReasonMode.js
Lines 10 to 43 in 64ee353
CA-UI5-COR
sap/base/Log.Level
openui5/src/sap.ui.core/src/sap/base/Log.js
Lines 51 to 100 in 1bc4df3
sap/ui/events/KeyCodes
openui5/src/sap.ui.core/src/sap/ui/events/KeyCodes.js
Lines 7 to 626 in 1bc4df3
sap/ui/core/mvc/XMLView.PreprocessorType
openui5/src/sap.ui.core/src/sap/ui/core/mvc/XMLView.js
Lines 867 to 897 in 1bc4df3
sap/ui/core/Popup.Dock
openui5/src/sap.ui.core/src/sap/ui/core/Popup.js
Lines 398 to 497 in 1bc4df3
sap/ui/core/ws/ReadyState
openui5/src/sap.ui.core/src/sap/ui/core/ws/ReadyState.js
Lines 10 to 44 in 1bc4df3
sap/ui/core/ws/SapPcpWebSocket.SUPPORTED_PROTOCOLS
openui5/src/sap.ui.core/src/sap/ui/core/ws/SapPcpWebSocket.js
Lines 58 to 77 in 1bc4df3
sap/ui/model/analytics/odata4analytics.SortOrder
openui5/src/sap.ui.core/src/sap/ui/model/analytics/odata4analytics.js
Lines 3590 to 3612 in 1bc4df3
sap/ui/model/ChangeReason
openui5/src/sap.ui.core/src/sap/ui/model/ChangeReason.js
Lines 10 to 78 in 1bc4df3
sap/ui/model/odata/UpdateMethod
openui5/src/sap.ui.core/src/sap/ui/model/odata/UpdateMethod.js
Lines 10 to 30 in 1bc4df3
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
RoundingMode
Key-Value Pairs Not Identical #2169 (7b6f6a1) (https://stackoverflow.com/a/43946624/5846045)Ideas to reduce future issues?
DataType.registerEnum
if the passed object contains faulty enum definitionsFootnotes
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 theIllustratedMessage
propertyillustrationType
explicitly states that the illustration set name (e.g.sapIllus-
) must be prepended. ↩The text was updated successfully, but these errors were encountered: