util

package
v0.0.0-...-8befeed Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRequestFailed     = errors.New("request failed")
	ErrResponseNotOk     = errors.New("response not ok")
	ErrFailedToCopyBytes = errors.New("failed to copy bytes")
)
View Source
var (
	ErrReadDocumentFromFile   = fmt.Errorf("file is missing")
	ErrOpenDocument           = fmt.Errorf("failed to open document")
	ErrNoFilesSpecified       = fmt.Errorf("no files specified")
	ErrDocumentMerge          = fmt.Errorf("failed to merge documents")
	ErrFailedToPatchDocument  = fmt.Errorf("failed to patch document")
	ErrRenderDocument         = fmt.Errorf("failed to render document")
	ErrGenerateOpenAPIV3Model = fmt.Errorf("failed to generate openapi v3 model")
	ErrWriteDocumentToFile    = fmt.Errorf("failed to write document to file")
	ErrNoGeneratorWithId      = fmt.Errorf("no generator with specified id")
	ErrWriteDocumentToStdout  = fmt.Errorf("failed to write document to stdout")
	ErrJSONMarshal            = fmt.Errorf("failed to marshal into JSON")
	ErrSwagger2OpenAPI30      = fmt.Errorf("failed to convert API spec from Swagger 2.0 to OpenAPI 3.0")
)

Functions

func AppendOrSetString

func AppendOrSetString(destStr *string, srcStr, prefix, separator string)

func CapitalizeAfterChars

func CapitalizeAfterChars(input string, chars []int32, capitalizeFirst bool) string

CapitalizeAfterChars removes the characters in the chars slice and capitalizes the next character

func CommentMultiLine

func CommentMultiLine(comment string, prefix string) string

func CommentSingleLine

func CommentSingleLine(comment string) string

CommentSingleLine returns a single line comment, replacing newlines with spaces

func ContentTypeToShortName

func ContentTypeToShortName(input string) string

func CopyFile

func CopyFile(src, dst string) error

func CountExcluding

func CountExcluding[S ~[]E, E comparable](s S, exclude ...E) int

CountExcluding counts the number of occurrences of elements in a slice, excluding specified values.

func DetectJSONOrYAML

func DetectJSONOrYAML(input []byte) (format string)

func DownloadBytes

func DownloadBytes(url string) ([]byte, error)

func Ellipsize

func Ellipsize(s string, maxLength int) string

Ellipsize truncates a string to the specified maximum length and appends "..." if it was truncated.

func FindCommonStrPrefix

func FindCommonStrPrefix(values []string) string

FindCommonStrPrefix returns the common prefix of all provided strings if any

func FindHighestVersion

func FindHighestVersion(versions []string) string

FindHighestVersion finds the highest semver version in a list of versions

func FirstNonEmptyString

func FirstNonEmptyString(values ...string) string

FirstNonEmptyString returns the first non-empty string from the input strings

func GetMapBool

func GetMapBool(config map[string]interface{}, key string, defaultValue bool) bool

func GetMapMap

func GetMapMap(config map[string]interface{}, key string) map[string]interface{}

func GetMapSliceString

func GetMapSliceString(config map[string]interface{}, key string, defaultSlice []string) []string

func GetMapString

func GetMapString(config map[string]interface{}, key string, defaultValue string) string

func JSONToYAML

func JSONToYAML(jsonData []byte) ([]byte, error)

JSONToYAML converts JSON data to YAML data

func LowerCaseFirstLetter

func LowerCaseFirstLetter(input string) string

LowerCaseFirstLetter lowercases the first letter of the input string

func MergeComponentMap

func MergeComponentMap[V any](destMap, srcMap *orderedmap.Map[string, V], componentType string)

func MergeMaps

func MergeMaps(target, source map[string]interface{})

func ParseURLAPIVersion

func ParseURLAPIVersion(url string) string

func RenameOrderedMapKeys

func RenameOrderedMapKeys[V any](
	m *orderedmap.Map[string, V],
	transformKey func(string) string,
) (mapping map[string]string)

func ResolvePath

func ResolvePath(path string) string

ResolvePath turns the path into an absolute path

func SliceToMapWithKeyFunc

func SliceToMapWithKeyFunc[T any, K comparable](items []T, keyFunc func(T) K) map[K]T

func StripANSI

func StripANSI(str string) string

StripANSI removes ANSI escape codes from a string.

func Ternary

func Ternary[T any](condition bool, trueValue T, falseValue T) T

Ternary evaluates a boolean and returns one of two values based on the condition.

func ToCamelCase

func ToCamelCase(input string) string

func ToKebabCase

func ToKebabCase(input string) string

func ToOperationId

func ToOperationId(method string, url string) string

func ToPascalCase

func ToPascalCase(input string) string

func ToSlug

func ToSlug(input string) string

func ToSnakeCase

func ToSnakeCase(input string) string

func ToUpperCamelCase

func ToUpperCamelCase(input string) string

func ToUpperSnakeCase

func ToUpperSnakeCase(input string) string

func TrimNonASCII

func TrimNonASCII(input string) string

TrimNonASCII removes non-ASCII characters from the input string

func TrimSpaceEachLine

func TrimSpaceEachLine(input string) string

func URLPathParamAddByPrefix

func URLPathParamAddByPrefix(path string) string

URLPathParamAddByPrefix converts path parameters to By{ParamName}

func URLRemovePathParams

func URLRemovePathParams(url string) string

func UpperCaseFirstLetter

func UpperCaseFirstLetter(input string) string

UpperCaseFirstLetter capitalizes the first letter of the input string

func UpperCaseFirstLetterOnly

func UpperCaseFirstLetterOnly(input string) string

UpperCaseFirstLetterOnly capitalizes the first letter and lowercases the rest of the input string

func UppercaseAcronyms

func UppercaseAcronyms(input string) string

UppercaseAcronyms replaces acronyms in the input string with their uppercase form

Types

This section is empty.

Jump to

Keyboard shortcuts

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