infer_union_discriminator

package
v2.968.13 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProcessUnionType

func ProcessUnionType(logger logging.Logger, typeDef *ast.TypeDef, schemaPath string)

ProcessUnionType processes a single union type and infers its discriminator if possible

func SummarizeMixedTagging

func SummarizeMixedTagging(typeDef *ast.TypeDef) (summary string, ok bool)

SummarizeMixedTagging inspects a union whose discriminator inference failed and reports how its members are tagged, so the silent loss of the forward-compatible Unknown* fallback can be surfaced to the user.

A member is considered "tagged" when it has a required property constrained to known values (const or closed enum) — i.e. it looks like it was designed to participate in a discriminated union.

Returns ok=false (no warning warranted) when:

  • fewer than two members are tagged: a single incidentally-constrained member (e.g. a `status` enum) next to a primitive does not indicate discriminated-union intent, or
  • any member is a map/any type: such a member already absorbs unknown object shapes, so the union is effectively forward-compatible.

Types

type DiscriminatorSpecificity

type DiscriminatorSpecificity int

DiscriminatorSpecificity represents how specific the discriminator values are Lower values are more specific (better)

const (
	// DiscriminatorSpecificityConst indicates discrimination by const values
	// Example: type: "dog" (const) vs type: "cat" (const)
	DiscriminatorSpecificityConst DiscriminatorSpecificity = 1
	// DiscriminatorSpecificitySingle indicates discrimination by single-value enums or const (mixed)
	// Example: type: enum["dog"] vs type: "cat" (const)
	DiscriminatorSpecificitySingle DiscriminatorSpecificity = 2
	// DiscriminatorSpecificityMulti indicates discrimination by multi-value enums
	// Example: type: enum["dog", "puppy"] vs type: enum["cat", "kitten"]
	DiscriminatorSpecificityMulti DiscriminatorSpecificity = 3
	// DiscriminatorSpecificityType indicates discrimination by primitive type only
	// Example: id: string vs id: number
	DiscriminatorSpecificityType DiscriminatorSpecificity = 4
)

Jump to

Keyboard shortcuts

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