parameter

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: MIT Imports: 2 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoParam []Parameter

NoParam is an empty slice of parameters.

Functions

This section is empty.

Types

type CollectionFormat

type CollectionFormat string

CollectionFormat defines the format for serializing array parameters in the URL query string.

const (
	CSV   CollectionFormat = "csv"
	SSV   CollectionFormat = "ssv"
	TSV   CollectionFormat = "tsv"
	Pipes CollectionFormat = "pipes"
	Multi CollectionFormat = "multi"
)

func (CollectionFormat) String

func (c CollectionFormat) String() string

String returns the string representation of the CollectionFormat.

type JsonParameter

type JsonParameter struct {
	Type              string              `json:"type,omitempty"`
	Description       string              `json:"description"`
	Name              string              `json:"name"`
	In                string              `json:"in,omitempty"`
	Required          bool                `json:"required"`
	Schema            *JsonResponseSchema `json:"schema,omitempty"`
	Format            string              `json:"format,omitempty"`
	Enum              []interface{}       `json:"enum,omitempty"`
	Default           interface{}         `json:"default,omitempty"`
	Min               int64               `json:"minimum,omitempty"`
	Max               int64               `json:"maximum,omitempty"`
	MinLen            int64               `json:"minLength,omitempty"`
	MaxLen            int64               `json:"maxLength,omitempty"`
	Pattern           string              `json:"pattern,omitempty"`
	MaxItems          int64               `json:"maxItems,omitempty"`
	MinItems          int64               `json:"minItems,omitempty"`
	UniqueItems       bool                `json:"uniqueItems,omitempty"`
	MultipleOf        int64               `json:"multipleOf,omitempty"`
	CollenctionFormat string              `json:"collectionFormat,omitempty"`
}

JsonParameter is the JSON model version of Parameter object used for API purposes https://swagger.io/specification/v2/#parameterObject

type JsonResponseSchema

type JsonResponseSchema struct {
	Ref   string                   `json:"$ref,omitempty"`
	Type  string                   `json:"type,omitempty"`
	Items *JsonResponseSchemeItems `json:"items,omitempty"`
}

JsonResponseSchema defines the schema for a JSON response as per the Swagger 2.0 specification. It is used to describe the structure and type of a response returned by an API endpoint. https://swagger.io/specification/v2/#schema-object

type JsonResponseSchemeItems

type JsonResponseSchemeItems struct {
	Type  string                   `json:"type,omitempty"`
	Ref   string                   `json:"$ref,omitempty"`
	Items *JsonResponseSchemeItems `json:"items,omitempty"`
}

JsonResponseSchemeItems represents the individual items in a JsonResponseSchema, especially for arrays. It provides the type or reference for the array items.

type Location

type Location string

Location specifies where in the request a parameter is expected to be located.

const (
	Query  Location = "query"
	Header Location = "header"
	Path   Location = "path"
	Form   Location = "formData"
)

func (Location) String

func (l Location) String() string

String returns the string representation of the Location.

type Option

type Option func(*Parameter)

Option represents a function that can modify a Parameter.

func WithCollectionFormat

func WithCollectionFormat(c CollectionFormat) Option

WithCollectionFormat sets the CollectionFormat field of a Parameter.

func WithDefault

func WithDefault(defaultValue interface{}) Option

WithDefault sets the Default field of a Parameter.

func WithDescription

func WithDescription(description string) Option

WithDescription sets the Description field of a Parameter.

func WithFormat

func WithFormat(format string) Option

WithFormat sets the Format field of a Parameter.

func WithIn

func WithIn(in Location) Option

WithIn sets the In field of a Parameter.

func WithMax

func WithMax(max int64) Option

WithMax sets the Max field of a Parameter.

func WithMaxItems

func WithMaxItems(maxItems int64) Option

WithMaxItems sets the MaxItems field of a Parameter.

func WithMaxLen

func WithMaxLen(maxLen int64) Option

WithMaxLen sets the MaxLen field of a Parameter.

func WithMin

func WithMin(min int64) Option

WithMin sets the Min field of a Parameter.

func WithMinItems

func WithMinItems(minItems int64) Option

WithMinItems sets the MinItems field of a Parameter.

func WithMinLen

func WithMinLen(minLen int64) Option

WithMinLen sets the MinLen field of a Parameter.

func WithMultipleOf

func WithMultipleOf(multipleOf int64) Option

WithMultipleOf sets the MultipleOf field of a Parameter.

func WithPattern

func WithPattern(pattern string) Option

WithPattern sets the Pattern field of a Parameter.

func WithRequired

func WithRequired() Option

WithRequired sets the Required field of a Parameter.

func WithType

func WithType(t ParamType) Option

WithType sets the Type field of a Parameter.

func WithUniqueItems

func WithUniqueItems(uniqueItems bool) Option

WithUniqueItems sets the UniqueItems field of a Parameter.

type ParamType

type ParamType string

ParamType represents the type of a parameter in the API endpoint.

const (
	String  ParamType = "string"
	Number  ParamType = "number"
	Integer ParamType = "integer"
	Boolean ParamType = "boolean"
	Array   ParamType = "array"
	File    ParamType = "file"
)

func (ParamType) String

func (p ParamType) String() string

String returns the string representation of the ParamType.

type Parameter

type Parameter struct {
	// contains filtered or unexported fields
}

Parameter represents a parameter in an API endpoint.

func BoolParam

func BoolParam(name string, l Location, opts ...Option) *Parameter

BoolParam creates a boolean parameter.

func FileParam

func FileParam(name string, opts ...Option) *Parameter

FileParam creates a file parameter.

func IntArrParam

func IntArrParam(name string, l Location, arr []int64, opts ...Option) *Parameter

IntArrParam creates an integer array parameter.

func IntEnumParam

func IntEnumParam(name string, l Location, arr []int64, opts ...Option) *Parameter

IntEnumParam creates an integer enum parameter.

func IntParam

func IntParam(name string, l Location, opts ...Option) *Parameter

IntParam creates an integer parameter.

func Params

func Params(params ...Parameter) (paramsArr []Parameter)

Params appends parameters to an existing parameter slice.

func StrArrParam

func StrArrParam(name string, l Location, arr []string, opts ...Option) *Parameter

StrArrParam creates a string array parameter.

func StrEnumParam

func StrEnumParam(name string, l Location, arr []string, opts ...Option) *Parameter

StrEnumParam creates a string enum parameter.

func StrParam

func StrParam(name string, l Location, opts ...Option) *Parameter

StrParam creates a string parameter.

func (*Parameter) AsJson

func (p *Parameter) AsJson() JsonParameter

AsJson returns the json representation of Parameter

func (Parameter) Location

func (p Parameter) Location() Location

Location returns the location of the parameter (i.e. Query, Body, Path, and etc.)

Jump to

Keyboard shortcuts

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