Skip to content

feat(gen): add schema/embed_struct_aliases feature - #1789

Merged
ernado merged 2 commits into
mainfrom
feat/struct-alias-embed
Nov 13, 2026
Merged

ernado merged 2 commits into
mainfrom
feat/struct-alias-embed

Conversation

@ernado

@ernado ernado commented Nov 13, 2026

Copy link
Copy Markdown
Member

Supersedes #1490, split into two commits:

  1. fix: reset nullable arrays when decoding null (from fix: handle struct aliases and reset nullable arrays on null #1490, author kept). Decoding null into an existing value now clears a nullable array instead of keeping stale items. Also regenerates the packages fix: handle struct aliases and reset nullable arrays on null #1490 missed (sample_api_*, ex_github, ex_openai_v2).
  2. feat(gen): add schema/embed_struct_aliases feature (opt-in). Aliases of object schemas are generated as type Foo struct{ Bar } instead of type Foo Bar, so methods of Bar (getters etc.) are promoted. Behind a flag because composite literals change (Foo{Name: …} → Foo{Bar: …}).

With the feature disabled, the generated code is byte-identical to main.

Tested with the feature enabled (code compiles, example tests pass): sample_api, http_requests, form, ex_github (425 BasicError response aliases), ex_k8s, ex_openai_v2, plus new integration test test_embed_struct_aliases (JSON, form, responses, validation, interface satisfaction).

bit0rez and others added 2 commits November 13, 2026 21:53
Generate aliases of object schemas (e.g. per-content-type request
bodies and per-status responses sharing one schema) as structs
embedding the original type instead of defined types:

	type CreatePetOK struct {
		Pet
	}

Methods of the original type are promoted, so aliases satisfy the
same interfaces. The feature is opt-in, since it changes generated
API: composite literals become CreatePetOK{Pet: pet}.

Based on #1490.

Co-authored-by: Ilya Merkulov <iamerkulov@avito.ru>
@ernado
ernado force-pushed the feat/struct-alias-embed branch from f6016ca to 872403e Compare November 13, 2026 20:01
@ernado
ernado merged commit 88ec4c1 into main Nov 13, 2026
17 checks passed
@ernado
ernado deleted the feat/struct-alias-embed branch November 13, 2026 20:10
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