grafana / grok

Grafana Object Development Kit
Apache License 2.0
50 stars 1 forks source link

Fix generated Go types when they include embedded structs #11

Open sdboyer opened 1 year ago

sdboyer commented 1 year ago

Currently, generated Go structs that include embeddings in the original CUE come out like this:

// PanelOptions defines model for PanelOptions.
type PanelOptions struct {
    // Embedded struct due to allOf(#/components/schemas/OptionsWithLegend)
    OptionsWithLegend `yaml:",inline"`
    // Embedded struct due to allOf(#/components/schemas/OptionsWithTooltip)
    OptionsWithTooltip `yaml:",inline"`
    // Embedded struct due to allOf(#/components/schemas/OptionsWithTextFormatting)
    OptionsWithTextFormatting `yaml:",inline"`
    // Embedded fields due to inline allOf schema
}

There SHOULD be more fields after the last comment - the ones declared directly on the object, not embedded. But there aren't. We've (more or less) fixed this issue in core, and now need to fix it out here in grok.

AgnesToulet commented 1 year ago

@sdboyer How did you fix it in core? (And what exactly did you mean by core?)

I think this should be fixed with: https://github.com/deepmap/oapi-codegen/pull/717 but it's open for a while now and seems stuck.

sdboyer commented 1 year ago

iirc the fix was via a hack with ExpandReferences that I added to the core Go types jenny, but I'll have to look.

more hack than true fix, though. still not completely happy with it.