Skip to content

Treat map entries with empty string values as missing for (required) #305

@alexander-yevsyukov

Description

@alexander-yevsyukov

A map<K, string> field marked with (required) currently accepts an entry whose value is an empty string. Such an entry is effectively "empty" and should be treated the same as having no entries at all for the purpose of the (required) constraint.

Consider this scenario from RequiredMapWithStringsITest:

val empty = Collections.newBuilder()
    .putContainsANonEmptyStringValue("", "")
    .putNotEmptyMapOfInts(111, 314)
    .addAtLeastOnePieceOfMeat(UltimateChoice.FISH)
    .addNotEmptyListOfLongs(42L)
assertInvalid(empty)

The above currently passes validation because the map contains one entry, even though that entry carries no information. The test prohibit an entry with empty string is @Disabled until we decide on the semantics.

Proposed behaviour

An entry with an empty string value in a (required) map should be considered as not satisfying the (required) constraint — by analogy with the way an empty string in a (required) string field is rejected.

An empty string key should be accepted even if (required) option is used.

Files

  • tests/validating/src/test/kotlin/io/spine/test/options/required/RequiredMapWithStringsITest.kt

Tasks

  • Decide on the precise semantics of an "empty" map entry for (required).
  • Update the validation logic accordingly.
  • Re-enable the prohibit an entry with empty string test.
  • Check that the documentation of the (required) option in spine/options.proto in Spine Base (../base-libraries/base) describes the required map key behavior. If not, update.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions