openapi3: enforce unique required entries and unique tag names in Validate()#1203
Merged
fenollp merged 3 commits intoJun 5, 2026
Merged
Conversation
…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>
fenollp
requested changes
Jun 4, 2026
| if err := me.emit(&DuplicateTagError{Name: v.Name, Origin: v.Origin}); err != nil { | ||
| return err | ||
| } | ||
| } else { |
Collaborator
There was a problem hiding this comment.
No need for this else here no?
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1200.
Two spec MUSTs that
Validate()did not enforce:requiredentries. JSON Schema 2020-12 §6.5.3 (OAS 3.1) and draft-04 (OAS 3.0) both require the elements of a schema'srequiredarray to be unique.schema.validatenow returns aDuplicateRequiredFieldErroron a repeat.Tags.Validatenow emits aDuplicateTagErroron 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 carryOriginwhen the document was loaded withIncludeOrigin = true.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 hardValidate()error to match the otherDuplicate*checks. If you'd prefer it gated behind aValidationOptioninstead, happy to switch.Tests / fixtures
errors.Asto the typed cluster + message).openapi3package 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