types

package
v0.1.45 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeArray   = "array"
	TypeBoolean = "boolean"
	TypeInteger = "integer"
	TypeNumber  = "number"
	TypeObject  = "object"
	TypeString  = "string"
)

Variables

View Source
var PlaceholderRegex = regexp.MustCompile(`\{[^\}]*\}`)

Functions

func AppendSliceFirstNonEmpty

func AppendSliceFirstNonEmpty[T comparable](data []T, value ...T) []T

AppendSliceFirstNonEmpty appends the first non-empty value to the given slice.

func Base64Encode

func Base64Encode(input string) string

func CleanupServiceFileStructure added in v0.1.39

func CleanupServiceFileStructure(servicePath string) error

CleanupServiceFileStructure removes empty directories from the service directory.

func CopyDirectory added in v0.1.39

func CopyDirectory(src, dest string) error

CopyDirectory copies a directory recursively.

func CopyFile added in v0.1.39

func CopyFile(srcPath, destPath string) error

CopyFile copies a file from srcPath to destPath. If the destination directory doesn't exist, it will be created.

func CopyNestedMap

func CopyNestedMap(source map[string]map[string]any) map[string]map[string]any

CopyNestedMap returns a copy of the given map with all nested maps copied as well.

func ExtractPlaceholders

func ExtractPlaceholders(input string) []string

ExtractPlaceholders extracts all placeholders including curly brackets from a pattern.

func ExtractZip added in v0.1.39

func ExtractZip(zipReader *zip.Reader, targetDir string, onlyPrefixes []string) error

ExtractZip extracts a zip archive to a target directory. onlyPrefixes is a list of prefixes that are allowed to be extracted.

func GetFileContentsFromURL added in v0.1.39

func GetFileContentsFromURL(client *http.Client, url string) ([]byte, string, error)

func GetFileHash added in v0.1.39

func GetFileHash(file io.Reader) string

GetFileHash gets the SHA256 hash of a file.

func GetRandomKeyFromMap

func GetRandomKeyFromMap[T any](m map[string]T) string

GetRandomKeyFromMap returns a random key from the given map.

func GetRandomSliceValue

func GetRandomSliceValue[T any](slice []T) T

GetRandomSliceValue returns a random value from the given slice.

func GetSliceMaxRepetitionNumber

func GetSliceMaxRepetitionNumber[T comparable](values []T) int

GetSliceMaxRepetitionNumber returns the maximum number of non-unique values in the given slice.

func GetSortedMapKeys

func GetSortedMapKeys[T any](content map[string]T) []string

GetSortedMapKeys returns the keys of the given map sorted alphabetically.

func GetValueByDottedPath

func GetValueByDottedPath(data map[string]any, path string) any

GetValueByDottedPath returns the value of the given path in the given map. If the path does not exist, nil is returned. e.g. GetValueByDottedPath(map[string]any{"a": map[string]any{"b": 1}}, "a.b") returns 1

func IsEmptyDir added in v0.1.39

func IsEmptyDir(path string) bool

IsEmptyDir checks if a directory is empty.

func IsInteger

func IsInteger(value any) bool

IsInteger checks if the value is an integer

func IsJsonType added in v0.1.39

func IsJsonType(content []byte) bool

IsJsonType checks if the content is a valid JSON document.

func IsMap

func IsMap(i any) bool

IsMap checks if the value is a map

func IsNumber

func IsNumber(value any) bool

IsNumber checks if the value is a number: integer or float

func IsSliceUnique

func IsSliceUnique[T comparable](path []T) bool

IsSliceUnique returns true if all values in the given slice are unique.

func IsValidHTTPVerb

func IsValidHTTPVerb(verb string) bool

IsValidHTTPVerb checks if the given HTTP verb is valid.

func IsValidURLResource

func IsValidURLResource(urlPattern string) bool

IsValidURLResource checks if the given URL resource pattern is valid: placeholders contain only alphanumeric characters, underscores, and hyphens

func IsYamlType added in v0.1.39

func IsYamlType(content []byte) bool

IsYamlType checks if the content is a valid YAML document.

func MapToURLEncodedForm

func MapToURLEncodedForm(data map[string]any) string

MapToURLEncodedForm converts a map to a URL encoded form. e.g. {"a": {"b": 1}} becomes "a[b]=1"

func MaybeRegexPattern

func MaybeRegexPattern(input string) bool

MaybeRegexPattern checks if the input string contains any special characters. This is a simple good-enough check to see if the context key is a regex pattern.

func RemovePointer

func RemovePointer[T bool | float64 | int64 | uint64](value *T) T

RemovePointer removes pointer from the boolean or numeric value

func SaveFile added in v0.1.39

func SaveFile(filePath string, data []byte) error

SaveFile saves a file to the specified path. If the destination directory doesn't exist, it will be created.

func SetValueByDottedPath

func SetValueByDottedPath(data map[string]any, path string, value any)

SetValueByDottedPath sets the value of the given path in the given map. If the path does not exist, it is created. e.g. SetValueByDottedPath(map[string]any{"a": map[string]any{"b": 1}}, "a.b", 2) sets the value of "a.b" to 2 ! This function modifies the given map.

func SliceContains

func SliceContains[T comparable](slice []T, value T) bool

SliceContains returns true if the given slice contains the given value.

func SliceDeleteAtIndex

func SliceDeleteAtIndex[T any](slice []T, index int) []T

SliceDeleteAtIndex deletes an element from a slice at the given index and preserves the order of the slice.

func SliceUnique

func SliceUnique[T comparable](slice []T) []T

SliceUnique returns a new slice with unique values from the given slice.

func ToFloat64

func ToFloat64(value any) (float64, error)

ToFloat64 converts underlying value to float64 if it can be represented as float64

func ToInt32

func ToInt32(value any) (int32, bool)

ToInt32 converts underlying value to int32 if it can be represented as int32

func ToInt64

func ToInt64(value any) (int64, bool)

ToInt64 converts underlying value to int64 if it can be represented as int64

func ToSnakeCase

func ToSnakeCase(input string) string

ToSnakeCase converts a string to snake_case case

func ToString

func ToString(value any) string

func ValidateStringWithPattern

func ValidateStringWithPattern(input string, pattern string) bool

ValidateStringWithPattern checks if the input string matches the given pattern.

Types

type Schema added in v0.1.39

type Schema struct {
	Type string `json:"type,omitempty" yaml:"type,omitempty"`

	// in 3.1 examples can be an array (which is recommended)
	Examples []any `json:"examples,omitempty" yaml:"examples,omitempty"`

	// items can be a schema in 2.0, 3.0 and 3.1 or a bool in 3.1
	Items *Schema `json:"items,omitempty" yaml:"items,omitempty"`

	// Compatible with all versions
	MultipleOf    float64            `json:"multipleOf,omitempty" yaml:"multipleOf,omitempty"`
	Maximum       float64            `json:"maximum,omitempty" yaml:"maximum,omitempty"`
	Minimum       float64            `json:"minimum,omitempty" yaml:"minimum,omitempty"`
	MaxLength     int64              `json:"maxLength,omitempty" yaml:"maxLength,omitempty"`
	MinLength     int64              `json:"minLength,omitempty" yaml:"minLength,omitempty"`
	Pattern       string             `json:"pattern,omitempty" yaml:"pattern,omitempty"`
	Format        string             `json:"format,omitempty" yaml:"format,omitempty"`
	MaxItems      int64              `json:"maxItems,omitempty" yaml:"maxItems,omitempty"`
	MinItems      int64              `json:"minItems,omitempty" yaml:"minItems,omitempty"`
	MaxProperties int64              `json:"maxProperties,omitempty" yaml:"maxProperties,omitempty"`
	MinProperties int64              `json:"minProperties,omitempty" yaml:"minProperties,omitempty"`
	Required      []string           `json:"required,omitempty" yaml:"required,omitempty"`
	Enum          []any              `json:"enum,omitempty" yaml:"enum,omitempty"`
	Properties    map[string]*Schema `json:"properties,omitempty" yaml:"properties,omitempty"`
	Not           *Schema            `json:"not,omitempty" yaml:"not,omitempty"`
	Default       any                `json:"default,omitempty" yaml:"default,omitempty"`
	Nullable      bool               `json:"nullable,omitempty" yaml:"nullable,omitempty"`
	ReadOnly      bool               `json:"readOnly,omitempty" yaml:"readOnly,omitempty"`
	WriteOnly     bool               `json:"writeOnly,omitempty" yaml:"writeOnly,omitempty"`
	Example       any                `json:"example,omitempty" yaml:"example,omitempty"`
	Deprecated    bool               `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
}

Schema is a struct that represents an OpenAPI schema. It is compatible with all versions of OpenAPI. All schema provider should implement the Document and KinOperation interfaces. This provides a unified way to work with different OpenAPI parsers.

Jump to

Keyboard shortcuts

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