api

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

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

Code generated by github.com/discord-gophers/goapi-gen version (devel) DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSwagger

func GetSwagger() (swagger *openapi3.T, err error)

GetSwagger returns the Swagger specification corresponding to the generated code in this file. The external references of Swagger specification are resolved. The logic of resolving external references is tightly connected to "import-mapping" feature. Externally referenced files must be embedded in the corresponding golang packages. Urls can be supported but this task was out of the scope.

func Handler

func Handler(si ServerInterface, opts ...ServerOption) http.Handler

Handler creates http.Handler with routing matching OpenAPI spec.

func PathToRawSpec

func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error)

Constructs a synthetic filesystem for resolving external references when loading openapi specifications.

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.

func (AddPetJSONRequestBody) Bind

Bind implements render.Binder.

type Error

type Error struct {
	// Error message
	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 InvalidParamFormatError

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

type NewPet

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

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

NewPet defines model for NewPet.

type Pet

type Pet struct {
	// Embedded struct due to allOf(#/components/schemas/NewPet)
	NewPet `yaml:",inline"`
	// Embedded fields due to inline allOf schema
	// Unique id of the pet
	ID int64 `json:"id"`
}

Pet defines model for Pet.

type PetStore

type PetStore struct {
	Lock   sync.Mutex
	Pets   map[int64]Pet
	NextId int64
}

func NewPetStore

func NewPetStore() *PetStore

func (*PetStore) AddPet

func (p *PetStore) AddPet(w http.ResponseWriter, r *http.Request)

func (*PetStore) DeletePet

func (p *PetStore) DeletePet(w http.ResponseWriter, r *http.Request, id int64)

func (*PetStore) FindPetByID

func (p *PetStore) FindPetByID(w http.ResponseWriter, r *http.Request, id int64)

func (*PetStore) FindPets

func (p *PetStore) FindPets(w http.ResponseWriter, r *http.Request, params FindPetsParams)

Here, we implement all of the handlers in the ServerInterface

type RequiredHeaderError

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

type RequiredParamError

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

type Response

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

Response is a common response struct for all the API calls. A Response object may be instantiated via functions for specific operation responses.

func AddPetJSON201Response

func AddPetJSON201Response(body Pet) *Response

AddPetJSON201Response is a constructor method for a AddPet response. A *Response is returned with the configured status code and content type from the spec.

func AddPetJSONDefaultResponse

func AddPetJSONDefaultResponse(body Error) *Response

AddPetJSONDefaultResponse is a constructor method for a AddPet response. A *Response is returned with the configured status code and content type from the spec.

func DeletePetJSONDefaultResponse

func DeletePetJSONDefaultResponse(body Error) *Response

DeletePetJSONDefaultResponse is a constructor method for a DeletePet response. A *Response is returned with the configured status code and content type from the spec.

func FindPetByIDJSON200Response

func FindPetByIDJSON200Response(body Pet) *Response

FindPetByIDJSON200Response is a constructor method for a FindPetByID response. A *Response is returned with the configured status code and content type from the spec.

func FindPetByIDJSONDefaultResponse

func FindPetByIDJSONDefaultResponse(body Error) *Response

FindPetByIDJSONDefaultResponse is a constructor method for a FindPetByID response. A *Response is returned with the configured status code and content type from the spec.

func FindPetsJSON200Response

func FindPetsJSON200Response(body []Pet) *Response

FindPetsJSON200Response is a constructor method for a FindPets response. A *Response is returned with the configured status code and content type from the spec.

func FindPetsJSONDefaultResponse

func FindPetsJSONDefaultResponse(body Error) *Response

FindPetsJSONDefaultResponse is a constructor method for a FindPets response. A *Response is returned with the configured status code and content type from the spec.

func (*Response) ContentType

func (resp *Response) ContentType(contentType string) *Response

ContentType is a builder method to override the default content type for a response.

func (*Response) MarshalJSON

func (resp *Response) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface. This is used to only marshal the body of the response.

func (*Response) MarshalXML

func (resp *Response) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface. This is used to only marshal the body of the response.

func (*Response) Render

func (resp *Response) Render(w http.ResponseWriter, r *http.Request) error

Render implements the render.Renderer interface. It sets the Content-Type header and status code based on the response definition.

func (*Response) Status

func (resp *Response) Status(statusCode int) *Response

Status is a builder method to override the default status code for a response.

type ServerInterface

type ServerInterface interface {
	// Returns all pets
	// (GET /pets)
	FindPets(w http.ResponseWriter, r *http.Request, params FindPetsParams)
	// Creates a new pet
	// (POST /pets)
	AddPet(w http.ResponseWriter, r *http.Request)
	// Deletes a pet by ID
	// (DELETE /pets/{id})
	DeletePet(w http.ResponseWriter, r *http.Request, id int64)
	// Returns a pet by ID
	// (GET /pets/{id})
	FindPetByID(w http.ResponseWriter, r *http.Request, id int64)
}

ServerInterface represents all server handlers.

type ServerInterfaceWrapper

type ServerInterfaceWrapper struct {
	Handler          ServerInterface
	Middlewares      map[string]func(http.Handler) http.Handler
	ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
}

ServerInterfaceWrapper converts contexts to parameters.

func (*ServerInterfaceWrapper) AddPet

AddPet operation middleware

func (*ServerInterfaceWrapper) DeletePet

func (siw *ServerInterfaceWrapper) DeletePet(w http.ResponseWriter, r *http.Request)

DeletePet operation middleware

func (*ServerInterfaceWrapper) FindPetByID

func (siw *ServerInterfaceWrapper) FindPetByID(w http.ResponseWriter, r *http.Request)

FindPetByID operation middleware

func (*ServerInterfaceWrapper) FindPets

func (siw *ServerInterfaceWrapper) FindPets(w http.ResponseWriter, r *http.Request)

FindPets operation middleware

type ServerOption

type ServerOption func(*ServerOptions)

func WithErrorHandler

func WithErrorHandler(handler func(w http.ResponseWriter, r *http.Request, err error)) ServerOption

func WithMiddleware

func WithMiddleware(key string, middleware func(http.Handler) http.Handler) ServerOption

func WithMiddlewares

func WithMiddlewares(middlewares map[string]func(http.Handler) http.Handler) ServerOption

func WithRouter

func WithRouter(r chi.Router) ServerOption

func WithServerBaseURL

func WithServerBaseURL(url string) ServerOption

type ServerOptions

type ServerOptions struct {
	BaseURL          string
	BaseRouter       chi.Router
	Middlewares      map[string]func(http.Handler) http.Handler
	ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
}

type TooManyValuesForParamError

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

type UnescapedCookieParamError

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

type UnmarshalingParamError

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

Jump to

Keyboard shortcuts

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