{"modulePath":"github.com/devdraftengineer/devdraft-go","version":"v0.0.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package param\n\n## Constants\n\n```go\nconst Omit forceOmit = -1\n```\nOmit can be used with \\[metadata.SetExtraFields] to ensure that a required field is omitted. This is useful as an escape hatch for when a required is unwanted for some unexpected reason.\n\n## Variables\n\n```go\nvar EscapeSJSONKey = strings.NewReplacer(\"\\\\\", \"\\\\\\\\\", \"|\", \"\\\\|\", \"#\", \"\\\\#\", \"@\", \"\\\\@\", \"*\", \"\\\\*\", \".\", \"\\\\.\", \":\", \"\\\\:\", \"?\", \"\\\\?\").Replace\n```\nIf we want to set a literal key value into JSON using sjson, we need to make sure it doesn't have special characters that sjson interprets as a path.\n\n## Functions\n\n```go\nfunc IsNull[T any](v T) bool\n```\nIsNull returns true if v was set to the JSON value null.\n\nTo set a param to null use [NullStruct](#NullStruct), [Null](#Null), [NullMap](#NullMap), or [NullSlice](#NullSlice) depending on the type of v.\n\nIsNull returns false if the value is omitted.\n\n```go\nfunc IsOmitted(v any) bool\n```\nIsOmitted returns true if v is the zero value of its type.\n\nIf IsOmitted is true, and the field uses a \\`json:\"...,omitzero\"\\` tag, the field will be omitted from the request.\n\nIf v is set explicitly to the JSON value \"null\", IsOmitted returns false.\n\n```go\nfunc MarshalObject[T ParamStruct](f T, underlying any) ([]byte, error)\n```\nMarshalObject uses a shimmed 'encoding/json' from Go 1.24, to support the 'omitzero' tag\n\nStability for the API of MarshalObject is not guaranteed.\n\n```go\nfunc MarshalUnion[T ParamStruct](metadata T, variants ...any) ([]byte, error)\n```\nMarshalUnion uses a shimmed 'encoding/json' from Go 1.24, to support the 'omitzero' tag\n\nStability for the API of MarshalUnion is not guaranteed.\n\n```go\nfunc MarshalWithExtras[T ParamStruct, R any](f T, underlying any, extras map[string]R) ([]byte, error)\n```\nMarshalWithExtras is used to marshal a struct with additional properties.\n\nStability for the API of MarshalWithExtras is not guaranteed.\n\n```go\nfunc NullMap[MapT ~map[string]T, T any]() MapT\n```\nNullMap returns a non-nil map with a length of 0. When used with [MarshalObject](#MarshalObject) or [MarshalUnion](#MarshalUnion), it will be marshaled as null.\n\nIt is unspecified behavior to mutate the map returned by [NullMap](#NullMap).\n\n```go\nfunc NullSlice[SliceT ~[]T, T any]() SliceT\n```\nNullSlice returns a non-nil slice with a length of 0. When used with [MarshalObject](#MarshalObject) or [MarshalUnion](#MarshalUnion), it will be marshaled as null.\n\nIt is unspecified behavior to mutate the slice returned by [NullSlice](#NullSlice).\n\n```go\nfunc NullStruct[T ParamStruct, PtrT InferPtr[T]]() T\n```\nNullStruct is used to set a struct to the JSON value null. Check for null structs with [IsNull](#IsNull).\n\nOnly the first type parameter should be provided, the type PtrT will be inferred.\n\n\tjson.Marshal(param.NullStruct[MyStruct]()) -\u003e 'null'\n\nTo send null to an [Opt](#Opt) field use [Null](#Null).\n\n```go\nfunc Override[T ParamStruct, PtrT InferPtr[T]](v any) T\n```\nOverride replaces the value of a struct with any type.\n\nOnly the first type parameter should be provided, the type PtrT will be inferred.\n\nIt's often useful for providing raw JSON\n\n\tparam.Override[MyStruct](json.RawMessage(`{\"foo\": \"bar\"}`))\n\nThe public fields of the returned struct T will be unset.\n\nTo override a specific field in a struct, use its \\[SetExtraFields] method.\n\n## Types\n\n```go\ntype APIObject struct {\n\t// contains filtered or unexported fields\n}\n```\nAPIObject should be embedded in api object fields, preferably using an alias to make private\n\n```go\nfunc (m APIObject) ExtraFields() map[string]any\n```\nExtraFields returns the extra fields added to the JSON object.\n\n```go\nfunc (m APIObject) Overrides() (any, bool)\n```\nOverrides returns the value of the struct when it is created with [Override](#Override), the second argument helps differentiate an explicit null.\n\n```go\nfunc (m *APIObject) SetExtraFields(extraFields map[string]any)\n```\nSetExtraFields adds extra fields to the JSON object.\n\nSetExtraFields will override any existing fields with the same key. For security reasons, ensure this is only used with trusted input data.\n\nTo intentionally omit a required field, use [Omit](#Omit).\n\n\tfoo.SetExtraFields(map[string]any{\"bar\": Omit})\n\nIf the struct already contains the field ExtraFields, then this method will have no effect.\n\n```go\ntype APIUnion struct {\n\t// contains filtered or unexported fields\n}\n```\nAPIUnion should be embedded in all api unions fields, preferably using an alias to make private\n\n```go\nfunc (m APIUnion) ExtraFields() map[string]any\n```\nExtraFields returns the extra fields added to the JSON object.\n\n```go\nfunc (m APIUnion) Overrides() (any, bool)\n```\nOverrides returns the value of the struct when it is created with [Override](#Override), the second argument helps differentiate an explicit null.\n\n```go\nfunc (m *APIUnion) SetExtraFields(extraFields map[string]any)\n```\nSetExtraFields adds extra fields to the JSON object.\n\nSetExtraFields will override any existing fields with the same key. For security reasons, ensure this is only used with trusted input data.\n\nTo intentionally omit a required field, use [Omit](#Omit).\n\n\tfoo.SetExtraFields(map[string]any{\"bar\": Omit})\n\nIf the struct already contains the field ExtraFields, then this method will have no effect.\n\n```go\ntype EncodedAsDate Opt[time.Time]\n```\nEncodedAsDate is not be stable and shouldn't be relied upon\n\n```go\nfunc (m EncodedAsDate) MarshalJSON() ([]byte, error)\n```\n\n```go\ntype InferPtr[T ParamStruct] interface {\n\t*T\n\t// contains filtered or unexported methods\n}\n```\nThis is an implementation detail and should never be explicitly set.\n\n```go\ntype Opt[T comparable] struct {\n\tValue T\n\t// contains filtered or unexported fields\n}\n```\nOpt represents an optional parameter of type T. Use the [Opt.Valid](#Opt.Valid) method to confirm.\n\n```go\nfunc NewOpt[T comparable](v T) Opt[T]\n```\n\n```go\nfunc Null[T comparable]() Opt[T]\n```\nNull creates optional field with the JSON value \"null\".\n\nTo set a struct to null, use [NullStruct](#NullStruct).\n\n```go\nfunc (o Opt[T]) MarshalJSON() ([]byte, error)\n```\n\n```go\nfunc (o Opt[T]) MarshalJSONWithTimeLayout(format string) []byte\n```\nMarshalJSONWithTimeLayout is necessary to bypass the internal caching performed by [json.Marshal](/encoding/json#Marshal). Prefer to use [Opt.MarshalJSON](#Opt.MarshalJSON) instead.\n\nThis function requires that the generic type parameter of [Opt](#Opt) is not [time.Time](/time#Time).\n\n```go\nfunc (o Opt[T]) Or(v T) T\n```\n\n```go\nfunc (o Opt[T]) String() string\n```\n\n```go\nfunc (o *Opt[T]) UnmarshalJSON(data []byte) error\n```\n\n```go\nfunc (o Opt[T]) Valid() bool\n```\nValid returns true if the value is not \"null\" or omitted.\n\nTo check if explicitly null, use \\[Opt.Null].\n\n```go\ntype Optional interface {\n\tValid() bool\n\t// contains filtered or unexported methods\n}\n```\nThis interface is useful for internal purposes.\n\n```go\ntype ParamNullable interface {\n\t// contains filtered or unexported methods\n}\n```\nParamNullable encapsulates all structs in parameters, and all [Opt](#Opt) types in parameters.\n\n```go\ntype ParamStruct interface {\n\tOverrides() (any, bool)\n\t// contains filtered or unexported methods\n}\n```\nParamStruct represents the set of all structs that are used in API parameters, by convention these usually end in \"Params\" or \"Param\".\n\n","path":"github.com/devdraftengineer/devdraft-go/packages/param","name":"param","synopsis":"","isRedistributable":true}
