Skip to Content
0
Aug 14, 2021 at 09:57 AM

SAP CAP Enum

1353 Views

Hi experts,

We have an enum type as follows:

type colour : String enum { Red; Pink; Purple; Indigo; Blue; Amber; Yellow; Orange }

We are trying to use this type in a colour property existing in various entities:

  colour: colour
  @description: 'Avatar colour';

2 questions:

1. But the database is not validating that string received against the list of colours defined in the enum and it is allowing all the strings. Any idea about how to achieve that? I have tried with @assert.range but it is just allowing me to do so if I define the enum within the entity itself and I want to avoid that as this enum is used in several entities.

2. On the other hand, the enum declaration is not allowing me to put values with spaces (e.g. Deep Blue). Any idea about how to achieve this?

Many thanks!

M.