Documentation
¶
Index ¶
- Constants
- Variables
- func AppendSliceFirstNonEmpty[T comparable](data []T, value ...T) []T
- func Base64Encode(input string) string
- func CleanupServiceFileStructure(servicePath string) error
- func CopyDirectory(src, dest string) error
- func CopyFile(srcPath, destPath string) error
- func CopyNestedMap(source map[string]map[string]any) map[string]map[string]any
- func ExtractPlaceholders(input string) []string
- func ExtractZip(zipReader *zip.Reader, targetDir string, onlyPrefixes []string) error
- func GetFileContentsFromURL(client *http.Client, url string) ([]byte, string, error)
- func GetFileHash(file io.Reader) string
- func GetRandomKeyFromMap[T any](m map[string]T) string
- func GetRandomSliceValue[T any](slice []T) T
- func GetSliceMaxRepetitionNumber[T comparable](values []T) int
- func GetSortedMapKeys[T any](content map[string]T) []string
- func GetValueByDottedPath(data map[string]any, path string) any
- func IsEmptyDir(path string) bool
- func IsInteger(value any) bool
- func IsJsonType(content []byte) bool
- func IsMap(i any) bool
- func IsNumber(value any) bool
- func IsSliceUnique[T comparable](path []T) bool
- func IsValidHTTPVerb(verb string) bool
- func IsValidURLResource(urlPattern string) bool
- func IsYamlType(content []byte) bool
- func MapToURLEncodedForm(data map[string]any) string
- func MaybeRegexPattern(input string) bool
- func RemovePointer[T bool | float64 | int64 | uint64](value *T) T
- func SaveFile(filePath string, data []byte) error
- func SetValueByDottedPath(data map[string]any, path string, value any)
- func SliceContains[T comparable](slice []T, value T) bool
- func SliceDeleteAtIndex[T any](slice []T, index int) []T
- func SliceUnique[T comparable](slice []T) []T
- func ToFloat64(value any) (float64, error)
- func ToInt32(value any) (int32, bool)
- func ToInt64(value any) (int64, bool)
- func ToSnakeCase(input string) string
- func ToString(value any) string
- func ValidateStringWithPattern(input string, pattern string) bool
- type Schema
Constants ¶
const ( TypeArray = "array" TypeBoolean = "boolean" TypeInteger = "integer" TypeNumber = "number" TypeObject = "object" TypeString = "string" )
Variables ¶
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 CleanupServiceFileStructure ¶ added in v0.1.39
CleanupServiceFileStructure removes empty directories from the service directory.
func CopyDirectory ¶ added in v0.1.39
CopyDirectory copies a directory recursively.
func CopyFile ¶ added in v0.1.39
CopyFile copies a file from srcPath to destPath. If the destination directory doesn't exist, it will be created.
func CopyNestedMap ¶
CopyNestedMap returns a copy of the given map with all nested maps copied as well.
func ExtractPlaceholders ¶
ExtractPlaceholders extracts all placeholders including curly brackets from a pattern.
func ExtractZip ¶ added in v0.1.39
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 GetFileHash ¶ added in v0.1.39
GetFileHash gets the SHA256 hash of a file.
func GetRandomKeyFromMap ¶
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 ¶
GetSortedMapKeys returns the keys of the given map sorted alphabetically.
func GetValueByDottedPath ¶
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
IsEmptyDir checks if a directory is empty.
func IsJsonType ¶ added in v0.1.39
IsJsonType checks if the content is a valid JSON document.
func IsSliceUnique ¶
func IsSliceUnique[T comparable](path []T) bool
IsSliceUnique returns true if all values in the given slice are unique.
func IsValidHTTPVerb ¶
IsValidHTTPVerb checks if the given HTTP verb is valid.
func IsValidURLResource ¶
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
IsYamlType checks if the content is a valid YAML document.
func MapToURLEncodedForm ¶
MapToURLEncodedForm converts a map to a URL encoded form. e.g. {"a": {"b": 1}} becomes "a[b]=1"
func MaybeRegexPattern ¶
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 ¶
RemovePointer removes pointer from the boolean or numeric value
func SaveFile ¶ added in v0.1.39
SaveFile saves a file to the specified path. If the destination directory doesn't exist, it will be created.
func SetValueByDottedPath ¶
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 ¶
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 ToSnakeCase ¶
ToSnakeCase converts a string to snake_case case
func ValidateStringWithPattern ¶
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.