-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Bug Report: demonstration of overlays and allOf not playing together nicely #2087
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f64f92b
demonstration of overlays and allOf not playing together nicely
nelzblooket 848ce19
Merge remote-tracking branch 'upstream/main' into pr/2087
mromaszewicz 1d631a0
Reorganize bug test case
mromaszewicz b959de8
fix: honor x-go-type on allOf schemas, stop extension leakage (#2335)
mromaszewicz abb6047
Implement Greptile suggestions
mromaszewicz a31663f
Defensively clone extensions before deleting identity keys
mromaszewicz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
internal/test/extensions/allof-merge-extensions/allof_merge_extensions.gen.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # yaml-language-server: $schema=../../../../configuration-schema.json | ||
| package: allofmergeextensions | ||
| generate: | ||
| models: true | ||
| output: allof_merge_extensions.gen.go | ||
| output-options: | ||
| skip-prune: true | ||
| overlay: | ||
| path: overlay.yaml |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| package allofmergeextensions | ||
|
|
||
| //go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=config.yaml spec.yaml |
14 changes: 14 additions & 0 deletions
14
internal/test/extensions/allof-merge-extensions/overlay.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| overlay: 1.0.0 | ||
| info: | ||
| title: "Example to indicate how to use the OpenAPI Overlay specification (https://github.com/OAI/Overlay-Specification)" | ||
| version: 1.0.0 | ||
| actions: | ||
| - target: $.components.schemas.Client | ||
| update: | ||
| x-go-type: OverlayClient | ||
| - target: $.components.schemas.ClientWithId | ||
| update: | ||
| x-go-type: OverlayClientWithId | ||
| - target: $.components.schemas.BaseOnly | ||
| update: | ||
| x-go-type: OverlayBaseOnly |
20 changes: 20 additions & 0 deletions
20
internal/test/extensions/allof-merge-extensions/overlays.go
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package allofmergeextensions | ||
|
|
||
| // OverlayClient defines model for OverlayClient. | ||
| type OverlayClient struct { | ||
| Name string `json:"name"` | ||
| } | ||
|
|
||
| // OverlayClientWithId defines model for OverlayClientWithId. | ||
| type OverlayClientWithId struct { | ||
| Id int `json:"id"` | ||
| Name string `json:"name"` | ||
| } | ||
|
|
||
| // OverlayBaseOnly is the user-provided override for the BaseOnly schema. | ||
| // DerivedNoOverride composes BaseOnly via allOf and must NOT be aliased | ||
| // to this type — it has to remain its own struct so the Extra field is | ||
| // preserved. | ||
| type OverlayBaseOnly struct { | ||
| Name string `json:"name"` | ||
| } |
38 changes: 38 additions & 0 deletions
38
internal/test/extensions/allof-merge-extensions/overlays_test.go
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package allofmergeextensions | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestAllOfOverlay(t *testing.T) { | ||
| var inner any = Client{} | ||
| _, ok := inner.(OverlayClient) | ||
| if !ok { | ||
| t.Errorf("expected Client to be of type OverlayClient") | ||
| } | ||
|
|
||
| var outer any = ClientWithId{} | ||
| _, ok = outer.(OverlayClientWithId) | ||
| if !ok { | ||
| t.Errorf("expected ClientWithId to be of type OverlayClientWithId") | ||
| } | ||
| } | ||
|
|
||
| // TestBaseOnlyOverlay covers the harder regression path: when only the | ||
| // base schema has x-go-type (via overlay) and the derived allOf schema | ||
| // has no override of its own, the derived schema must still be emitted | ||
| // as a distinct struct containing all composed fields. The previous | ||
| // bug leaked BaseOnly's x-go-type up through the allOf merge, producing | ||
| // `type DerivedNoOverride = OverlayBaseOnly` and silently dropping the | ||
| // Extra field. The struct literal below would fail to compile under | ||
| // the buggy codegen because OverlayBaseOnly has no Extra field. | ||
| func TestBaseOnlyOverlay(t *testing.T) { | ||
| d := DerivedNoOverride{Name: "x", Extra: "y"} | ||
|
|
||
| var asAny any = d | ||
| if _, ok := asAny.(OverlayBaseOnly); ok { | ||
| t.Error("DerivedNoOverride must not be aliased to OverlayBaseOnly; composition would drop the Extra field") | ||
| } | ||
|
|
||
| if d.Name != "x" || d.Extra != "y" { | ||
| t.Errorf("field values not preserved through composed struct: %+v", d) | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| openapi: "3.0.0" | ||
| info: | ||
| version: 1.0.0 | ||
| title: Regression test for allOf + x-go-type interaction (issue #2335) | ||
| components: | ||
| schemas: | ||
| Client: | ||
| type: object | ||
| required: | ||
| - name | ||
| properties: | ||
| name: | ||
| type: string | ||
| ClientWithId: | ||
| allOf: | ||
| - $ref: '#/components/schemas/Client' | ||
| - properties: | ||
| id: | ||
| type: integer | ||
| required: | ||
| - id | ||
|
|
||
| # Second scenario: only the BASE schema receives an x-go-type overlay; | ||
| # the derived allOf schema has no override of its own. It must still | ||
| # be emitted as a distinct struct (with both Name and Extra), not | ||
| # aliased to the base's overlay target. Regression test for the case | ||
| # where the codegen used to leak the base's x-go-type up through the | ||
| # allOf merge, silently dropping the derived schema's extra fields. | ||
| BaseOnly: | ||
| type: object | ||
| required: | ||
| - name | ||
| properties: | ||
| name: | ||
| type: string | ||
| DerivedNoOverride: | ||
| allOf: | ||
| - $ref: '#/components/schemas/BaseOnly' | ||
| - properties: | ||
| extra: | ||
| type: string | ||
| required: | ||
| - extra |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.