schema

package
v0.0.0-...-2eef36f Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() *splitter

func NewCommand

func NewCommand(ctx context.Context) *cobra.Command

Types

type Item

type Item struct {
	Properties map[string]extv1.JSONSchemaProps
	// contains filtered or unexported fields
}
func buildOutputMap(groups []Item, propMap map[string]PropMap, chainedProps []string) ([]Item, map[string]extv1.JSONSchemaProps) {
	fmt.Printf("buildOutputMap: groups %d, chainedprops: %v\n", len(groups), chainedProps)
	sortedKeys := getSortedKeys(propMap)
	for _, prop := range sortedKeys {
		// idx is the last entry in the group -> we always append to the last entry of the group
		idx := len(groups) - 1
		if groups[idx].tokens+propMap[prop].tokens < 3500 {
			groups[idx].tokens += propMap[prop].tokens
			groups[idx].Properties = addData(
				groups[idx].Properties,
				append(chainedProps, prop),
				propMap[prop].data,
			)
		} else {
			// if we exceed the tokens we add a new item to the group
			groups = append(groups, Item{tokens: 0, Properties: map[string]extv1.JSONSchemaProps{}}) // append the group

			idx := len(groups) - 1
			if groups[idx].tokens+propMap[prop].tokens < 3500 {
				groups[idx].tokens += propMap[prop].tokens
				groups[idx].Properties = addData(
					groups[idx].Properties,
					append(chainedProps, prop),
					propMap[prop].data,
				)
			} else {
				// if a single item exceeds the token limit we need to split
				// add the initial element to the props w/o the properties
				groups[idx].Properties[prop] = propMap[prop].data
				for k := range groups[idx].Properties[prop].Properties {
					delete(groups[idx].Properties[prop].Properties, k)
				}
				groups, groups[idx].Properties = buildOutputMap(
					groups,
					propMap[prop].propMap,
					append(chainedProps, prop), // append the prop
				)
			}
		}
	}
	idx := len(groups) - 1
	return groups, groups[idx].Properties
}

func NewItem

func NewItem() Item

type PropMap

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

type Runner

type Runner struct {
	Command *cobra.Command
	Ctx     context.Context
}

func NewRunner

func NewRunner(ctx context.Context) *Runner

NewRunner returns a command runner.

Jump to

Keyboard shortcuts

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