Documentation
¶
Index ¶
- func FindBestDiscriminators(types [][]string, optionalTieBreakerFunc ...TieBreaker) [][]string
- func GetRefName(reference references.Reference) (string, string)
- func NewGoEnumNamer() goEnumNamer
- func StringSetFrom(elements []string, stringToIndex *map[string]int, indexToString *[]string) stringSet
- type Features
- type LabelWithSource
- type Namer
- type Resolver
- type TieBreaker
- type TypeDefLabels
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:
- Start with the name for every type being the concatenation of all the labels.
- Try to remove one label at a time from all the types.
- 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.
Types ¶
type LabelWithSource ¶
type 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 (*Resolver) RenameTypesWithDuplicateNames ¶
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 ¶
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