openapi3: typed context wrappers for combinator and tag validation#1199
Merged
fenollp merged 4 commits intoJun 3, 2026
Merged
Conversation
This was referenced Jun 3, 2026
fenollp
reviewed
Jun 3, 2026
Follow-up to getkin#1188. Adds scope to two previously unwrapped Validate() sites, in the same vein as the context wrappers from getkin#1183: - oneOf/anyOf/allOf element failures in Schema.validate now carry a SchemaCombinatorElementValidationError naming the combinator. - Per-tag failures in Tags.Validate now carry a TagValidationError naming the tag. Both are category-4 context wrappers: they add scope via Unwrap and do not themselves report a failure, so errors.As still walks through to the inner cluster/leaf. Unlike getkin#1187 these add a scope prefix to Error(), so they are not byte-for-byte; the apis-guru golden fixtures are updated to match. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
These nine goldens were regenerated in a context where the global string format validators (uuid, email, ipv4, ipv6) that TestIssue735 registers were not active, so they captured a different first validation error than a full `go test ./openapi3/` run produces. CI runs the whole package, where those validators are registered, so the affected specs surface uuid/email format errors and the committed goldens no longer matched. Regenerated against the full package run. The nine files now match the baseline on the default branch, and the package test passes and is stable across repeated runs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
SchemaCombinatorElementValidationError wraps each combinator element, so a deeply nested same-combinator schema (common in the AWS specs) rendered "invalid allOf element: " once per nesting level. Collapse a run of same-combinator wrappers in Error() so the scope prints once. The typed chain is unchanged: Unwrap and errors.As still see every level, only the rendered message drops the repeats, and a run of a different combinator (e.g. allOf inside a oneOf) is still shown. Adds a wrapper test for the collapse and chain preservation, and regenerates the affected apis-guru goldens. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
6c1426d to
965b9e8
Compare
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.
Follow-up to #1188, in the same vein as the context wrappers from #1183.
Two
Validate()sites previously propagated their inner error with no scope. This adds typed context wrappers so consumers can tell where a failure occurred viaerrors.As, without parsing the message:SchemaCombinatorElementValidationError{Combinator, Cause}wraps a failure in aoneOf/anyOf/allOfsub-schema, naming which combinator the element belongs to.TagValidationError{Name, Cause}wraps a per-tag failure in the document-roottagslist, naming the tag. (Issue Additional validation cases that could be typed (follow-up to #1187) #1188 sketched this asTagInvalidError{Cause}; renamed to match the*ValidationErrorconvention invalidation_error_context.goand given aNamefield so the wrapper actually says which tag.)Both are category-4 context wrappers: they add scope via
Unwrapand do not themselves report a failure, soerrors.Asstill walks through to the inner cluster/leaf.Backward compatibility: unlike #1187, these add a scope prefix to
Error()(e.g.invalid allOf element: ...,tag "pet": ...), so they are not byte-for-byte. The apis-guru golden fixtures are updated to match (116 files, each just gaining the prefix).Scope: implements items 3 and 4 from #1188. Per the discussion there, the enum-duplicate item is dropped (uniqueness is only a SHOULD), and the required-duplicate item plus tag-name uniqueness are tracked separately as genuine MUST checks.
Closes #1188.