genutils

package
v0.0.0-...-b710084 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// MergePatchStrategy is the name of the Merge patch strategy
	MergePatchStrategy = "merge"
	// ReplacePatchStrategy is the name of the Replace patch strategy
	ReplacePatchStrategy = "replace"
)

Variables

View Source
var (
	// UnionMarker is the definition of the union marker, as defined in https://github.com/kubernetes/enhancements/blob/master/keps/sig-api-machinery/20190325-unions.md#proposal
	UnionMarker = markers.Must(markers.MakeDefinition("union", markers.DescribesType, struct{}{}))
	// UnionDiscriminatorMarker is the definition of the union discriminator marker, as defined in https://github.com/kubernetes/enhancements/blob/master/keps/sig-api-machinery/20190325-unions.md#proposal
	UnionDiscriminatorMarker = markers.Must(markers.MakeDefinition("unionDiscriminator", markers.DescribesField, struct{}{}))
)

Functions

func AddUnionOneOfConstraints

func AddUnionOneOfConstraints(jsonSchema *apiext.JSONSchemaProps, unionDiscriminators []markers.FieldInfo, removeDiscriminators bool, fieldsToSkip ...string)

AddUnionOneOfConstraints adds oneOf constraints in the given Json schema for all the unions, based on the authorized values of the union members

func ContainsPatchStrategy

func ContainsPatchStrategy(field *markers.FieldInfo, strategy string) bool

ContainsPatchStrategy reads the field tags to check whether the given patch strategy is defined

func EditJSONSchema

func EditJSONSchema(jsonSchema *apiext.JSONSchemaProps, visitor Visitor)

EditJSONSchema allows editing a Json Schema by applying the visitor function to each level of the schema.

func GetPatchMergeKey

func GetPatchMergeKey(field *markers.FieldInfo) string

GetPatchMergeKey reads the field tags to retrieve the patch merge key. It returns nil if no such key is defined

func LatestKubeLikeVersion

func LatestKubeLikeVersion(versions []string) string

LatestKubeLikeVersion retrieves the latest version from the the provided versions, according to "kube-like" versioning order. "Kube-like" versions start with a "v", then are followed by a number (the major version), then optionally the string "alpha" or "beta" and another number (the minor version). These are sorted first by GA > beta > alpha (where GA is a version with no suffix such as beta or alpha), and then by comparing major version, then minor version. An example sorted list of versions: v10, v2, v1, v11beta2, v10beta3, v3beta1, v12alpha1, v11alpha2, foo1, foo10.

func RegisterUnionMarkers

func RegisterUnionMarkers(into *markers.Registry) error

RegisterUnionMarkers registers the `union` and `unionDiscriminator` markers

func SortKubeLikeVersion

func SortKubeLikeVersion(versions []string)

SortKubeLikeVersion sorts the provided versions according to "kube-like" versioning order. "Kube-like" versions start with a "v", then are followed by a number (the major version), then optionally the string "alpha" or "beta" and another number (the minor version). These are sorted first by GA > beta > alpha (where GA is a version with no suffix such as beta or alpha), and then by comparing major version, then minor version. An example sorted list of versions: v10, v2, v1, v11beta2, v10beta3, v3beta1, v12alpha1, v11alpha2, foo1, foo10.

func WriteFormattedSourceFile

func WriteFormattedSourceFile(filename string, ctx *genall.GenerationContext, root *loader.Package, writeContents func(*bytes.Buffer))

WriteFormattedSourceFile creates a Go source file in a given package, dumps to it the content provided by the `writeContents` function and formats the result through go/fmt. If formatting cannot be applied (due to some syntax error probably), it returns an error.

Types

type Visitor

type Visitor func(schema *apiext.JSONSchemaProps) (newVisitor Visitor, stop bool)

Visitor is the type of a function that visits one level of Json schema

Jump to

Keyboard shortcuts

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