openapi

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: AGPL-3.0 Imports: 16 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 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 AssertGetTaskV1ResponseConstraints

func AssertGetTaskV1ResponseConstraints(obj GetTaskV1Response) error

AssertGetTaskV1ResponseConstraints checks if the values respects the defined constraints

func AssertGetTaskV1ResponseRequired

func AssertGetTaskV1ResponseRequired(obj GetTaskV1Response) error

AssertGetTaskV1ResponseRequired checks if the required fields are not zero-ed

func AssertGetWorkV1ResponseConstraints

func AssertGetWorkV1ResponseConstraints(obj GetWorkV1Response) error

AssertGetWorkV1ResponseConstraints checks if the values respects the defined constraints

func AssertGetWorkV1ResponseRequired

func AssertGetWorkV1ResponseRequired(obj GetWorkV1Response) error

AssertGetWorkV1ResponseRequired checks if the required fields are not zero-ed

func AssertGetWorkV1TaskConstraints

func AssertGetWorkV1TaskConstraints(obj GetWorkV1Task) error

AssertGetWorkV1TaskConstraints checks if the values respects the defined constraints

func AssertGetWorkV1TaskRequired

func AssertGetWorkV1TaskRequired(obj GetWorkV1Task) error

AssertGetWorkV1TaskRequired checks if the required fields are not zero-ed

func AssertListTasksV1ResponseConstraints

func AssertListTasksV1ResponseConstraints(obj ListTasksV1Response) error

AssertListTasksV1ResponseConstraints checks if the values respects the defined constraints

func AssertListTasksV1ResponseRequired

func AssertListTasksV1ResponseRequired(obj ListTasksV1Response) error

AssertListTasksV1ResponseRequired 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 AssertReportWorkV1RequestConstraints

func AssertReportWorkV1RequestConstraints(obj ReportWorkV1Request) error

AssertReportWorkV1RequestConstraints checks if the values respects the defined constraints

func AssertReportWorkV1RequestRequired

func AssertReportWorkV1RequestRequired(obj ReportWorkV1Request) error

AssertReportWorkV1RequestRequired checks if the required fields are not zero-ed

func AssertReportWorkV1ResponseConstraints

func AssertReportWorkV1ResponseConstraints(obj ReportWorkV1Response) error

AssertReportWorkV1ResponseConstraints checks if the values respects the defined constraints

func AssertReportWorkV1ResponseRequired

func AssertReportWorkV1ResponseRequired(obj ReportWorkV1Response) error

AssertReportWorkV1ResponseRequired checks if the required fields are not zero-ed

func AssertReportWorkV1TaskResultConstraints

func AssertReportWorkV1TaskResultConstraints(obj ReportWorkV1TaskResult) error

AssertReportWorkV1TaskResultConstraints checks if the values respects the defined constraints

func AssertReportWorkV1TaskResultRequired

func AssertReportWorkV1TaskResultRequired(obj ReportWorkV1TaskResult) error

AssertReportWorkV1TaskResultRequired checks if the required fields are not zero-ed

func AssertScheduleRunV1RequestConstraints

func AssertScheduleRunV1RequestConstraints(obj ScheduleRunV1Request) error

AssertScheduleRunV1RequestConstraints checks if the values respects the defined constraints

func AssertScheduleRunV1RequestRequired

func AssertScheduleRunV1RequestRequired(obj ScheduleRunV1Request) error

AssertScheduleRunV1RequestRequired checks if the required fields are not zero-ed

func AssertScheduleRunV1ResponseConstraints

func AssertScheduleRunV1ResponseConstraints(obj ScheduleRunV1Response) error

AssertScheduleRunV1ResponseConstraints checks if the values respects the defined constraints

func AssertScheduleRunV1ResponseRequired

func AssertScheduleRunV1ResponseRequired(obj ScheduleRunV1Response) error

AssertScheduleRunV1ResponseRequired checks if the required fields are not zero-ed

func DefaultErrorHandler

func DefaultErrorHandler(w http.ResponseWriter, _ *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) chi.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 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 string `json:"error"`

	Message string `json:"message"`
}

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 GetTaskV1Response

type GetTaskV1Response struct {
	Name string `json:"name"`

	Hash string `json:"hash"`

	Content string `json:"content"`
}

type GetWorkV1Response

type GetWorkV1Response struct {

	// Internal identifier of the unit of work.
	RunID int32 `json:"runID"`

	// Repository for which to apply the tasks.
	Repository string `json:"repository,omitempty"`

	// Names of the tasks to execute.
	Tasks []GetWorkV1Task `json:"tasks"`
}

type GetWorkV1Task

type GetWorkV1Task struct {

	// Hash of the task. Used to detect if server and worker are out of sync.
	Hash string `json:"hash"`

	// Name of the task to execute.
	Name string `json:"name"`
}

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 ListTasksV1Response

type ListTasksV1Response struct {

	// Names of registered tasks.
	Tasks []string `json:"tasks"`
}

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 {
	Param string
	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 ReportWorkV1Request

type ReportWorkV1Request struct {

	// General that occurred during the run, if any.
	Error string `json:"error,omitempty"`

	// Internal identifier of the unit of work.
	RunID int32 `json:"runID"`

	// Results of each task.
	TaskResults []ReportWorkV1TaskResult `json:"taskResults,omitempty"`
}

type ReportWorkV1Response

type ReportWorkV1Response struct {

	// Indicator of the result of the operation.
	Result string `json:"result"`
}

type ReportWorkV1TaskResult

type ReportWorkV1TaskResult struct {

	// Error encountered during the run, if any.
	Error string `json:"error,omitempty"`

	// Name of the repository.
	RepositoryName string `json:"repositoryName"`

	// Identifier of the result.
	Result int32 `json:"result,omitempty"`

	// Name of the task.
	TaskName string `json:"taskName"`
}

ReportWorkV1TaskResult - Result of the run of a task.

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

type Routes

type Routes map[string]Route

Routes is a map of defined api endpoints

type ScheduleRunV1Request

type ScheduleRunV1Request struct {

	// Name of the repository for which to add a run. If empty, the run uses the filters of the task.
	RepositoryName string `json:"repositoryName,omitempty"`

	// Schedule the run after the given time. If empty, then the current time is used.
	ScheduleAfter time.Time `json:"scheduleAfter,omitempty"`

	// Name of the task for which to add a run.
	TaskName string `json:"taskName"`

	RunData map[string]string `json:"runData,omitempty"`
}

type ScheduleRunV1Response

type ScheduleRunV1Response struct {

	// Identifier of the newly scheduled run.
	RunID int32 `json:"runID"`
}

type TaskAPIController

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

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

func NewTaskAPIController

func NewTaskAPIController(s TaskAPIServicer, opts ...TaskAPIOption) *TaskAPIController

NewTaskAPIController creates a default api controller

func (*TaskAPIController) GetTaskV1

func (c *TaskAPIController) GetTaskV1(w http.ResponseWriter, r *http.Request)

GetTaskV1 - Get information about a task.

func (*TaskAPIController) ListTasksV1

func (c *TaskAPIController) ListTasksV1(w http.ResponseWriter, r *http.Request)

ListTasksV1 - List tasks.

func (*TaskAPIController) Routes

func (c *TaskAPIController) Routes() Routes

Routes returns all the api routes for the TaskAPIController

type TaskAPIOption

type TaskAPIOption func(*TaskAPIController)

TaskAPIOption for how the controller is set up.

func WithTaskAPIErrorHandler

func WithTaskAPIErrorHandler(h ErrorHandler) TaskAPIOption

WithTaskAPIErrorHandler inject ErrorHandler into controller

type TaskAPIRouter

type TaskAPIRouter interface {
	GetTaskV1(http.ResponseWriter, *http.Request)
	ListTasksV1(http.ResponseWriter, *http.Request)
}

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

type TaskAPIServicer

type TaskAPIServicer interface {
	GetTaskV1(context.Context, string) (ImplResponse, error)
	ListTasksV1(context.Context) (ImplResponse, error)
}

TaskAPIServicer defines the api actions for the TaskAPI 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 WorkerAPIController

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

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

func NewWorkerAPIController

func NewWorkerAPIController(s WorkerAPIServicer, opts ...WorkerAPIOption) *WorkerAPIController

NewWorkerAPIController creates a default api controller

func (*WorkerAPIController) GetWorkV1

func (c *WorkerAPIController) GetWorkV1(w http.ResponseWriter, r *http.Request)

GetWorkV1 - Get a unit of work.

func (*WorkerAPIController) ReportWorkV1

func (c *WorkerAPIController) ReportWorkV1(w http.ResponseWriter, r *http.Request)

ReportWorkV1 - Report the result of a unit of work

func (*WorkerAPIController) Routes

func (c *WorkerAPIController) Routes() Routes

Routes returns all the api routes for the WorkerAPIController

func (*WorkerAPIController) ScheduleRunV1

func (c *WorkerAPIController) ScheduleRunV1(w http.ResponseWriter, r *http.Request)

ScheduleRunV1 - Schedule a run.

type WorkerAPIOption

type WorkerAPIOption func(*WorkerAPIController)

WorkerAPIOption for how the controller is set up.

func WithWorkerAPIErrorHandler

func WithWorkerAPIErrorHandler(h ErrorHandler) WorkerAPIOption

WithWorkerAPIErrorHandler inject ErrorHandler into controller

type WorkerAPIRouter

type WorkerAPIRouter interface {
	GetWorkV1(http.ResponseWriter, *http.Request)
	ReportWorkV1(http.ResponseWriter, *http.Request)
	ScheduleRunV1(http.ResponseWriter, *http.Request)
}

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

type WorkerAPIServicer

type WorkerAPIServicer interface {
	GetWorkV1(context.Context) (ImplResponse, error)
	ReportWorkV1(context.Context, ReportWorkV1Request) (ImplResponse, error)
	ScheduleRunV1(context.Context, ScheduleRunV1Request) (ImplResponse, error)
}

WorkerAPIServicer defines the api actions for the WorkerAPI 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.

Jump to

Keyboard shortcuts

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