gen

command
v1.0.0-beta3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Command gen post-processes the genmodels package after go-jsonschema, doing five things it cannot:

  1. 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.
  2. 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.
  3. Generates a Type<Struct> constant for every body with a "type" const: the single source of truth for the wire discriminator value.
  4. 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.
  5. 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL