petstore

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2019 License: Apache-2.0 Imports: 11 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/oapi-codegen/api/petstore-expanded.yaml  > examples/oapi-codegen/api/petstore.gen.go

Documentation

Overview

Package petstore provides primitives to interact the openapi HTTP API.

Code generated by github.com/deepmap/oapi-codegen 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

func ParseaddPetResponse

func ParseaddPetResponse(rsp *http.Response) (*addPetResponse, error)

ParseaddPetResponse parses an HTTP response from a AddPetWithResponse call

func ParsedeletePetResponse

func ParsedeletePetResponse(rsp *http.Response) (*deletePetResponse, error)

ParsedeletePetResponse parses an HTTP response from a DeletePetWithResponse call

func ParsefindPetByIdResponse

func ParsefindPetByIdResponse(rsp *http.Response) (*findPetByIdResponse, error)

ParsefindPetByIdResponse parses an HTTP response from a FindPetByIdWithResponse call

func ParsefindPetsResponse

func ParsefindPetsResponse(rsp *http.Response) (*findPetsResponse, error)

ParsefindPetsResponse parses an HTTP response from a FindPetsWithResponse call

Types

type AddPetJSONRequestBody

type AddPetJSONRequestBody addPetJSONBody

AddPetRequestBody 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.
	Server string

	// HTTP client with any customized settings, such as certificate chains.
	Client *http.Client

	// A callback for modifying requests which are generated before sending over
	// the network.
	RequestEditor RequestEditorFn

	// A callback which gets called after request finished, before any
	// deserialization steps.
	RequestCompletion RequestCompletionFn

	// List of additional interceptors, which gets called prior
	// of the RequestEditor.
	Interceptors []Interceptor
	// contains filtered or unexported fields
}

Client which conforms to the OpenAPI3 specification for this service.

func NewClient

func NewClient(ctx context.Context, opts ...Option) (*Client, error)

NewClient creates a new Client.

func (*Client) AddPet

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

func (*Client) AddPetWithBody

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

func (*Client) DeletePet

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

func (*Client) FindPetById

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

func (*Client) FindPets

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

func (*Client) Intercept

func (c *Client) Intercept(req *http.Request, ctx context.Context) error

Intercept intercepts the request, applies all registered Interceptors which are part of the client. If an Interceptor fails, the Interceptor chain will return early.

type ClientInterface

type ClientInterface interface {

	// Intercept intercepts the request, applies all registered Interceptors
	// which are part of the client.
	// If an Interceptor fails, the Interceptor chain will return early.
	Intercept(req *http.Request, ctx context.Context) error

	// FindPets request
	FindPets(ctx context.Context, params *FindPetsParams) (*http.Response, error)

	// AddPet request  with any body
	AddPetWithBody(ctx context.Context, contentType string, body io.Reader) (*http.Response, error)

	AddPet(ctx context.Context, body AddPetJSONRequestBody) (*http.Response, error)

	// DeletePet request
	DeletePet(ctx context.Context, id int64) (*http.Response, error)

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

The interface specification for the client above.

type ClientWithResponses

type ClientWithResponses struct {
	ClientInterface
}

ClientWithResponses builds on ClientInterface to offer response payloads

func NewClientWithResponses

func NewClientWithResponses(server string) *ClientWithResponses

NewClientWithResponses returns a ClientWithResponses with a default Client:

func NewClientWithResponsesAndRequestEditorFunc

func NewClientWithResponsesAndRequestEditorFunc(server string, reqEditorFn RequestEditorFn) *ClientWithResponses

NewClientWithResponsesAndRequestEditorFunc takes in a RequestEditorFn callback function and returns a ClientWithResponses with a default Client:

func (*ClientWithResponses) AddPetWithBodyWithResponse

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

AddPetWithBodyWithResponse request with arbitrary body returning *AddPetResponse

func (*ClientWithResponses) AddPetWithResponse

func (c *ClientWithResponses) AddPetWithResponse(ctx context.Context, body AddPetJSONRequestBody) (*addPetResponse, error)

func (*ClientWithResponses) DeletePetWithResponse

func (c *ClientWithResponses) DeletePetWithResponse(ctx context.Context, id int64) (*deletePetResponse, error)

DeletePetWithResponse request returning *DeletePetResponse

func (*ClientWithResponses) FindPetByIdWithResponse

func (c *ClientWithResponses) FindPetByIdWithResponse(ctx context.Context, id int64) (*findPetByIdResponse, error)

FindPetByIdWithResponse request returning *FindPetByIdResponse

func (*ClientWithResponses) FindPetsWithResponse

func (c *ClientWithResponses) FindPetsWithResponse(ctx context.Context, params *FindPetsParams) (*findPetsResponse, error)

FindPetsWithResponse request returning *FindPetsResponse

type Error

type Error struct {
	Code    int32  `json:"code"`
	Message string `json:"message"`
}

Error defines model for Error.

type FindPetsParams

type FindPetsParams struct {

	// tags to filter by
	Tags *[]string `json:"tags,omitempty"`

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

FindPetsParams defines parameters for FindPets.

type Interceptor

type Interceptor interface {
	// Intercept intercepts a request and can fail with an error.
	Intercept(req *http.Request, ctx context.Context) error
}

Interceptor allows intercepting requests.

type InterceptorFn

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

InterceptorFn allows intercepting requests and can be used as an adapter to a Interceptor.

func (InterceptorFn) Intercept

func (f InterceptorFn) Intercept(req *http.Request, ctx context.Context) error

InterceptorFn is an adapter to allow the use of ordinary functions as Interceptors.

type NewPet

type NewPet struct {
	Name string  `json:"name"`
	Tag  *string `json:"tag,omitempty"`
}

NewPet defines model for NewPet.

type Option

type Option func(*Client) error

Option allows setting custom parameters during construction

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL overrides the baseURL.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient allows overriding the default httpClient, which is automatically created. This is useful for tests.

func WithIdleTimeout

func WithIdleTimeout(timeout time.Duration) Option

WithIdleTimeout overrides the timeout of idle connections.

func WithInterceptors

func WithInterceptors(interceptors ...Interceptor) Option

WithInterceptors allows adding 0..N interceptors, which get called in serial order prior of calling the RequestEditor before finally making the request. Use this function to attach authentication mechanisms.

func WithMaxIdleConnections

func WithMaxIdleConnections(maxIdleConns uint) Option

WithMaxIdleConnections overrides the amount of idle connections of the underlying http-client.

func WithRequestCompletionFn

func WithRequestCompletionFn(fn RequestCompletionFn) Option

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

func WithRequestEditorFn

func WithRequestEditorFn(fn RequestEditorFn) Option

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

func WithRequestTimeout

func WithRequestTimeout(timeout time.Duration) Option

WithRequestTimeout overrides the timeout of individual requests.

func WithUserAgent

func WithUserAgent(userAgent string) Option

WithUserAgent allows setting the userAgent

type Pet

type Pet struct {
	// Embedded struct due to allOf(#/components/schemas/NewPet)
	NewPet
	// Embedded fields due to inline allOf schema
	Id int64 `json:"id"`
}

Pet defines model for Pet.

type RequestCompletionFn

type RequestCompletionFn func(req *http.Request, resp *http.Response)

RequestCompletionFn is the function signature for the RequestCompletion callback function

type RequestEditorFn

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

RequestEditorFn is the function signature for the RequestEditor callback function

Directories

Path Synopsis
chi
api
Package api provides primitives to interact the openapi HTTP API.
Package api provides primitives to interact 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 The code under api/petstore/ has been generated from that specification.
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 The code under api/petstore/ has been generated from that specification.
api
Package api provides primitives to interact the openapi HTTP API.
Package api provides primitives to interact the openapi HTTP API.

Jump to

Keyboard shortcuts

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