Skip to content

openapi3: typed context wrappers for combinator and tag validation#1199

Merged
fenollp merged 4 commits into
getkin:masterfrom
oasdiff:openapi3-type-validation-followup-1188
Jun 3, 2026
Merged

openapi3: typed context wrappers for combinator and tag validation#1199
fenollp merged 4 commits into
getkin:masterfrom
oasdiff:openapi3-type-validation-followup-1188

Conversation

@reuvenharrison
Copy link
Copy Markdown
Contributor

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 via errors.As, without parsing the message:

  • SchemaCombinatorElementValidationError{Combinator, Cause} wraps a failure in a oneOf / anyOf / allOf sub-schema, naming which combinator the element belongs to.
  • TagValidationError{Name, Cause} wraps a per-tag failure in the document-root tags list, naming the tag. (Issue Additional validation cases that could be typed (follow-up to #1187) #1188 sketched this as TagInvalidError{Cause}; renamed to match the *ValidationError convention in validation_error_context.go and given a Name field so the wrapper actually says which 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.

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.

reuvenharrison and others added 4 commits June 3, 2026 18:27
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>
@fenollp fenollp force-pushed the openapi3-type-validation-followup-1188 branch from 6c1426d to 965b9e8 Compare June 3, 2026 16:27
@fenollp fenollp merged commit 2222e35 into getkin:master Jun 3, 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.

Additional validation cases that could be typed (follow-up to #1187)

2 participants