Skip to content

openapi3: track Origin on the document root (T)#1184

Merged
fenollp merged 1 commit into
getkin:masterfrom
oasdiff:feat/track-origin-on-t
May 15, 2026
Merged

openapi3: track Origin on the document root (T)#1184
fenollp merged 1 commit into
getkin:masterfrom
oasdiff:feat/track-origin-on-t

Conversation

@reuvenharrison

Copy link
Copy Markdown
Contributor

Why

Every element struct in openapi3 (Info, License, Paths, Operation, ...) carries an Origin so consumers can attach file/line/column to it. T itself does not. As a result the document-root fields (openapi, info, paths, webhooks, jsonSchemaDialect) have no source location, even when the document is loaded with Loader.IncludeOrigin = true. A consumer reporting "openapi is required" can name the file but not the line.

What

Add Origin *Origin to T. No loader change is needed: yaml3 already injects an __origin__ entry into the document's root mapping, oasdiff/yaml already surfaces it as the root OriginTree.Origin, and applyOriginsToStruct already sets the Origin field on any struct that has one tagged json:"-". T simply never had the field.

Wire it into the doc-root validation errors. The six constructors for doc-root findings previously passed nil for origin (their comments said the loader "doesn't track" *T, now obsolete):

  • newOpenAPIVersionRequired
  • newInfoRequired
  • newPathsRequired
  • newJSONSchemaDialectAbsoluteURIRequired
  • newWebhooksFieldFor31Plus
  • newJSONSchemaDialectFieldFor31Plus

Each now takes an origin *Origin, and T.Validate passes doc.Origin. The resulting RequiredFieldError / FieldVersionMismatchError carries it like every other typed error.

Resolution granularity matches kin's existing Origin model:

  • Scalar root fields (openapi, jsonSchemaDialect) resolve precisely via Origin.Fields[name].
  • Object / missing root fields (info, paths, webhooks) fall back to Origin.Key (the document root) — still a file and position, just not the exact key.

Compatibility

Error() strings are unchanged. The new field is json:"-" yaml:"-", so marshalling is unaffected, and Origin is only populated when IncludeOrigin is set (opt-in, as before).

Tests

  • TestOrigin_Tdoc.Origin is populated; Origin.Fields["openapi"] resolves to the openapi: line.
  • TestValidationError_OriginForDocumentRootFields — replaces TestValidationError_OriginNilForDocumentRootFields, which pinned the old "doc-root fields have nil Origin" behavior; now asserts the doc-root error carries T.Origin.

Full suite green; .github/docs/openapi3.txt regenerated.

Every element struct (Info, License, Paths, ...) carries an Origin so
consumers can locate it, but T itself did not. Document-root fields
(openapi, info, paths, webhooks, jsonSchemaDialect) therefore had no
source location, even with Loader.IncludeOrigin enabled.

Add Origin *Origin to T. The existing applyOrigins machinery populates
it automatically from the root __origin__ entry that yaml3 already
injects into the document mapping, so no loader change is needed.

Wire the six doc-root validation-error constructors to accept an origin
and have T.Validate pass doc.Origin. Scalar root fields (openapi,
jsonSchemaDialect) resolve precisely via Origin.Fields; object or
missing root fields fall back to Origin.Key.

Error() strings are unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@fenollp fenollp merged commit dc70f84 into getkin:master May 15, 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.

2 participants