openapi3: track Origin on the document root (T)#1184
Merged
Conversation
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>
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.
Why
Every element struct in
openapi3(Info,License,Paths,Operation, ...) carries anOriginso consumers can attach file/line/column to it.Titself does not. As a result the document-root fields (openapi,info,paths,webhooks,jsonSchemaDialect) have no source location, even when the document is loaded withLoader.IncludeOrigin = true. A consumer reporting "openapi is required" can name the file but not the line.What
Add
Origin *OrigintoT. No loader change is needed:yaml3already injects an__origin__entry into the document's root mapping,oasdiff/yamlalready surfaces it as the rootOriginTree.Origin, andapplyOriginsToStructalready sets theOriginfield on any struct that has one taggedjson:"-".Tsimply never had the field.Wire it into the doc-root validation errors. The six constructors for doc-root findings previously passed
nilfor origin (their comments said the loader "doesn't track"*T, now obsolete):newOpenAPIVersionRequirednewInfoRequirednewPathsRequirednewJSONSchemaDialectAbsoluteURIRequirednewWebhooksFieldFor31PlusnewJSONSchemaDialectFieldFor31PlusEach now takes an
origin *Origin, andT.Validatepassesdoc.Origin. The resultingRequiredFieldError/FieldVersionMismatchErrorcarries it like every other typed error.Resolution granularity matches kin's existing
Originmodel:openapi,jsonSchemaDialect) resolve precisely viaOrigin.Fields[name].info,paths,webhooks) fall back toOrigin.Key(the document root) — still a file and position, just not the exact key.Compatibility
Error()strings are unchanged. The new field isjson:"-" yaml:"-", so marshalling is unaffected, andOriginis only populated whenIncludeOriginis set (opt-in, as before).Tests
TestOrigin_T—doc.Originis populated;Origin.Fields["openapi"]resolves to theopenapi:line.TestValidationError_OriginForDocumentRootFields— replacesTestValidationError_OriginNilForDocumentRootFields, which pinned the old "doc-root fields have nil Origin" behavior; now asserts the doc-root error carriesT.Origin.Full suite green;
.github/docs/openapi3.txtregenerated.