Skip to content

Commit 6570abd

Browse files
plheideGemini
authored andcommitted
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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ only specific validations remain to be fully implemented.
163163
* [ ] Boolean subschemas (§6.7)
164164
* [ ] `allOf`
165165
* [ ] `anyOf`
166-
* [ ] `oneOf`
166+
* [x] `oneOf` (primitive variants only; **note**: object discriminated unions pending)
167167
* [ ] `not`
168168
* [ ] Semantic formats (§7.3)
169169
* [x] Dates and times

0 commit comments

Comments
 (0)