Skip to content

NewValidator corrupts the shared document model when a schema has a recursive $ref target #304

Description

@litteratum

Continuation of #293.
The issue was fixed only partially.

What's wrong

Building a validator mutates the caller's live DocumentModel. After validator.NewValidator(doc), schemas that are read for the first time afterwards can resolve with an empty Type (and other lazily-resolved fields degrade the same way).

Root cause

go-yaml v4 mutates the nodes it serializes — it strips their resolved tags in place (issue 371). Since the high-level model resolves lazily from those same nodes, any schema read after construction sees the stripped nodes.

Reproduction

A parameter whose schema references #/components/schemas/T where T contains properties.self.$ref: '#/components/schemas/T'. Build the model, call NewValidator, then read any not-yet-read schema's Type → empty.

Fix

Always clone the node before marshalling in renderYAMLNodeForValidation.

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

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions