oapi

package
v0.0.0-...-381a539 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

Package oapi 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

View Source
const (
	BearerAuthScopes = "BearerAuth.Scopes"
)

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 MustSwagger

func MustSwagger() *openapi3.T

MustSwagger calls GetSwagger or panics.

func PathToRawSpec

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

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

func RegisterSecurity

func RegisterSecurity(f RegisterSecurityFunc) func(next http.Handler) http.Handler

RegisterSecurity registers the given security function to be used for verifying authentication and authorization.

Types

type CreatePostJSONBody

type CreatePostJSONBody Post

CreatePostJSONBody defines parameters for CreatePost.

type CreatePostJSONRequestBody

type CreatePostJSONRequestBody CreatePostJSONBody

CreatePostJSONRequestBody defines body for CreatePost for application/json ContentType.

func (CreatePostJSONRequestBody) Bind

Bind implements render.Binder.

type Error

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

Error object returned on any error.

func RespErr

func RespErr(err error) Error

RespErr returns an Error response value from an error.

type FoodCategories

type FoodCategories struct {
	AdditionalProperties map[string][]string `json:"-"`
}

FoodCategories defines model for FoodCategories.

func (FoodCategories) Get

func (a FoodCategories) Get(fieldName string) (value []string, found bool)

Getter for additional properties for FoodCategories. Returns the specified element and whether it was found

func (FoodCategories) MarshalJSON

func (a FoodCategories) MarshalJSON() ([]byte, error)

Override default JSON handling for FoodCategories to handle AdditionalProperties

func (*FoodCategories) Set

func (a *FoodCategories) Set(fieldName string, value []string)

Setter for additional properties for FoodCategories

func (*FoodCategories) UnmarshalJSON

func (a *FoodCategories) UnmarshalJSON(b []byte) error

Override default JSON handling for FoodCategories to handle AdditionalProperties

type FoodPreferences

type FoodPreferences struct {
	Likes   []string       `json:"likes"`
	Prefers FoodCategories `json:"prefers"`
}

FoodPreferences defines model for FoodPreferences.

type FormError

type FormError struct {
	// Embedded struct due to allOf(#/components/schemas/Error)
	Error `yaml:",inline"`
	// Embedded fields due to inline allOf schema
	FormID string `json:"form_id,omitempty"`
}

FormError defines model for FormError.

type GetNextPostsParams

type GetNextPostsParams struct {
	// The ID to start the pagination from, or empty to start from top.
	PrevID *ID `json:"prev_id,omitempty"`
}

GetNextPostsParams defines parameters for GetNextPosts.

type ID

type ID foodtinder.ID

Snowflake ID.

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(b []byte) error

type InvalidParamFormatError

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

func (InvalidParamFormatError) Error

func (err InvalidParamFormatError) Error() string

Error implements error.

func (InvalidParamFormatError) ParamName

func (err InvalidParamFormatError) ParamName() string

func (InvalidParamFormatError) Unwrap

func (err InvalidParamFormatError) Unwrap() error

type LikePostJSONBody

type LikePostJSONBody struct {
	Like *bool `json:"like,omitempty"`
}

LikePostJSONBody defines parameters for LikePost.

type LikePostJSONRequestBody

type LikePostJSONRequestBody LikePostJSONBody

LikePostJSONRequestBody defines body for LikePost for application/json ContentType.

func (LikePostJSONRequestBody) Bind

Bind implements render.Binder.

type LoginMetadata

type LoginMetadata struct {
	// The User-Agent used for logging in.
	UserAgent string `json:"user_agent,omitempty"`
}

Optional metadata included on login.

type LoginParams

type LoginParams struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

LoginParams defines parameters for Login.

type NotFoundError

type NotFoundError FormError

Error object returned on a form error.

type ParameterError

type ParameterError interface {
	error
	// ParamName is the name of the parameter that the error is referring to.
	ParamName() string
}

ParameterName is an interface that is implemented by error types that are relevant to a specific parameter.

type Post

type Post struct {
	CoverHash   string `json:"cover_hash,omitempty"`
	Description string `json:"description"`

	// Snowflake ID.
	ID     ID       `json:"id"`
	Images []string `json:"images"`

	// Likes is the number of likes of this post.
	Likes int `json:"likes"`

	// Location is the location where the post was made.
	Location string   `json:"location,omitempty"`
	Tags     []string `json:"tags"`
	Username string   `json:"username"`
}

Post defines model for Post.

type PostListing

type PostListing struct {
	// Embedded struct due to allOf(#/components/schemas/Post)
	Post `yaml:",inline"`
	// Embedded fields due to inline allOf schema
	Liked bool `json:"liked"`
}

PostListing defines model for PostListing.

type RegisterParams

type RegisterParams struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

RegisterParams defines parameters for Register.

type RegisterSecurityFunc

type RegisterSecurityFunc struct {
	Func    openapi3filter.AuthenticationFunc
	OnError func(w http.ResponseWriter, r *http.Request, err error)
}

RegisterSecurityFunc is a structure containing 2 callbacks needed for RegisterSecurity.

type RequiredHeaderError

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

func (RequiredHeaderError) Error

func (err RequiredHeaderError) Error() string

Error implements error.

func (RequiredHeaderError) ParamName

func (err RequiredHeaderError) ParamName() string

type RequiredParamError

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

func (RequiredParamError) Error

func (err RequiredParamError) Error() string

Error implements error.

func (RequiredParamError) ParamName

func (err RequiredParamError) ParamName() string

func (RequiredParamError) Unwrap

func (err RequiredParamError) Unwrap() error

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 CreatePostJSON200Response

func CreatePostJSON200Response(body Post) *Response

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

func CreatePostJSON400Response

func CreatePostJSON400Response(body Error) *Response

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

func CreatePostJSON500Response

func CreatePostJSON500Response(body Error) *Response

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

func DeletePostJSON404Response

func DeletePostJSON404Response(body FormError) *Response

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

func DeletePostJSON500Response

func DeletePostJSON500Response(body Error) *Response

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

func GetAssetJSON404Response

func GetAssetJSON404Response(body FormError) *Response

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

func GetAssetJSON500Response

func GetAssetJSON500Response(body Error) *Response

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

func GetLikedPostsJSON200Response

func GetLikedPostsJSON200Response(body []Post) *Response

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

func GetLikedPostsJSON500Response

func GetLikedPostsJSON500Response(body Error) *Response

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

func GetNextPostsJSON200Response

func GetNextPostsJSON200Response(body []PostListing) *Response

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

func GetNextPostsJSON400Response

func GetNextPostsJSON400Response(body FormError) *Response

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

func GetNextPostsJSON500Response

func GetNextPostsJSON500Response(body Error) *Response

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

func GetPostJSON200Response

func GetPostJSON200Response(body PostListing) *Response

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

func GetPostJSON404Response

func GetPostJSON404Response(body FormError) *Response

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

func GetPostJSON500Response

func GetPostJSON500Response(body Error) *Response

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

func GetSelfJSON200Response

func GetSelfJSON200Response(body Self) *Response

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

func GetSelfJSON500Response

func GetSelfJSON500Response(body Error) *Response

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

func GetUserJSON200Response

func GetUserJSON200Response(body User) *Response

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

func GetUserJSON400Response

func GetUserJSON400Response(body FormError) *Response

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

func GetUserJSON404Response

func GetUserJSON404Response(body FormError) *Response

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

func GetUserJSON500Response

func GetUserJSON500Response(body Error) *Response

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

func LikePostJSON400Response

func LikePostJSON400Response(body Error) *Response

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

func LikePostJSON404Response

func LikePostJSON404Response(body FormError) *Response

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

func LikePostJSON500Response

func LikePostJSON500Response(body Error) *Response

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

func ListFoodsJSON200Response

func ListFoodsJSON200Response(body FoodCategories) *Response

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

func ListFoodsJSON500Response

func ListFoodsJSON500Response(body Error) *Response

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

func LoginJSON200Response

func LoginJSON200Response(body Session) *Response

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

func LoginJSON401Response

func LoginJSON401Response(body Error) *Response

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

func LoginJSON500Response

func LoginJSON500Response(body Error) *Response

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

func RegisterJSON200Response

func RegisterJSON200Response(body Session) *Response

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

func RegisterJSON400Response

func RegisterJSON400Response(body FormError) *Response

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

func RegisterJSON500Response

func RegisterJSON500Response(body Error) *Response

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

func UploadAssetJSON200Response

func UploadAssetJSON200Response(body string) *Response

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

func UploadAssetJSON400Response

func UploadAssetJSON400Response(body Error) *Response

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

func UploadAssetJSON413Response

func UploadAssetJSON413Response(body Error) *Response

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

func UploadAssetJSON500Response

func UploadAssetJSON500Response(body Error) *Response

UploadAssetJSON500Response is a constructor method for a UploadAsset 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 Self

type Self struct {
	// Embedded struct due to allOf(#/components/schemas/User)
	User `yaml:",inline"`
	// Embedded struct due to allOf(#/components/schemas/FoodPreferences)
	FoodPreferences `yaml:",inline"`
	// Embedded fields due to inline allOf schema
	Birthday *openapi_types.Date `json:"birthday,omitempty"`
}

Self defines model for Self.

type ServerError

type ServerError Error

Error object returned on any error.

type ServerInterface

type ServerInterface interface {
	// Upload an asset
	// (POST /assets)
	UploadAsset(w http.ResponseWriter, r *http.Request) *Response
	// Get the file asset by the given ID. Note that assets are not separated by type; the user must assume the type from the context that the asset ID is from.
	// (GET /assets/{id})
	GetAsset(w http.ResponseWriter, r *http.Request, id string) *Response
	// Get the list of all valid food categories and names.
	// (GET /food/list)
	ListFoods(w http.ResponseWriter, r *http.Request) *Response
	// Log in using username and password. A 401 is returned if the information is incorrect.
	// (POST /login)
	Login(w http.ResponseWriter, r *http.Request, params LoginParams) *Response
	// Get the next batch of posts
	// (GET /posts)
	GetNextPosts(w http.ResponseWriter, r *http.Request, params GetNextPostsParams) *Response
	// Create a new post
	// (POST /posts)
	CreatePost(w http.ResponseWriter, r *http.Request) *Response
	// Get the list of posts liked by the user
	// (GET /posts/like)
	GetLikedPosts(w http.ResponseWriter, r *http.Request) *Response
	// Delete the current user's posts by ID. A 401 is returned if the user tries to delete someone else's post.
	// (DELETE /posts/{id})
	DeletePost(w http.ResponseWriter, r *http.Request, id ID) *Response
	// Get the post with the given ID.
	// (GET /posts/{id})
	GetPost(w http.ResponseWriter, r *http.Request, id ID) *Response
	// Like or unlike the post
	// (POST /posts/{id}/like)
	LikePost(w http.ResponseWriter, r *http.Request, id ID) *Response
	// Register using username and password
	// (POST /register)
	Register(w http.ResponseWriter, r *http.Request, params RegisterParams) *Response
	// Get the current user
	// (GET /users/@self)
	GetSelf(w http.ResponseWriter, r *http.Request) *Response
	// Get a user by their username
	// (GET /users/{username})
	GetUser(w http.ResponseWriter, r *http.Request, username string) *Response
}

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

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

CreatePost operation middleware

func (*ServerInterfaceWrapper) DeletePost

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

DeletePost operation middleware

func (*ServerInterfaceWrapper) GetAsset

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

GetAsset operation middleware

func (*ServerInterfaceWrapper) GetLikedPosts

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

GetLikedPosts operation middleware

func (*ServerInterfaceWrapper) GetNextPosts

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

GetNextPosts operation middleware

func (*ServerInterfaceWrapper) GetPost

GetPost operation middleware

func (*ServerInterfaceWrapper) GetSelf

GetSelf operation middleware

func (*ServerInterfaceWrapper) GetUser

GetUser operation middleware

func (*ServerInterfaceWrapper) LikePost

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

LikePost operation middleware

func (*ServerInterfaceWrapper) ListFoods

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

ListFoods operation middleware

func (*ServerInterfaceWrapper) Login

Login operation middleware

func (*ServerInterfaceWrapper) Register

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

Register operation middleware

func (*ServerInterfaceWrapper) UploadAsset

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

UploadAsset 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 Session

type Session struct {
	Expiry time.Time `json:"expiry"`

	// Optional metadata included on login.
	Metadata LoginMetadata `json:"metadata"`
	Token    string        `json:"token"`
	Username string        `json:"username"`
}

Session defines model for Session.

type TooManyValuesForParamError

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

func (TooManyValuesForParamError) Error

func (err TooManyValuesForParamError) Error() string

Error implements error.

func (TooManyValuesForParamError) ParamName

func (err TooManyValuesForParamError) ParamName() string

type UnescapedCookieParamError

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

func (UnescapedCookieParamError) Error

func (err UnescapedCookieParamError) Error() string

Error implements error.

func (UnescapedCookieParamError) ParamName

func (err UnescapedCookieParamError) ParamName() string

func (UnescapedCookieParamError) Unwrap

func (err UnescapedCookieParamError) Unwrap() error

type UnmarshalingParamError

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

func (UnmarshalingParamError) Error

func (err UnmarshalingParamError) Error() string

Error implements error.

func (UnmarshalingParamError) ParamName

func (err UnmarshalingParamError) ParamName() string

func (UnmarshalingParamError) Unwrap

func (err UnmarshalingParamError) Unwrap() error

type User

type User struct {
	Avatar      string `json:"avatar"`
	Bio         string `json:"bio,omitempty"`
	DisplayName string `json:"display_name,omitempty"`
	Username    string `json:"username"`
}

User defines model for User.

type UserError

type UserError Error

Error object returned on any error.

Jump to

Keyboard shortcuts

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