Skip to content

openapi3: enforce unique required entries and unique tag names in Validate()#1203

Merged
fenollp merged 3 commits into
getkin:masterfrom
oasdiff:feat/validate-unique-required-and-tags
Jun 5, 2026
Merged

openapi3: enforce unique required entries and unique tag names in Validate()#1203
fenollp merged 3 commits into
getkin:masterfrom
oasdiff:feat/validate-unique-required-and-tags

Conversation

@reuvenharrison
Copy link
Copy Markdown
Contributor

Closes #1200.

Two spec MUSTs that Validate() did not enforce:

  1. Unique required entries. JSON Schema 2020-12 §6.5.3 (OAS 3.1) and draft-04 (OAS 3.0) both require the elements of a schema's required array to be unique. schema.validate now returns a DuplicateRequiredFieldError on a repeat.
  2. Unique tag names. The OpenAPI Object says "Each tag name in the list MUST be unique." Tags.Validate now emits a DuplicateTagError on a repeat (empty names are left to per-tag validation, not flagged here).

Both new error types follow the existing Duplicate* cluster pattern (cf. DuplicateParameterError / DuplicateOperationIDError) and carry Origin when the document was loaded with IncludeOrigin = true.

# now rejected
type: object
required: [id, id]
properties: { id: { type: string } }
# now rejected
tags:
  - name: pet
  - name: pet

Behavior change

As called out in #1200, this is a behavior change: documents carrying these duplicates that passed Validate() before will now fail. It is wired as a hard Validate() error to match the other Duplicate* checks. If you'd prefer it gated behind a ValidationOption instead, happy to switch.

Tests / fixtures

  • Unit tests for both errors (errors.As to the typed cluster + message).
  • The full openapi3 package passes, and no apis-guru golden fixture changed (the corpus trips neither check), so there is no fixture churn to review.

🤖 Generated with Claude Code

reuvenharrison and others added 2 commits June 4, 2026 15:08
…idate()

Two spec MUSTs that Validate() did not check (getkin#1200):

- The elements of a schema's `required` array MUST be unique (JSON Schema
  2020-12 §6.5.3 for OAS 3.1, draft-04 for OAS 3.0). schema.validate now
  returns DuplicateRequiredFieldError on a repeat.
- Each tag name in the document-root `tags` list MUST be unique (OpenAPI
  Object). Tags.Validate now emits DuplicateTagError on a repeat.

Both follow the existing Duplicate* cluster pattern (cf. DuplicateParameterError)
and carry Origin when the document was loaded with IncludeOrigin.

This is a behavior change: documents carrying these duplicates that passed
Validate() before now fail. No apis-guru golden fixture changed (the corpus
trips neither check).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
go doc dump (docs.sh) now lists DuplicateRequiredFieldError and
DuplicateTagError, which the CI `git diff --exit-code` gate after generation
requires to be committed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread openapi3/tag.go Outdated
if err := me.emit(&DuplicateTagError{Name: v.Name, Origin: v.Origin}); err != nil {
return err
}
} else {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this else here no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Re-inserting an existing key into the seen set is a no-op, so the seen update
can run unconditionally after the duplicate check instead of in an else.
No behavior change. (review feedback)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@fenollp fenollp merged commit 6c01290 into getkin:master Jun 5, 2026
5 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.

openapi3: Validate() does not enforce two spec MUSTs (unique required entries, unique tag names)

2 participants