generator

package
v1.25.1 Latest Latest
Warning

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

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

Documentation

Overview

Package generator generates consistent breaking change and changelog message definitions.

Overview

The generator package creates message IDs and localized message templates from a declarative YAML configuration. This ensures consistency across all checker rules and simplifies adding new change types.

Usage

Generate messages from a YAML tree definition:

messages, err := generator.Generate(generator.GetTree("changes.yaml"))

YAML Structure

The input YAML defines a tree of changes with:

  • changes: the main change hierarchy (paths, operations, parameters, etc.)
  • components: reusable change definitions referenced via $ref

Each change node can have:

  • actions: map of action types (add, remove, change) to objects affected
  • nextLevel: nested changes for child elements
  • excludeFromHierarchy: whether to skip this level in message hierarchy

Generated Output

For each action/object combination, the generator produces:

  • A kebab-case ID (e.g., "request-property-pattern-added")
  • A human-readable message template with placeholders (e.g., "added pattern %s to property %s")

Advantages

  • Consistent naming: IDs follow predictable patterns based on hierarchy
  • Consistent messages: templates use standard grammar and structure
  • Extensible: add new change types by editing YAML, not code
  • Maintainable: single source of truth for all message definitions

Status

This is an internal tool. The generated output (messages.yaml) can replace the manually written messages in localizations_src. Additional work is needed to ensure full coverage and handle translations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(getter Getter) ([]string, error)

func GetTree

func GetTree(file string) func() (MessageGenerator, error)

Types

type Actions

type Actions map[string]Objects

type ChangeMap

type ChangeMap map[string]Changes

type ChangeTree

type ChangeTree struct {
	Changes    ChangeMap `yaml:"changes"`
	Components ChangeMap `yaml:"components"`
}

type Changes

type Changes struct {
	Ref                  string    `yaml:"$ref"`
	ExcludeFromHierarchy bool      `yaml:"excludeFromHierarchy"`
	Actions              Actions   `yaml:"actions"`
	NextLevel            ChangeMap `yaml:"nextLevel"`
}

type Getter

type Getter func() (MessageGenerator, error)

type IValueSet

type IValueSet interface {
	// contains filtered or unexported methods
}

type MessageGenerator

type MessageGenerator interface {
	// contains filtered or unexported methods
}

type Object

type Object struct {
	Hierarchy            []string `yaml:"hierarchy"`
	Names                []string `yaml:"names"`
	Adverbs              []string `yaml:"adverbs"`
	StartWithName        bool     `yaml:"startWithName"`
	PredicativeAdjective string   `yaml:"predicativeAdjective"`
	AttributiveAdjective string   `yaml:"attributiveAdjective"`
}

type Objects

type Objects []Object

type ValueSet

type ValueSet struct {
	AttributiveAdjective string // attributive adjectives are added before the object
	PredicativeAdjective string // predicative adjectives are added after the object
	Hierarchy            []string
	Names                []string
	Actions              []string
	Adverbs              []string
}

type ValueSetA

type ValueSetA ValueSet

ValueSetA messages start with the object for example: "api was removed without deprecation"

type ValueSetB

type ValueSetB ValueSet

ValueSetB messages start with the action for example: "removed %s request parameter %s"

type ValueSetList

type ValueSetList []ValueSet

type ValueSets

type ValueSets []IValueSet

Jump to

Keyboard shortcuts

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