Skip to content

feat(overlay): apply overlays with an in-tree applier on theory/jsonpath - #2643

Merged
mromaszewicz merged 6 commits into
oapi-codegen:mainfrom
mromaszewicz:feat/overlay-theory-jsonpath
Oct 31, 2026
Merged

mromaszewicz merged 6 commits into
oapi-codegen:mainfrom
mromaszewicz:feat/overlay-theory-jsonpath

Conversation

@mromaszewicz

@mromaszewicz mromaszewicz commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

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 under go get -u since go-yit moved to go.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 same go get -u breaks 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 on github.com/theory/jsonpath (MIT, no runtime dependencies, strict RFC 9535). It works on the spec as decoded JSON values with json.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-sequence update on a sequence target is appended (as the specification says) instead of replacing the sequence, and remove on $ is an error instead of a no-op. overlay: 1.1.0 documents are still accepted; copy actions are reported as unsupported.
  • Targets are now RFC 9535 JSONPath. The previous dialect differed in a few ways: filters tested the node itself rather than its children, names containing - or / were allowed after a dot, =~ /re/ existed, and X[*] == v meant "all elements match". An invalid target's error suggests the RFC 9535 form and names the compatibility option.
  • compatibility.overlays-use-yaml-jsonpath (default false) 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.
  • Tests: a new internal/test/overlay/ category holds the tests of overlay application itself. Its rfc9535 and legacy_jsonpath leaves apply the same set of actions, one overlay per dialect, to one shared spec. The existing leaves under references/overlays test 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.
  • Docs: the README overlay section is rewritten in RFC 9535 syntax with a short migration note; configuration-schema.json and docs/configuration.md gain the new option; examples/overlay targets are rewritten and regenerate unchanged.
  • Dependencies: speakeasy-api/openapi and 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-codegen no 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 lint pass; make generate leaves no diff.
  • 27 targets from our fixtures and README, run through the real yaml-jsonpath engine and through translation + theory/jsonpath, select identical node sets.
  • Generating the legacy_jsonpath leaf 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: true to keep the previous behaviour for the whole overlay.

🤖 Generated with Claude Code

mromaszewicz and others added 4 commits October 31, 2026 10:58
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]>
@mromaszewicz
mromaszewicz requested a review from a team as a code owner October 31, 2026 14:59
@socket-security

socket-security Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedgithub.com/​theory/​jsonpath@​v0.12.2100100100100100

View full report

@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The latest changes appear safe to merge; the moved fixtures retain valid file paths and imports.

Summary

Replaces the Speakeasy overlay dependency with an in-tree applier using theory/jsonpath.

  • The generator applies overlays through an in-tree applier.
  • Overlay targets use RFC 9535 by default, with a switch for older syntax.

Reviews (2) · Last reviewed commit: "docs(test): describe the overlay test ca..." · Reviewed by Greptile

mromaszewicz and others added 2 commits October 31, 2026 11:03
…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]>
@mromaszewicz mromaszewicz added the notable changes Used for release notes to highlight these more highly label Oct 31, 2026
@mromaszewicz
mromaszewicz merged commit 36ca5c6 into oapi-codegen:main Oct 31, 2026
17 checks passed
@mromaszewicz
mromaszewicz deleted the feat/overlay-theory-jsonpath branch October 31, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notable changes Used for release notes to highlight these more highly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent YAML libraries

1 participant