namer

package
v2.932.8 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindBestDiscriminators

func FindBestDiscriminators(types [][]string, optionalTieBreakerFunc ...TieBreaker) [][]string

FindBestDiscriminators finds the smallest subset of labels to discriminate between types. For each type it picks the smallest subset of its labels such that no other type has all of those labels.

Top down algorithm:

  1. Start with the name for every type being the concatenation of all the labels.
  2. Try to remove one label at a time from all the types.
  3. If removing the label leaves the type name ambiguous, put the label back. A name is considered ambiguous if it is a subset of another name.

Parameters:

  • types: A list of lists of strings, where each inner list represents a type represented by its labels.
  • optionalTieBreakerFunc: An optional function that can be used to break ties between labels of equal granularity. Return empty string if no preference.

Returns:

  • A list of strings, where each string represents a label that discriminates between the types.

func GetRefName

func GetRefName(reference references.Reference) (string, string)

func NewGoEnumNamer

func NewGoEnumNamer() goEnumNamer

NewGoEnumNamer returns a goEnumNamer configured for Go-like targets.

func StringSetFrom

func StringSetFrom(elements []string, stringToIndex *map[string]int, indexToString *[]string) stringSet

Types

type Features

type Features interface {
	RecordFeatureUsage(ctx context.Context, feature features.Feature)
}

type LabelWithSource

type LabelWithSource struct {
	Label string
	// Sanitized, lowercase, no spaces or underscores - maximized conflict
	LabelNormalized string
	Source          labelSource
}

type Namer

type Namer struct {
	Subsystem *subsystem.Subsystem
}

func New

func New(ss *subsystem.Subsystem) *Namer

func (*Namer) GetFieldName

func (n *Namer) GetFieldName(ctx context.Context, schema *oas3.JSONSchema[oas3.Referenceable], defaultName string, parentComponentRef references.Reference) (string, error)

func (*Namer) GetTypeName

func (n *Namer) GetTypeName(ctx context.Context, s *oas3.JSONSchema[oas3.Referenceable], contextStack ast.ContextStack, parentComponentRef references.Reference, skipNestedRefTracking bool) (string, string, ast.ContextStack, error)

GetTypeName returns the type name and ref type for a schema. The skipNestedRefTracking parameter controls whether the libopenapi nested ref bug behavior should be skipped. Set to true for array items and additionalProperties where the bug doesn't apply.

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

func NewResolver

func NewResolver(subsystem *subsystem.Subsystem, logger logging.Logger) (*Resolver, error)

func (*Resolver) RenameTypesWithDuplicateNames

func (r *Resolver) RenameTypesWithDuplicateNames(ctx context.Context, typeDefs ast.TypeDefs) error

func (*Resolver) ResolveNames

func (r *Resolver) ResolveNames(ctx context.Context, register *register.Register, cfg configuration.ImportConfig, maintainOriginalOrder, resolveEnums bool)

resolveEnums should be set to false for first run to ensure we don't resolve enums before types are resolved

type TieBreaker

type TieBreaker func(labelA, labelB string) string

TieBreaker is a function type used to break ties between labels.

type TypeDefLabels

type TypeDefLabels struct {
	// Where each label came from, not all labels are used in the name
	All []LabelWithSource

	// Labels that were selected as discriminators which are concatenated with the original name
	Selected []*LabelWithSource
}

TypeDefLabels keeps track of all the labels for a TypeDef

Jump to

Keyboard shortcuts

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