Skip to content

Conversation

@clarkjohnd
Copy link

@clarkjohnd clarkjohnd commented Sep 12, 2025

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:

    WorkItemView:
      x-go-allof-embed-refs: true
      allOf:
      - $ref: '#/components/schemas/WorkItem'
      - type: object
        properties:
          project:
            $ref: '#/components/schemas/ProjectSummary'
          organisation:
            $ref: '#/components/schemas/OrganisationSummary'
type WorkItemView struct {
    // all fields duplicated from root component WorkItem
    // ...
    // ...
    Organisation *OrganisationSummary `json:"organisation,omitempty"`
    Project      *ProjectSummary      `json:"project,omitempty"`
}

to:

type WorkItemView struct {
    // Embedded struct due to allOf(#/components/schemas/WorkItem)
    WorkItem `yaml:",inline"`
    // Embedded fields due to inline allOf schema
    Organisation *OrganisationSummary `json:"organisation,omitempty"`
    Project      *ProjectSummary      `json:"project,omitempty"`
}

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.

lahabana and others added 3 commits September 11, 2025 22:49
This is useful when working with extending APIs

Signed-off-by: Charly Molter <charly.molter@konghq.com>
@clarkjohnd clarkjohnd requested a review from a team as a code owner September 12, 2025 14:29
@kusari-inspector
Copy link

Kusari Inspector

Kusari Analysis Results:

Proceed with these changes

✅ No Flagged Issues Detected
All values appear to be within acceptable risk parameters.

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.


@kusari-inspector rerun - Trigger a re-analysis of this PR
@kusari-inspector feedback [your message] - Send feedback to our AI and team
See Kusari's documentation for setup and configuration.
Commit: 5389038, performed at: 2025-09-12T14:29:19Z

Found this helpful? Give it a 👍 or 👎 reaction!

@marcoabreu
Copy link

Would love to see this merged, good job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants