Skip to content

Missing required field goes unreported when its path shares a prefix with an absent optional field #1054

Description

@hunseonglee

JsonContentHandler.isNestedBeneathMissingOptionalField decides whether a missing descriptor is covered by an absent optional ancestor using a plain string prefix test:

if (candidate.isOptional() && descriptor.getPath().startsWith(candidate.getPath()) && isMissing(candidate, payload)) {

Because there is no segment-boundary check, a required field whose path merely shares a string prefix with an absent optional field's path is treated as nested beneath it, and its absence is never reported. For payload {"c": "charlie"} with descriptors optional a (absent) and required ab (absent), findMissingFields() returns nothing and the snippet is generated, although ab is a missing required field. The same applies to e.g. optional a.b and required a.bc, and it also affects resolveFieldType.

Reproduced on main (3ec9c63, 4.0.2-SNAPSHOT).

Expected: ab is only considered nested beneath a when the path continues with a segment boundary (a.b... or a[...]), so the missing required field is reported. I will submit a PR with a fix and tests.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions