Skip to content

feat(sdkgen): Render anyOf properties as closed unions - #7

Merged
jedevc merged 3 commits into
prod-stagingfrom
jedevc/sdkgen-unions
Sep 3, 2026
Merged

feat(sdkgen): Render anyOf properties as closed unions#7
jedevc merged 3 commits into
prod-stagingfrom
jedevc/sdkgen-unions

Conversation

@jedevc

@jedevc jedevc commented Sep 3, 2026

Copy link
Copy Markdown
Member

An anyOf property has no single Go type, so generated plugin SDKs degraded it to interface{} and left callers to hand-roll the encoding — the sandbox plugin's signal has been shipping that way. This ports the closed-union rendering the platform SDK's own templates already do, plus the non-object fix a named array branch needs.

The go-sdk side: unikraft-cloud/go-sdk#234 and unikraft-cloud/go-sdk#250 added the union templates there, and unikraft-cloud/go-sdk#263 is the matching non-object fix.

The openapi-gen bump picks up unikraft-cloud/x#440, so the sandbox command line in https://github.com/unikraft-cloud/plugins/pull/23 generates as CommandLineUnion with CommandLineShell and CommandLineArgs variants.

@jedevc
jedevc force-pushed the jedevc/sdkgen-unions branch from 07bb4fe to 76b1fb1 Compare September 3, 2026 10:22
@jedevc
jedevc marked this pull request as ready for review September 3, 2026 10:23
@jedevc
jedevc requested a review from craciunoiuc September 3, 2026 10:23
The pinned version predates the goUnions helper: it landed on
prod-staging after the commit this was pinned to, despite carrying an
earlier commit date.

Signed-off-by: Justin Chadwell <justin@unikraft.com>
A property declared as an anyOf of two shapes had no single Go type, so
it was degraded to interface{} and callers were left to hand-roll the
encoding. The sandbox plugin's signal parameter has been shipping that
way since it gained a name form.

Ports the union rendering the platform SDK's templates already do: a
marker interface, a named type per branch, and a decoder dispatching on
the JSON kind. Emitted into model.gen.go alongside the models rather
than one file per union, which is the shape sdkgen renders.

Signed-off-by: Justin Chadwell <justin@unikraft.com>
Every named schema that wasn't an enum became a struct, so a component
declaring an array of strings generated an empty struct that no array
could ever decode into.

They are now the type they encode to, under a name of their own. This
only surfaces through unions, where such a schema is the named branch a
union takes its name from, but it was always wrong.

Signed-off-by: Justin Chadwell <justin@unikraft.com>
@jedevc
jedevc force-pushed the jedevc/sdkgen-unions branch from 76b1fb1 to 06b9900 Compare September 3, 2026 10:24

@craciunoiuc craciunoiuc left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good here. Thanks! I love go templates.

Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.com>
Approved-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.com>

@jedevc
jedevc merged commit f18b182 into prod-staging Sep 3, 2026
6 checks passed
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.

2 participants