Skip to content

[Bug]: uniqueItems validators are incorrectly injected into unrelated classes with same-named fields #60

Description

@horaceewang-TT

Describe the bug

The uniqueItems post-processing logic currently collects constrained fields as a global set of field names.

When multiple generated classes contain list fields with the same name, inject_unique_items injects a validator into every matching class, even when only one class declares uniqueItems: true in its schema.

To Reproduce

  1. Define a schema for First where tags is an array with uniqueItems: true.
  2. Generate a module containing both First.tags and Second.tags.
  3. Run the uniqueItems post-processing step.
  4. Inspect the generated classes.

Expected behavior

Expected Behavior

The uniqueItems validator should only be injected into the class whose schema explicitly declares uniqueItems: true.

If multiple classes contain list fields with the same name:

  • The class declaring uniqueItems: true must reject duplicate values.
  • Classes without the constraint must not receive the validator.
  • Unconstrained fields must continue to accept duplicate values.
  • The generated module must contain exactly one validator for each scoped uniqueItems constraint.

Screenshots

No response

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions