Repository navigation
fix(overlay): correctly resolve references after Overlay application - #1825
jamietanna merged 6 commits into
Conversation
|
Interesting - would you mind adding an example of this to I've not hit this before, but would be good to see what we're missing |
|
@jamietanna Thank you for the swift review! I agree and removed config flag and enabled it by default. I also added an example to Apparently the issue only occurs if the spec is in a diffent directory then the one oapi-codegen is invoked from. Therefore I put the spec.yaml into the subdirectory |
|
@jamietanna Is the example sufficient or do you need more information? :) |
|
Thanks very much for this @jgraeger - this was a good catch, and I'm classing this as a bug, not a feature 😅 I've pushed a couple of tweaks - will wait for CI then merge Main tweaks:
|
|
Tried this fix on my side and it works well! Is there any ETA for this release @jamietanna? Thanks! |
…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]>
…ath (#2643) * feat(overlay): apply overlays with an in-tree applier on theory/jsonpath 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: #2502 Co-Authored-By: Claude Fable 5.1 <[email protected]> * test(overlay): consolidate overlay tests under internal/test/overlay 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]> * docs(overlay): document RFC 9535 targets and the compatibility option 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]> * fix(overlay): accept overlay 1.1.x documents 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]> * test(overlay): keep only overlay-specific tests under internal/test/overlay Move allof_merge_extensions and external_json_ref back to references/overlays, unchanged from before this branch. They test allOf merging (#2335) and external references (#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]> * docs(test): describe the overlay test category in .greptile/rules.md references/ keeps its overlays, and overlay/ is described as the tests of overlay application itself. Co-Authored-By: Claude Fable 5.1 <[email protected]> --------- Co-authored-by: Claude Fable 5.1 <[email protected]>
When working with overlays, oapi-codegen doesn't support external references, even though they are supported for the same file without overlays.
This PR
adds a new settingconfigures the oapi loader such as the external references are resolved as for a normal file (against the filepath of the spec).resolve-refsto the OverlayOutput configuration. If enabled,