petstore

package
v2.1.20 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

README

OpenAPI Code Generation Example

This directory contains an example server using our code generator which implements the OpenAPI petstore-expanded example.

This is the structure:

  • api/: Contains the OpenAPI 3.0 specification
  • api/petstore/: The generated code for our pet store handlers
  • internal/: Pet store handler implementation and unit tests
  • cmd/: Runnable server implementing the OpenAPI 3 spec.

To generate the handler glue, run:

go run cmd/oapi-codegen/oapi-codegen.go --package petstore examples/petstore-expanded/petstore-expanded.yaml  > examples/petstore-expanded/petstore.gen.go

Documentation

Overview

Package petstore provides primitives to interact with the openapi HTTP API.

Code generated by github.com/KosyanMedia/oapi-codegen/v2 version (devel) DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAddPetRequest

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

NewAddPetRequest calls the generic AddPet builder with application/json body

func NewAddPetRequestWithBody

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

NewAddPetRequestWithBody generates requests for AddPet with any type of body

func NewDeletePetRequest

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

NewDeletePetRequest generates requests for DeletePet

func NewFindPetByIDRequest

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

NewFindPetByIDRequest generates requests for FindPetByID

func NewFindPetsRequest

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

NewFindPetsRequest generates requests for FindPets

Types

type AddPetJSONBody

type AddPetJSONBody = NewPet

AddPetJSONBody defines parameters for AddPet.

type AddPetJSONRequestBody

type AddPetJSONRequestBody = AddPetJSONBody

AddPetJSONRequestBody defines body for AddPet for application/json ContentType.

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 swagger 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)

Creates a new Client, with reasonable defaults

func (*Client) AddPet

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

func (*Client) AddPetWithBody

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

func (*Client) DeletePet

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

func (*Client) FindPetByID

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

func (*Client) FindPets

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

type ClientAddPetResponse

type ClientAddPetResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON201      *Pet
	JSONDefault  *Error
}

func ParseAddPetResponse

func ParseAddPetResponse(rsp *http.Response) (*ClientAddPetResponse, error)

ParseAddPetResponse parses an HTTP response from a AddPetWithResponse call

func (ClientAddPetResponse) RawResponse added in v2.1.17

func (r ClientAddPetResponse) RawResponse() *http.Response

RawResponse returns pointer to the raw http.Response

func (ClientAddPetResponse) ResponseBody added in v2.0.8

func (r ClientAddPetResponse) ResponseBody() []byte

ResponseBody returns HTTPResponse.Body as byte array

func (ClientAddPetResponse) Status

func (r ClientAddPetResponse) Status() string

Status returns HTTPResponse.Status

func (ClientAddPetResponse) StatusCode

func (r ClientAddPetResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type ClientDeletePetResponse

type ClientDeletePetResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSONDefault  *Error
}

func ParseDeletePetResponse

func ParseDeletePetResponse(rsp *http.Response) (*ClientDeletePetResponse, error)

ParseDeletePetResponse parses an HTTP response from a DeletePetWithResponse call

func (ClientDeletePetResponse) RawResponse added in v2.1.17

func (r ClientDeletePetResponse) RawResponse() *http.Response

RawResponse returns pointer to the raw http.Response

func (ClientDeletePetResponse) ResponseBody added in v2.0.8

func (r ClientDeletePetResponse) ResponseBody() []byte

ResponseBody returns HTTPResponse.Body as byte array

func (ClientDeletePetResponse) Status

func (r ClientDeletePetResponse) Status() string

Status returns HTTPResponse.Status

func (ClientDeletePetResponse) StatusCode

func (r ClientDeletePetResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type ClientFindPetByIDResponse

type ClientFindPetByIDResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *Pet
	JSONDefault  *Error
}

func ParseFindPetByIDResponse

func ParseFindPetByIDResponse(rsp *http.Response) (*ClientFindPetByIDResponse, error)

ParseFindPetByIDResponse parses an HTTP response from a FindPetByIDWithResponse call

func (ClientFindPetByIDResponse) RawResponse added in v2.1.17

func (r ClientFindPetByIDResponse) RawResponse() *http.Response

RawResponse returns pointer to the raw http.Response

func (ClientFindPetByIDResponse) ResponseBody added in v2.0.8

func (r ClientFindPetByIDResponse) ResponseBody() []byte

ResponseBody returns HTTPResponse.Body as byte array

func (ClientFindPetByIDResponse) Status

func (r ClientFindPetByIDResponse) Status() string

Status returns HTTPResponse.Status

func (ClientFindPetByIDResponse) StatusCode

func (r ClientFindPetByIDResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type ClientFindPetsResponse

type ClientFindPetsResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      []Pet
	JSONDefault  *Error
}

func ParseFindPetsResponse

func ParseFindPetsResponse(rsp *http.Response) (*ClientFindPetsResponse, error)

ParseFindPetsResponse parses an HTTP response from a FindPetsWithResponse call

func (ClientFindPetsResponse) RawResponse added in v2.1.17

func (r ClientFindPetsResponse) RawResponse() *http.Response

RawResponse returns pointer to the raw http.Response

func (ClientFindPetsResponse) ResponseBody added in v2.0.8

func (r ClientFindPetsResponse) ResponseBody() []byte

ResponseBody returns HTTPResponse.Body as byte array

func (ClientFindPetsResponse) Status

func (r ClientFindPetsResponse) Status() string

Status returns HTTPResponse.Status

func (ClientFindPetsResponse) StatusCode

func (r ClientFindPetsResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type ClientInterface

type ClientInterface interface {
	// FindPets request
	FindPets(ctx context.Context, params FindPetsParams, reqEditors ...RequestEditorFn) (*http.Response, error)

	// AddPet request with any body
	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 request
	DeletePet(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*http.Response, error)

	// FindPetByID request
	FindPetByID(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*http.Response, error)
}

The interface specification for the client above.

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 ClientWithResponses

type ClientWithResponses struct {
	ClientInterface
}

ClientWithResponses builds on ClientInterface to offer response payloads

func NewClientWithResponses

func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error)

NewClientWithResponses creates a new ClientWithResponses, which wraps Client with return type handling

func (*ClientWithResponses) AddPetWithBodyWithResponse

func (c *ClientWithResponses) AddPetWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ClientAddPetResponse, error)

AddPetWithBodyWithResponse request with arbitrary body returning *AddPetResponse

func (*ClientWithResponses) AddPetWithResponse

func (c *ClientWithResponses) AddPetWithResponse(ctx context.Context, body AddPetJSONRequestBody, reqEditors ...RequestEditorFn) (*ClientAddPetResponse, error)

func (*ClientWithResponses) DeletePetWithResponse

func (c *ClientWithResponses) DeletePetWithResponse(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*ClientDeletePetResponse, error)

DeletePetWithResponse request returning *DeletePetResponse

func (*ClientWithResponses) FindPetByIDWithResponse

func (c *ClientWithResponses) FindPetByIDWithResponse(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*ClientFindPetByIDResponse, error)

FindPetByIDWithResponse request returning *FindPetByIDResponse

func (*ClientWithResponses) FindPetsWithResponse

func (c *ClientWithResponses) FindPetsWithResponse(ctx context.Context, params FindPetsParams, reqEditors ...RequestEditorFn) (*ClientFindPetsResponse, error)

FindPetsWithResponse request returning *FindPetsResponse

type ClientWithResponsesInterface

type ClientWithResponsesInterface interface {
	// FindPets request
	FindPetsWithResponse(ctx context.Context, params FindPetsParams, reqEditors ...RequestEditorFn) (*ClientFindPetsResponse, error)

	// AddPet request with any body
	AddPetWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ClientAddPetResponse, error)

	AddPetWithResponse(ctx context.Context, body AddPetJSONRequestBody, reqEditors ...RequestEditorFn) (*ClientAddPetResponse, error)

	// DeletePet request
	DeletePetWithResponse(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*ClientDeletePetResponse, error)

	// FindPetByID request
	FindPetByIDWithResponse(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*ClientFindPetByIDResponse, error)
}

ClientWithResponsesInterface is the interface specification for the client with responses above.

type Error

type Error struct {
	// Error code
	Code int32 `json:"code" validate:"required"`

	// Error message
	Message string `json:"message" validate:"required"`
}

Error defines model for Error.

type FindPetsParams

type FindPetsParams struct {
	// tags to filter by
	Tags []string `form:"tags,omitempty" json:"tags,omitempty"`

	// maximum number of results to return
	Limit *int32 `form:"limit,omitempty" json:"limit,omitempty"`
}

FindPetsParams defines parameters for FindPets.

type HttpRequestDoer

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

Doer performs HTTP requests.

The standard http.Client implements this interface.

type NewPet

type NewPet struct {
	// Name of the pet
	Name string `json:"name" validate:"required"`

	// Type of the pet
	Tag *string `json:"tag,omitempty"`
}

NewPet defines model for NewPet.

type Pet

type Pet struct {
	// Unique id of the pet
	Id int64 `json:"id" validate:"required"`

	// Name of the pet
	Name string `json:"name" validate:"required"`

	// Type of the pet
	Tag *string `json:"tag,omitempty"`
}

Pet defines model for Pet.

type RequestEditorFn

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

RequestEditorFn is the function signature for the RequestEditor callback function

Directories

Path Synopsis
chi
api
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.
This is an example of implementing the Pet Store from the OpenAPI documentation found at: https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v3.0/petstore.yaml
This is an example of implementing the Pet Store from the OpenAPI documentation found at: https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v3.0/petstore.yaml
api
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.
gin
api
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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