| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
This is useful when working with extending APIs Signed-off-by: Charly Molter <charly.molter@konghq.com>
Kusari Analysis Results:
No pinned version dependency changes, code issues or exposed secrets detected! Note View full detailed analysis result for more information on the output and the checks that were run.
Found this helpful? Give it a 👍 or 👎 reaction! |
Sorry, something went wrong.
|
Would love to see this merged, good job! |
Sorry, something went wrong.
Sorry, something went wrong.
Greptile SummaryThis PR adds support for struct embedding in allOf compositions via the x-go-allof-embed-refs: true extension. The implementation allows referenced schemas to be embedded as structs rather than having their fields duplicated, enabling better code reuse for extendable types. Key Changes:
Potential Issue:
Confidence Score: 3/5
Important Files Changed
Last reviewed commit: b109546 |
Sorry, something went wrong.
| allOf: | ||
| - $ref: "#/components/schemas/PersonProperties" | ||
| - required: [ FirstName, LastName ] | ||
| - $ref: "#/components/schemas/FirstName" |
There was a problem hiding this comment.
Potential overlapping field issue: both PersonProperties (line 34) and FirstName (line 36) define a FirstName property. The validation logic in merge_schemas.go:215-219 checks for overlapping fields and should reject this when x-go-allof-embed-refs: true is set. Verify that this test case generates correctly or if it needs to be updated.
Sorry, something went wrong.
|
This is a very tricky change, despite seeming simple, and I think we need lots more testing to ensure it doesn't break behavior. When you embed structs, you also embed their methods. In your example, say, WorkItem is a complex schema with a complex structure that requires implementing the json.Marshaler and json.Unmarshaler interfaces, which we do automatically. Due to this embedding, when the json library is doing its unarshaling, it will find that WorkItemView has JSON marshaling specializations, and it will call those, so it will attempt to unmarshal WorkItemView using WorkItem.UnmarshalJSON. I've hit these problems before. Dynamic typing in a stricly typed language is quite hard, and allOf/anyOf/oneOf has been the most difficult thing to support in oapi-codegen. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
A rebase of 2 year old PR (#1295) (main code courtesy of Lahabana!) to the latest main branch with a very small tweak to error handling. This is a feature I find very useful. Also addresses #1622 (comment), where the original draft PR was linked.
Using one of my own app examples, adding x-go-allof-embed-refs: true to allOf components:
to:
This helps build reusable functions for "extendable" types - e.g. I have a function to populate WorkItem - now if I extend work item to add other fields for other API paths (like above example), I can reuse the same function to manage the WorkItem nested struct, rather than rebuilding an entire new function for the extended type.