Repository navigation
feat(gen): add schema/embed_struct_aliases feature - #1789
Merged
Merged
Conversation
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
force-pushed
the
feat/struct-alias-embed
branch
from
November 13, 2026 20:01
f6016ca to
872403e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #1490, split into two commits:
nullinto 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).schema/embed_struct_aliasesfeature (opt-in). Aliases of object schemas are generated astype Foo struct{ Bar }instead oftype Foo Bar, so methods ofBar(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
BasicErrorresponse aliases), ex_k8s, ex_openai_v2, plus new integration testtest_embed_struct_aliases(JSON, form, responses, validation, interface satisfaction).