Commit 6570abd
feat: emit typed wrapper for primitive oneOf schemas
Detects schemas where every oneOf variant is a JSON primitive (string,
number, integer, boolean, null) and emits a wrapper Go type instead of
falling through to interface{}. The wrapper holds the decoded value in
a private field and exposes:
UnmarshalJSON - dispatch on json.Decoder.Token kind so a number
that also matches integer cannot ambiguously
satisfy two variants.
MarshalJSON - emit the underlying value or null.
UnmarshalYAML
MarshalYAML
Value() - typed getter returning any.
IsZero() - supports omitzero.
As<Kind>() - typed accessor per declared variant
(AsString / AsNumber / AsBool / IsNull).
Detection wires into both generateDeclaredType (root) and
generateTypeInline (object property) so the wrapper is emitted whether
the oneOf is the root schema or a nested field.
Includes golden-file fixtures under tests/data/oneOfPrimitive/ covering
number+string, number+string+bool, string+null, and an in-field case
that mirrors the original motivating use case (a "value" property
typed as number|string|bool).1 parent bfb04bf commit 6570abd
13 files changed
Lines changed: 1216 additions & 1 deletion
File tree
- pkg/generator
- tests
- data/oneOfPrimitive
- inField
- numStringBool
- numString
- withNull
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | | - | |
| 166 | + | |
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| |||
0 commit comments