Skip to content

fix: reject duplicate enum values and repeated non-repeatable directives#436

Merged
StevenACoffman merged 1 commit into
vektah:masterfrom
advoretsky:fix/enum-value-and-directive-uniqueness
Jun 6, 2026
Merged

fix: reject duplicate enum values and repeated non-repeatable directives#436
StevenACoffman merged 1 commit into
vektah:masterfrom
advoretsky:fix/enum-value-and-directive-uniqueness

Conversation

@advoretsky

Copy link
Copy Markdown
Contributor

LoadSchema silently merged duplicate enum values (no uniqueness check), unlike object fields which already error with "Field X.Y can only be defined once." Add the equivalent check for enum values, reported as "Enum value X.Y can only be defined once."

Also enforce that a non-repeatable directive is applied at most once per schema location during schema validation (the executable-document rule in validator/rules already covers queries, but the type system was unchecked). The check is scoped to single authored locations via a singleLocation flag: a type's own directives are merged across its base definition and every extension, which the spec treats as distinct locations, so the merged list is exempt to avoid rejecting a directive used once per location.

Adds YAML cases covering duplicate enum values (same definition and across an extension), a repeated non-repeatable directive on a field and on an enum value, and positive cases (repeatable directive, the same directive on distinct locations, and a directive on a type plus its extension).

Fixes #435

Describe your PR and link to any relevant issues.

I have:

  • [v] Added tests covering the bug / feature
  • [v] Updated any relevant documentation

@coveralls

coveralls commented Jun 5, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 87.371% (+0.08%) from 87.295% — advoretsky:fix/enum-value-and-directive-uniqueness into vektah:master

@StevenACoffman

StevenACoffman commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Would you mind changing your commit to not attribute claude?

There's also a minor formatting nit:

Error: validator/schema.go:175:1: File is not properly formatted (golines)
  		if err := validateDirectives(&schema, ext.Directives, LocationSchema, nil, true); err != nil {

@advoretsky advoretsky force-pushed the fix/enum-value-and-directive-uniqueness branch from 19cf88b to 45130a0 Compare June 6, 2026 20:42
LoadSchema silently merged duplicate enum values (no uniqueness check),
unlike object fields which already error with "Field X.Y can only be
defined once." Add the equivalent check for enum values, reported as
"Enum value X.Y can only be defined once."

Also enforce that a non-repeatable directive is applied at most once per
schema location during schema validation (the executable-document rule
in validator/rules already covers queries, but the type system was
unchecked). The check is scoped to single authored locations via a
singleLocation flag: a type's own directives are merged across its base
definition and every extension, which the spec treats as distinct
locations, so the merged list is exempt to avoid rejecting a directive
used once per location.

Adds YAML cases covering duplicate enum values (same definition and
across an extension), a repeated non-repeatable directive on a field and
on an enum value, and positive cases (repeatable directive, the same
directive on distinct locations, and a directive on a type plus its
extension).

Fixes vektah#435
@advoretsky advoretsky force-pushed the fix/enum-value-and-directive-uniqueness branch from 45130a0 to 4ed950c Compare June 6, 2026 20:55
@advoretsky

advoretsky commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

removed Claude attribution and fixed formatting

@StevenACoffman StevenACoffman merged commit 807d627 into vektah:master Jun 6, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LoadSchema silently accepts duplicate enum values (no schema-side uniqueness check, unlike object fields)

3 participants