Repository navigation
feat(overlay): apply overlays with an in-tree applier on theory/jsonpath - #2643
Merged
mromaszewicz merged 6 commits intoOct 31, 2026
Merged
Conversation
Overlay support came from github.com/speakeasy-api/openapi/overlay, whose JSONPath chain (speakeasy-api/jsonpath, vmware-labs/yaml-jsonpath, dprotaso/go-yit) breaks under `go get -u` since go-yit moved to go.yaml.in/yaml/v4. Replace it with a small Overlay 1.0.0 applier in internal/overlay, built on github.com/theory/jsonpath (MIT, no runtime dependencies, strict RFC 9535), working on the spec as decoded JSON values with json.Number so numeric literals keep their text. The applier mirrors what the previous library did for 1.0.0 overlays: the same validation, actions applied in order, recursive merge of mappings, sequences appended to, other values replaced, removal from the parent, and in strict mode an error listing every action whose target matched nothing. Unlike before, a non-sequence update to a sequence target is appended to it, as the Overlay specification says, instead of replacing the sequence, and removing $ is an error instead of a no-op. Targets are now RFC 9535 JSONPath. An invalid target's error suggests the RFC 9535 form of a target written in the previous dialect, and names the new compatibility.overlays-use-yaml-jsonpath option, which reads targets in the previous dialect by translating them with internal/overlay/legacyjsonpath. The examples/overlay targets are rewritten in RFC 9535; the generated code is unchanged. speakeasy-api/openapi and the modules it pulled in are no longer dependencies of any module; github.com/oasdiff/yaml, already used by kin-openapi, becomes a direct dependency to read overlay YAML. Closes: oapi-codegen#2502 Co-Authored-By: Claude Fable 5.1 <[email protected]>
Overlay tests get a category of their own: the allof_merge_extensions and external_json_ref leaves move there from references/overlays, with their import paths and schema references updated. Two new leaves, rfc9535 and legacy_jsonpath, apply overlays that express the same actions, one in each JSONPath dialect, to one shared spec.yaml: structural and filtered updates, renaming a type, removing a property, removing x-internal schemas, properties, paths and operations, removing by tag and by operationId, merging, appending to sequences and replacing a scalar. The overlays also add oapi-codegen's extensions, several of them through filtered targets: x-go-name on schemas and properties, x-go-type with x-go-type-import, x-go-type-skip-optional-pointer, x-omitempty, x-go-json-ignore and x-order. overlay_test.go checks that both leaves embed the same document, the expected effects on it, and that the generated code honours the added extensions. Operations tagged internal carry no other tags, so the two dialects' readings of a tag comparison agree; the difference is covered by a unit test in internal/overlay/legacyjsonpath. Generating the legacy_jsonpath leaf with the previous, speakeasy-based oapi-codegen gives the same output, apart from the action that appends a mapping to the top-level tags, which that version applied by replacing the sequence. The category list in .greptile/rules.md gains overlay/. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Rewrite the README's overlay example in RFC 9535 JSONPath and note the main differences from the previous dialect, and that compatibility.overlays-use-yaml-jsonpath keeps it. Co-Authored-By: Claude Fable 5.1 <[email protected]>
The previous implementation accepted "overlay: 1.1.0", which it read as a request for RFC 9535 targets. That is now what every overlay gets, so rejecting the version would only break overlays that already moved to it. Copy actions, the other 1.1.0 addition, are reported as unsupported. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Contributor
[Medium impact] The latest changes appear safe to merge; the moved fixtures retain valid file paths and imports. SummaryReplaces the Speakeasy overlay dependency with an in-tree applier using
Reviews (2) · Last reviewed commit: "docs(test): describe the overlay test ca..." · Reviewed by Greptile |
…verlay Move allof_merge_extensions and external_json_ref back to references/overlays, unchanged from before this branch. They test allOf merging (oapi-codegen#2335) and external references (oapi-codegen#1825) and only happen to use an overlay, so they stay in their feature's category; internal/test/overlay holds the tests of overlay application itself. Co-Authored-By: Claude Fable 5.1 <[email protected]>
references/ keeps its overlays, and overlay/ is described as the tests of overlay application itself. Co-Authored-By: Claude Fable 5.1 <[email protected]>
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: #2502
Why
Overlay support came from
github.com/speakeasy-api/openapi/overlay, whose JSONPath chain (speakeasy-api/jsonpath→vmware-labs/yaml-jsonpath→dprotaso/go-yit) breaks undergo get -usince go-yit moved togo.yaml.in/yaml/v4(#2502). Bumping the dependency does not help: Speakeasy's newer versions use a fork of yaml-jsonpath that still imports go-yit statically, so the samego get -ubreaks the new stack too. The only structural fix is to stop depending on that chain.What
internal/overlay: a small OpenAPI Overlay 1.0 applier built ongithub.com/theory/jsonpath(MIT, no runtime dependencies, strict RFC 9535). It works on the spec as decoded JSON values withjson.Number, so numeric literals keep their text, and it drops the YAML round-trip that caused several earlier overlay bugs. Validation, action ordering, recursive merge of mappings, append to sequences, replacement of scalars, removal, and strict-mode reporting of unmatched targets all match the previous behaviour. Two deliberate differences: a non-sequenceupdateon a sequence target is appended (as the specification says) instead of replacing the sequence, andremoveon$is an error instead of a no-op.overlay: 1.1.0documents are still accepted;copyactions are reported as unsupported.-or/were allowed after a dot,=~ /re/existed, andX[*] == vmeant "all elements match". An invalid target's error suggests the RFC 9535 form and names the compatibility option.compatibility.overlays-use-yaml-jsonpath(defaultfalse) reads every target in the previous dialect by translating it to RFC 9535 (internal/overlay/legacyjsonpath). It is an all-or-nothing switch for the whole overlay; there is no per-target dialect detection. The translation's known limitations are in that package's doc.internal/test/overlay/category holds the tests of overlay application itself. Itsrfc9535andlegacy_jsonpathleaves apply the same set of actions, one overlay per dialect, to one shared spec. The existing leaves underreferences/overlaystest other features that happen to use an overlay and stay where they are. The test asserts both produce identical embedded specs and that extensions added through overlays (x-go-name,x-go-type+x-go-type-import,x-go-type-skip-optional-pointer,x-omitempty,x-go-json-ignore,x-order), several via filtered targets, are honoured in the generated code.configuration-schema.jsonanddocs/configuration.mdgain the new option;examples/overlaytargets are rewritten and regenerate unchanged.speakeasy-api/openapiand everything it pulled in (its jsonpath, the yaml-jsonpath fork, go-yit, jsonschema/v6, gcf-go) are gone from all three modules.go list -deps ./cmd/oapi-codegenno longer contains any of them.github.com/oasdiff/yaml, already used by kin-openapi, becomes a direct dependency for reading overlay YAML. No Go version change.Verification
make tidy && make test && make generate && make lintpass;make generateleaves no diff.legacy_jsonpathleaf with the previous Speakeasy-based binary gives byte-identical output.Release note
The overlay implementation changed: action targets are now RFC 9535 JSONPath. Overlays written in the previous dialect should be updated, or set
compatibility.overlays-use-yaml-jsonpath: trueto keep the previous behaviour for the whole overlay.🤖 Generated with Claude Code