openapi

package
v0.0.0-...-730913c Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTypeAssertionError is thrown when type an interface does not match the asserted type
	ErrTypeAssertionError = errors.New("unable to assert type")
)

Functions

func AssertAmountConstraints

func AssertAmountConstraints(obj Amount) error

AssertAmountConstraints checks if the values respects the defined constraints

func AssertAmountRequired

func AssertAmountRequired(obj Amount) error

AssertAmountRequired checks if the required fields are not zero-ed

func AssertCommentRequestConstraints

func AssertCommentRequestConstraints(obj CommentRequest) error

AssertCommentRequestConstraints checks if the values respects the defined constraints

func AssertCommentRequestRequired

func AssertCommentRequestRequired(obj CommentRequest) error

AssertCommentRequestRequired checks if the required fields are not zero-ed

func AssertErrorConstraints

func AssertErrorConstraints(obj Error) error

AssertErrorConstraints checks if the values respects the defined constraints

func AssertErrorRequired

func AssertErrorRequired(obj Error) error

AssertErrorRequired checks if the required fields are not zero-ed

func AssertLoginRequestConstraints

func AssertLoginRequestConstraints(obj LoginRequest) error

AssertLoginRequestConstraints checks if the values respects the defined constraints

func AssertLoginRequestRequired

func AssertLoginRequestRequired(obj LoginRequest) error

AssertLoginRequestRequired checks if the required fields are not zero-ed

func AssertRecurseInterfaceRequired

func AssertRecurseInterfaceRequired[T any](obj interface{}, callback func(T) error) error

AssertRecurseInterfaceRequired recursively checks each struct in a slice against the callback. This method traverse nested slices in a preorder fashion.

func AssertRecurseValueRequired

func AssertRecurseValueRequired[T any](value reflect.Value, callback func(T) error) error

AssertRecurseValueRequired checks each struct in the nested slice against the callback. This method traverse nested slices in a preorder fashion. ErrTypeAssertionError is thrown if the underlying struct does not match type T.

func AssertStatisticConstraints

func AssertStatisticConstraints(obj Statistic) error

AssertStatisticConstraints checks if the values respects the defined constraints

func AssertStatisticRequired

func AssertStatisticRequired(obj Statistic) error

AssertStatisticRequired checks if the required fields are not zero-ed

func AssertStatisticsResponseConstraints

func AssertStatisticsResponseConstraints(obj StatisticsResponse) error

AssertStatisticsResponseConstraints checks if the values respects the defined constraints

func AssertStatisticsResponseRequired

func AssertStatisticsResponseRequired(obj StatisticsResponse) error

AssertStatisticsResponseRequired checks if the required fields are not zero-ed

func DefaultErrorHandler

func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, err error, result *ImplResponse)

DefaultErrorHandler defines the default logic on how to handle errors from the controller. Any errors from parsing request params will return a StatusBadRequest. Otherwise, the error code originating from the servicer will be used.

func EncodeJSONResponse

func EncodeJSONResponse(i interface{}, status *int, w http.ResponseWriter) error

EncodeJSONResponse uses the json encoder to write an interface to the http response with an optional status code

func IsZeroValue

func IsZeroValue(val interface{}) bool

IsZeroValue checks if the val is the zero-ed value.

func Logger

func Logger(inner http.Handler, name string) http.Handler

func NewRouter

func NewRouter(routers ...Router) *mux.Router

NewRouter creates a new router for any number of api routers

func ReadFormFileToTempFile

func ReadFormFileToTempFile(r *http.Request, key string) (*os.File, error)

ReadFormFileToTempFile reads file data from a request form and writes it to a temporary file

func ReadFormFilesToTempFiles

func ReadFormFilesToTempFiles(r *http.Request, key string) ([]*os.File, error)

ReadFormFilesToTempFiles reads files array data from a request form and writes it to a temporary files

Types

type Amount

type Amount struct {
	Blog int32 `json:"blog"`

	Comment int32 `json:"comment"`
}

type AuthenticationAPIController

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

AuthenticationAPIController binds http requests to an api service and writes the service results to the http response

func (*AuthenticationAPIController) PostLogin

PostLogin - provides JWT token

func (*AuthenticationAPIController) Routes

func (c *AuthenticationAPIController) Routes() Routes

Routes returns all the api routes for the AuthenticationAPIController

type AuthenticationAPIOption

type AuthenticationAPIOption func(*AuthenticationAPIController)

AuthenticationAPIOption for how the controller is set up.

func WithAuthenticationAPIErrorHandler

func WithAuthenticationAPIErrorHandler(h ErrorHandler) AuthenticationAPIOption

WithAuthenticationAPIErrorHandler inject ErrorHandler into controller

type AuthenticationAPIRouter

type AuthenticationAPIRouter interface {
	PostLogin(http.ResponseWriter, *http.Request)
}

AuthenticationAPIRouter defines the required methods for binding the api requests to a responses for the AuthenticationAPI The AuthenticationAPIRouter implementation should parse necessary information from the http request, pass the data to a AuthenticationAPIServicer to perform the required actions, then write the service results to the http response.

type AuthenticationAPIServicer

type AuthenticationAPIServicer interface {
	PostLogin(context.Context, LoginRequest) (ImplResponse, error)
}

AuthenticationAPIServicer defines the api actions for the AuthenticationAPI service This interface intended to stay up to date with the openapi yaml used to generate it, while the service implementation can be ignored with the .openapi-generator-ignore file and updated with the logic required for the API.

type CommentAPIController

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

CommentAPIController binds http requests to an api service and writes the service results to the http response

func (*CommentAPIController) PostComment

func (c *CommentAPIController) PostComment(w http.ResponseWriter, r *http.Request)

PostComment - Saves a new Comment

func (*CommentAPIController) Routes

func (c *CommentAPIController) Routes() Routes

Routes returns all the api routes for the CommentAPIController

type CommentAPIOption

type CommentAPIOption func(*CommentAPIController)

CommentAPIOption for how the controller is set up.

func WithCommentAPIErrorHandler

func WithCommentAPIErrorHandler(h ErrorHandler) CommentAPIOption

WithCommentAPIErrorHandler inject ErrorHandler into controller

type CommentAPIRouter

type CommentAPIRouter interface {
	PostComment(http.ResponseWriter, *http.Request)
}

CommentAPIRouter defines the required methods for binding the api requests to a responses for the CommentAPI The CommentAPIRouter implementation should parse necessary information from the http request, pass the data to a CommentAPIServicer to perform the required actions, then write the service results to the http response.

type CommentAPIServicer

type CommentAPIServicer interface {
	PostComment(context.Context, int32, string, CommentRequest) (ImplResponse, error)
}

CommentAPIServicer defines the api actions for the CommentAPI service This interface intended to stay up to date with the openapi yaml used to generate it, while the service implementation can be ignored with the .openapi-generator-ignore file and updated with the logic required for the API.

type CommentRequest

type CommentRequest struct {
	Content string `json:"content"`
}

type Constraint

type Constraint[T Number | string | bool] func(actual T) error

func WithMaximum

func WithMaximum[T Number](expected T) Constraint[T]

func WithMinimum

func WithMinimum[T Number](expected T) Constraint[T]

type Error

type Error struct {

	// Error message
	Message string `json:"message"`

	// The timestamp the error has occured
	Timestamp string `json:"timestamp"`
}

Error - Error object

type ErrorHandler

type ErrorHandler func(w http.ResponseWriter, r *http.Request, err error, result *ImplResponse)

ErrorHandler defines the required method for handling error. You may implement it and inject this into a controller if you would like errors to be handled differently from the DefaultErrorHandler

type ImplResponse

type ImplResponse struct {
	Code int
	Body interface{}
}

ImplResponse defines an implementation response with error code and the associated body

func Response

func Response(code int, body interface{}) ImplResponse

Response return a ImplResponse struct filled

type LoginRequest

type LoginRequest struct {
	User string `json:"user"`

	Pw string `json:"pw"`
}

type Number

type Number interface {
	~int32 | ~int64 | ~float32 | ~float64
}

type Operation

type Operation[T Number | string | bool] func(actual string) (T, bool, error)

func WithDefaultOrParse

func WithDefaultOrParse[T Number | string | bool](def T, parse ParseString[T]) Operation[T]

func WithParse

func WithParse[T Number | string | bool](parse ParseString[T]) Operation[T]

func WithRequire

func WithRequire[T Number | string | bool](parse ParseString[T]) Operation[T]

type ParseString

type ParseString[T Number | string | bool] func(v string) (T, error)

type ParsingError

type ParsingError struct {
	Err error
}

ParsingError indicates that an error has occurred when parsing request parameters

func (*ParsingError) Error

func (e *ParsingError) Error() string

func (*ParsingError) Unwrap

func (e *ParsingError) Unwrap() error

type RequiredError

type RequiredError struct {
	Field string
}

RequiredError indicates that an error has occurred when parsing request parameters

func (*RequiredError) Error

func (e *RequiredError) Error() string

type Route

type Route struct {
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

A Route defines the parameters for an api endpoint

type Router

type Router interface {
	Routes() Routes
}

Router defines the required methods for retrieving api routes

func NewAuthenticationAPIController

func NewAuthenticationAPIController(s AuthenticationAPIServicer, opts ...AuthenticationAPIOption) Router

NewAuthenticationAPIController creates a default api controller

func NewCommentAPIController

func NewCommentAPIController(s CommentAPIServicer, opts ...CommentAPIOption) Router

NewCommentAPIController creates a default api controller

func NewStatisticsAPIController

func NewStatisticsAPIController(s StatisticsAPIServicer, opts ...StatisticsAPIOption) Router

NewStatisticsAPIController creates a default api controller

type Routes

type Routes map[string]Route

Routes is a map of defined api endpoints

type Statistic

type Statistic struct {
	Userid string `json:"userid"`

	Amount Amount `json:"amount"`
}

type StatisticsAPIController

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

StatisticsAPIController binds http requests to an api service and writes the service results to the http response

func (*StatisticsAPIController) GetStatistics

func (c *StatisticsAPIController) GetStatistics(w http.ResponseWriter, r *http.Request)

GetStatistics - Provides statistics about user activity

func (*StatisticsAPIController) Routes

func (c *StatisticsAPIController) Routes() Routes

Routes returns all the api routes for the StatisticsAPIController

type StatisticsAPIOption

type StatisticsAPIOption func(*StatisticsAPIController)

StatisticsAPIOption for how the controller is set up.

func WithStatisticsAPIErrorHandler

func WithStatisticsAPIErrorHandler(h ErrorHandler) StatisticsAPIOption

WithStatisticsAPIErrorHandler inject ErrorHandler into controller

type StatisticsAPIRouter

type StatisticsAPIRouter interface {
	GetStatistics(http.ResponseWriter, *http.Request)
}

StatisticsAPIRouter defines the required methods for binding the api requests to a responses for the StatisticsAPI The StatisticsAPIRouter implementation should parse necessary information from the http request, pass the data to a StatisticsAPIServicer to perform the required actions, then write the service results to the http response.

type StatisticsAPIServicer

type StatisticsAPIServicer interface {
	GetStatistics(context.Context, int32) (ImplResponse, error)
}

StatisticsAPIServicer defines the api actions for the StatisticsAPI service This interface intended to stay up to date with the openapi yaml used to generate it, while the service implementation can be ignored with the .openapi-generator-ignore file and updated with the logic required for the API.

type StatisticsResponse

type StatisticsResponse struct {
	Size int32 `json:"size,omitempty"`

	BeforeThisDate time.Time `json:"beforeThisDate,omitempty"`

	Items []Statistic `json:"items,omitempty"`
}

Jump to

Keyboard shortcuts

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