Documentation
¶
Overview ¶
Command gen post-processes the genmodels package after go-jsonschema, doing five things it cannot:
- Strips the dead `<Type>_<N>` typedefs emitted for each branch of a nullable `anyOf` (e.g. AssetEventResponsePartitionKey_0); the structs use `any`, so these are never referenced.
- Widens every concrete int/float/bool field whose schema default the Go zero value does not satisfy to a pointer (e.g. GetPreviousTI.MapIndex int -> *int, GetAssetEventByAsset.Ascending bool -> *bool). With a plain scalar, ,omitempty drops an explicit zero value (0, false) on encode and the supervisor reapplies its default, reversing the caller's intent; a pointer keeps ,omitempty meaning "absent" for nil while encoding an explicit zero, and on decode nil is the natural "use the default". Strings are exempt: an explicit "" is off-contract for these fields, so decode-side seeding (5) serves them better than a pointer.
- Generates a Type<Struct> constant for every body with a "type" const: the single source of truth for the wire discriminator value.
- Generates EnsureType, which stamps a body's "type" field from its Go type, so the binding lives only in generated code and call sites can't mismatch.
- Generates a DecodeMsgpack per struct carrying a schema default the Go zero value would not satisfy (a non-zero builtin scalar, or any non-null default on a nullable interface{}/enum field), seeding it before decode since msgpack applies no defaults. Pointer-widened fields (see 2) are skipped: their default is simply nil.
Constants and cases key on the generated struct names (read from models.gen.go) matched to the schema's wire values case-insensitively, since go-jsonschema may recapitalize a body (ClearAssetStoreByUri -> ClearAssetStoreByURI) away from its $def name.
Click to show internal directories.
Click to hide internal directories.