client

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DateFormat = "2006-01-02"

Variables

This section is empty.

Functions

func MarshalDeepObject

func MarshalDeepObject(i any, paramName string) (string, error)

MarshalDeepObject marshals an object to deepObject style query parameters.

func NewAddPetRequest

func NewAddPetRequest(server string, body addPetJSONRequestBody) (*http.Request, error)

NewAddPetRequest creates a POST request for /pets with application/json body

func NewAddPetRequestWithBody

func NewAddPetRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error)

NewAddPetRequestWithBody creates a POST request for /pets with any body

func NewDeletePetRequest

func NewDeletePetRequest(server string, id int64) (*http.Request, error)

NewDeletePetRequest creates a DELETE request for /pets/{id}

func NewFindPetByIDRequest

func NewFindPetByIDRequest(server string, id int64) (*http.Request, error)

NewFindPetByIDRequest creates a GET request for /pets/{id}

func NewFindPetsRequest

func NewFindPetsRequest(server string, params *FindPetsParams) (*http.Request, error)

NewFindPetsRequest creates a GET request for /pets

func StyleParameter

func StyleParameter(paramName string, value any, opts ParameterOptions) (string, error)

StyleParameter serializes a Go value into an OpenAPI-styled parameter string. This is the entry point for client-side parameter serialization. The Style field in opts selects the serialization format. If Style is empty, "simple" is assumed.

Types

type Client

type Client struct {
	// The endpoint of the server conforming to this interface, with scheme,
	// https://api.deepmap.com for example. This can contain a path relative
	// to the server, such as https://api.deepmap.com/dev-test, and all the
	// paths in the OpenAPI spec will be appended to the server.
	Server string

	// Doer for performing requests, typically a *http.Client with any
	// customized settings, such as certificate chains.
	Client HttpRequestDoer

	// A list of callbacks for modifying requests which are generated before sending over
	// the network.
	RequestEditors []RequestEditorFn
}

Client which conforms to the OpenAPI3 specification for this service.

func NewClient

func NewClient(server string, opts ...ClientOption) (*Client, error)

NewClient creates a new Client with reasonable defaults.

func (*Client) AddPet

func (c *Client) AddPet(ctx context.Context, body addPetJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

AddPet makes a POST request to /pets with application/json body

func (*Client) AddPetWithBody

func (c *Client) AddPetWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

AddPetWithBody makes a POST request to /pets Creates a new pet

func (*Client) DeletePet

func (c *Client) DeletePet(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*http.Response, error)

DeletePet makes a DELETE request to /pets/{id} Deletes a pet by ID

func (*Client) FindPetByID

func (c *Client) FindPetByID(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*http.Response, error)

FindPetByID makes a GET request to /pets/{id} Returns a pet by ID

func (*Client) FindPets

func (c *Client) FindPets(ctx context.Context, params *FindPetsParams, reqEditors ...RequestEditorFn) (*http.Response, error)

FindPets makes a GET request to /pets Returns all pets

type ClientHttpError

type ClientHttpError[E any] struct {
	StatusCode int
	Body       E
	RawBody    []byte
}

ClientHttpError represents an HTTP error response. The type parameter E is the type of the parsed error body.

func (*ClientHttpError[E]) Error

func (e *ClientHttpError[E]) Error() string

type ClientInterface

type ClientInterface interface {
	// FindPets makes a GET request to /pets
	FindPets(ctx context.Context, params *FindPetsParams, reqEditors ...RequestEditorFn) (*http.Response, error)
	// AddPetWithBody makes a POST request to /pets
	AddPetWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
	AddPet(ctx context.Context, body addPetJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
	// DeletePet makes a DELETE request to /pets/{id}
	DeletePet(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*http.Response, error)
	// FindPetByID makes a GET request to /pets/{id}
	FindPetByID(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*http.Response, error)
}

ClientInterface is the interface specification for the client.

type ClientOption

type ClientOption func(*Client) error

ClientOption allows setting custom parameters during construction.

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL overrides the baseURL.

func WithHTTPClient

func WithHTTPClient(doer HttpRequestDoer) ClientOption

WithHTTPClient allows overriding the default Doer, which is automatically created using http.Client. This is useful for tests.

func WithRequestEditorFn

func WithRequestEditorFn(fn RequestEditorFn) ClientOption

WithRequestEditorFn allows setting up a callback function, which will be called right before sending the request. This can be used to mutate the request.

type Date

type Date struct {
	time.Time
}

func (Date) Format

func (d Date) Format(layout string) string

Format returns the date formatted according to layout.

func (Date) MarshalJSON

func (d Date) MarshalJSON() ([]byte, error)

func (Date) MarshalText

func (d Date) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler for Date.

func (Date) String

func (d Date) String() string

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(data []byte) error

func (*Date) UnmarshalText

func (d *Date) UnmarshalText(data []byte) error

type FindPetsParams

type FindPetsParams struct {
	// tags (optional)
	Tags *[]string `form:"tags" json:"tags"`
	// limit (optional)
	Limit *int32 `form:"limit" json:"limit"`
}

FindPetsParams defines parameters for FindPets.

type HttpRequestDoer

type HttpRequestDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

HttpRequestDoer performs HTTP requests. The standard http.Client implements this interface.

type ParamLocation

type ParamLocation int

ParamLocation indicates where a parameter is located in an HTTP request.

const (
	ParamLocationUndefined ParamLocation = iota
	ParamLocationQuery
	ParamLocationPath
	ParamLocationHeader
	ParamLocationCookie
)

type ParameterOptions

type ParameterOptions struct {
	Style         string        // OpenAPI style: "simple", "form", "label", "matrix", "deepObject", "pipeDelimited", "spaceDelimited"
	ParamLocation ParamLocation // Where the parameter appears: query, path, header, cookie
	Explode       bool
	Required      bool
	Type          string // OpenAPI type: "string", "integer", "array", "object"
	Format        string // OpenAPI format: "int32", "date-time", etc.
	AllowReserved bool   // When true, reserved characters in query values are not percent-encoded
}

ParameterOptions carries OpenAPI parameter metadata to bind and style functions so they can handle style dispatch, explode, required, type-aware coercions, and location-aware escaping from a single uniform call site. All fields have sensible zero-value defaults.

type RequestEditorFn

type RequestEditorFn func(ctx context.Context, req *http.Request) error

RequestEditorFn is the function signature for the RequestEditor callback function.

type SimpleClient

type SimpleClient struct {
	*Client
}

SimpleClient wraps Client with typed responses for operations that have unambiguous response types. Methods return the success type directly, and HTTP errors are returned as *ClientHttpError[E] where E is the error type.

func NewSimpleClient

func NewSimpleClient(server string, opts ...ClientOption) (*SimpleClient, error)

NewSimpleClient creates a new SimpleClient which wraps a Client.

func (*SimpleClient) AddPet

func (c *SimpleClient) AddPet(ctx context.Context, body addPetJSONRequestBody, reqEditors ...RequestEditorFn) (petstore.Pet, error)

AddPet makes a POST request to /pets and returns the parsed response. Creates a new pet On success, returns the response body. On HTTP error, returns *ClientHttpError[petstore.Error].

func (*SimpleClient) FindPetByID

func (c *SimpleClient) FindPetByID(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (petstore.Pet, error)

FindPetByID makes a GET request to /pets/{id} and returns the parsed response. Returns a pet by ID On success, returns the response body. On HTTP error, returns *ClientHttpError[petstore.Error].

func (*SimpleClient) FindPets

func (c *SimpleClient) FindPets(ctx context.Context, params *FindPetsParams, reqEditors ...RequestEditorFn) ([]petstore.Pet, error)

FindPets makes a GET request to /pets and returns the parsed response. Returns all pets On success, returns the response body. On HTTP error, returns *ClientHttpError[petstore.Error].

type UUID

type UUID = uuid.UUID

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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