utils

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

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

Go to latest
Published: Feb 11, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyPatch

func ApplyPatch(input []byte, patchFiles []PatchConfig) ([]byte, error)

ApplyPatch applies patches to the raw bytes input.

func ApplyPatchFromRawJSON

func ApplyPatchFromRawJSON(input []byte, patchFiles []PatchConfig) ([]byte, error)

ApplyPatchFromRawJSON applies patches to the raw JSON bytes input without validation request.

func ApplyPatchToHTTPSchema

func ApplyPatchToHTTPSchema(
	input *schema.NDCHttpSchema,
	patchFiles []PatchConfig,
) (*schema.NDCHttpSchema, error)

ApplyPatchToHTTPSchema applies JSON patches to NDC HTTP schema and validate the output.

func BuildUniqueSchemaTypeName

func BuildUniqueSchemaTypeName(sm *rest.NDCHttpSchema, name string) string

BuildUniqueSchemaTypeName builds the unique type name from schema.

func CloneURL

func CloneURL(input *url.URL) *url.URL

CloneURL clones the input URL to a new instance.

func IsContentTypeBinary

func IsContentTypeBinary(contentType string) bool

IsContentTypeBinary checks if the content type relates to binary.

func IsContentTypeJSON

func IsContentTypeJSON(contentType string) bool

IsContentTypeJSON checks if the content type is JSON.

func IsContentTypeMultipartForm

func IsContentTypeMultipartForm(contentType string) bool

IsContentTypeMultipartForm checks the content type relates to multipart form.

func IsContentTypeText

func IsContentTypeText(contentType string) bool

IsContentTypeText checks if the content type relates to text.

func IsContentTypeXML

func IsContentTypeXML(contentType string) bool

IsContentTypeXML checks if the content type is XML.

func IsNullableTypeEncoder

func IsNullableTypeEncoder(input schema.TypeEncoder) bool

IsNullableTypeEncoder checks if the input type is nullable.

func MarshalSchema

func MarshalSchema(content any, format schema.SchemaFileFormat) ([]byte, error)

MarshalSchema encodes the NDC HTTP schema to bytes.

func MaskString

func MaskString(input string) string

MaskString masks the string value for security.

func ReadFileFromPath

func ReadFileFromPath(filePath string) ([]byte, error)

ReadFileFromPath read file content from either file path or URL.

func RemoveYAMLSpecialCharacters

func RemoveYAMLSpecialCharacters(input []byte) string

RemoveYAMLSpecialCharacters remote special characters to avoid YAML unmarshaling error.

func ResolveFilePath

func ResolveFilePath(dir string, filePath string) string

ResolveFilePath resolves file path with directory.

func SliceUnique

func SliceUnique[T cmp.Ordered](input []T) []T

SliceUnique gets unique elements of the input slice.

func SliceUnorderedEqual

func SliceUnorderedEqual[T cmp.Ordered](a []T, b []T) bool

SliceUnorderedEqual compares if both slices are equal with unordered positions.

func SplitStringsAndTrimSpaces

func SplitStringsAndTrimSpaces(input string, sep string) []string

SplitStringsAndTrimSpaces wrap strings.Split with all leading and trailing white space removed.

func StringSliceToCamelCase

func StringSliceToCamelCase(inputs []string) string

StringSliceToCamelCase convert a slice of strings to camelCase.

func StringSliceToConstantCase

func StringSliceToConstantCase(inputs []string) string

StringSliceToConstantCase convert a slice of string to CONSTANT_CASE.

func StringSliceToPascalCase

func StringSliceToPascalCase(inputs []string) string

StringSliceToPascalCase convert a slice of string to PascalCase.

func StringSliceToSnakeCase

func StringSliceToSnakeCase(inputs []string) string

StringSliceToSnakeCase convert a slice of string to snake_case.

func StripHTMLTags

func StripHTMLTags(str string) string

StripHTMLTags aggressively strips HTML tags from a string. It will only keep anything between `>` and `<`.

func ToCamelCase

func ToCamelCase(input string) string

ToCamelCase convert a string to camelCase.

func ToConstantCase

func ToConstantCase(input string) string

ToConstantCase converts string to CONSTANT_CASE.

func ToPascalCase

func ToPascalCase(input string) string

ToPascalCase convert a string to PascalCase.

func ToSnakeCase

func ToSnakeCase(input string) string

ToSnakeCase converts string to snake_case.

func UnwrapNullableType

func UnwrapNullableType(input schema.Type) (schema.TypeEncoder, bool, error)

UnwrapNullableType unwraps the underlying type of the nullable type.

func UnwrapNullableTypeEncoder

func UnwrapNullableTypeEncoder(input schema.TypeEncoder) (schema.TypeEncoder, bool, error)

UnwrapNullableTypeEncoder unwraps the underlying type of the nullable type.

func WalkFiles

func WalkFiles(filePath string, callback func(data []byte) error) error

WalkFiles read one file or many files in a folder if the file path is a directory.

func WrapNullableTypeEncoder

func WrapNullableTypeEncoder(input schema.TypeEncoder) schema.TypeEncoder

WrapNullableTypeEncoder wraps the schema type with nullable.

func WriteSchemaFile

func WriteSchemaFile(outputPath string, content any) error

WriteSchemaFile writes the NDC HTTP schema to file.

Types

type PatchConfig

type PatchConfig struct {
	Path     string        `json:"path"     yaml:"path"`
	Strategy PatchStrategy `json:"strategy" yaml:"strategy" jsonschema:"enum=merge,enum=json6902,default=merge"`
}

PatchConfig the configuration for JSON patch.

type PatchStrategy

type PatchStrategy string

PatchStrategy represents the patch strategy enum.

const (
	// PatchStrategyMerge the merge strategy enum for [RFC 7396] specification
	//
	// [RFC 7396]: https://datatracker.ietf.org/doc/html/rfc7396
	PatchStrategyMerge PatchStrategy = "merge"
	// PatchStrategyJSON6902 the patch strategy enum for [RFC 6902] specification
	//
	// [RFC 6902]: https://datatracker.ietf.org/doc/html/rfc6902
	PatchStrategyJSON6902 PatchStrategy = "json6902"
)

Jump to

Keyboard shortcuts

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