fix(tester):
This commit is contained in:
parent
dba24ab6ec
commit
ba46086058
1 changed files with 0 additions and 497 deletions
|
@ -1,497 +0,0 @@
|
|||
// Package testerv1 provides primitives to interact with the openapi HTTP API.
|
||||
//
|
||||
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.4.1 DO NOT EDIT.
|
||||
package testerv1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/oapi-codegen/runtime"
|
||||
)
|
||||
|
||||
const (
|
||||
BearerAuthScopes = "bearerAuth.Scopes"
|
||||
)
|
||||
|
||||
// AddParticipantResponse defines model for AddParticipantResponse.
|
||||
type AddParticipantResponse struct {
|
||||
Id int32 `json:"id"`
|
||||
}
|
||||
|
||||
// AddTaskResponse defines model for AddTaskResponse.
|
||||
type AddTaskResponse struct {
|
||||
Id int32 `json:"id"`
|
||||
}
|
||||
|
||||
// BestSolution defines model for BestSolution.
|
||||
type BestSolution struct {
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Id int32 `json:"id"`
|
||||
Language int32 `json:"language"`
|
||||
ParticipantId int32 `json:"participant_id"`
|
||||
Penalty int32 `json:"penalty"`
|
||||
Score int32 `json:"score"`
|
||||
State int32 `json:"state"`
|
||||
TaskId int32 `json:"task_id"`
|
||||
TotalScore int32 `json:"total_score"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// Contest defines model for Contest.
|
||||
type Contest struct {
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Id int32 `json:"id"`
|
||||
Title string `json:"title"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// CreateContestResponse defines model for CreateContestResponse.
|
||||
type CreateContestResponse struct {
|
||||
Id int32 `json:"id"`
|
||||
}
|
||||
|
||||
// CreateProblemResponse defines model for CreateProblemResponse.
|
||||
type CreateProblemResponse struct {
|
||||
Id int32 `json:"id"`
|
||||
}
|
||||
|
||||
// GetContestResponse defines model for GetContestResponse.
|
||||
type GetContestResponse struct {
|
||||
Contest Contest `json:"contest"`
|
||||
Tasks []struct {
|
||||
BestSolution BestSolution `json:"best_solution"`
|
||||
Task RichTask `json:"task"`
|
||||
} `json:"tasks"`
|
||||
}
|
||||
|
||||
// GetProblemResponse defines model for GetProblemResponse.
|
||||
type GetProblemResponse struct {
|
||||
Problem Problem `json:"problem"`
|
||||
}
|
||||
|
||||
// ListContestsResponse defines model for ListContestsResponse.
|
||||
type ListContestsResponse struct {
|
||||
Contests []Contest `json:"contests"`
|
||||
}
|
||||
|
||||
// ListProblemsResponse defines model for ListProblemsResponse.
|
||||
type ListProblemsResponse struct {
|
||||
Problems []Problem `json:"problems"`
|
||||
}
|
||||
|
||||
// Problem defines model for Problem.
|
||||
type Problem struct {
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Id int32 `json:"id"`
|
||||
InputFormat string `json:"input_format"`
|
||||
LatexSummary string `json:"latex_summary"`
|
||||
Legend string `json:"legend"`
|
||||
MemoryLimit int32 `json:"memory_limit"`
|
||||
Notes string `json:"notes"`
|
||||
OutputFormat string `json:"output_format"`
|
||||
TimeLimit int32 `json:"time_limit"`
|
||||
Title string `json:"title"`
|
||||
Tutorial string `json:"tutorial"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// RichTask defines model for RichTask.
|
||||
type RichTask struct {
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Id int32 `json:"id"`
|
||||
MemoryLimit int32 `json:"memory_limit"`
|
||||
Position int32 `json:"position"`
|
||||
ProblemId int32 `json:"problem_id"`
|
||||
TimeLimit int32 `json:"time_limit"`
|
||||
Title string `json:"title"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// DeleteParticipantParams defines parameters for DeleteParticipant.
|
||||
type DeleteParticipantParams struct {
|
||||
ParticipantId int32 `form:"participant_id" json:"participant_id"`
|
||||
}
|
||||
|
||||
// AddParticipantParams defines parameters for AddParticipant.
|
||||
type AddParticipantParams struct {
|
||||
UserId int32 `form:"user_id" json:"user_id"`
|
||||
}
|
||||
|
||||
// DeleteTaskParams defines parameters for DeleteTask.
|
||||
type DeleteTaskParams struct {
|
||||
TaskId int32 `form:"task_id" json:"task_id"`
|
||||
}
|
||||
|
||||
// AddTaskParams defines parameters for AddTask.
|
||||
type AddTaskParams struct {
|
||||
ProblemId int32 `form:"problem_id" json:"problem_id"`
|
||||
}
|
||||
|
||||
// ServerInterface represents all server handlers.
|
||||
type ServerInterface interface {
|
||||
|
||||
// (GET /contests)
|
||||
ListContests(c *fiber.Ctx) error
|
||||
|
||||
// (POST /contests)
|
||||
CreateContest(c *fiber.Ctx) error
|
||||
|
||||
// (DELETE /contests/{id})
|
||||
DeleteContest(c *fiber.Ctx, id int32) error
|
||||
|
||||
// (GET /contests/{id})
|
||||
GetContest(c *fiber.Ctx, id int32) error
|
||||
|
||||
// (DELETE /contests/{id}/participants)
|
||||
DeleteParticipant(c *fiber.Ctx, id int32, params DeleteParticipantParams) error
|
||||
|
||||
// (POST /contests/{id}/participants)
|
||||
AddParticipant(c *fiber.Ctx, id int32, params AddParticipantParams) error
|
||||
|
||||
// (DELETE /contests/{id}/tasks)
|
||||
DeleteTask(c *fiber.Ctx, id int32, params DeleteTaskParams) error
|
||||
|
||||
// (POST /contests/{id}/tasks)
|
||||
AddTask(c *fiber.Ctx, id int32, params AddTaskParams) error
|
||||
|
||||
// (GET /problems)
|
||||
ListProblems(c *fiber.Ctx) error
|
||||
|
||||
// (POST /problems)
|
||||
CreateProblem(c *fiber.Ctx) error
|
||||
|
||||
// (DELETE /problems/{id})
|
||||
DeleteProblem(c *fiber.Ctx, id int32) error
|
||||
|
||||
// (GET /problems/{id})
|
||||
GetProblem(c *fiber.Ctx, id int32) error
|
||||
}
|
||||
|
||||
// ServerInterfaceWrapper converts contexts to parameters.
|
||||
type ServerInterfaceWrapper struct {
|
||||
Handler ServerInterface
|
||||
}
|
||||
|
||||
type MiddlewareFunc fiber.Handler
|
||||
|
||||
// ListContests operation middleware
|
||||
func (siw *ServerInterfaceWrapper) ListContests(c *fiber.Ctx) error {
|
||||
|
||||
c.Context().SetUserValue(BearerAuthScopes, []string{})
|
||||
|
||||
return siw.Handler.ListContests(c)
|
||||
}
|
||||
|
||||
// CreateContest operation middleware
|
||||
func (siw *ServerInterfaceWrapper) CreateContest(c *fiber.Ctx) error {
|
||||
|
||||
c.Context().SetUserValue(BearerAuthScopes, []string{})
|
||||
|
||||
return siw.Handler.CreateContest(c)
|
||||
}
|
||||
|
||||
// DeleteContest operation middleware
|
||||
func (siw *ServerInterfaceWrapper) DeleteContest(c *fiber.Ctx) error {
|
||||
|
||||
var err error
|
||||
|
||||
// ------------- Path parameter "id" -------------
|
||||
var id int32
|
||||
|
||||
err = runtime.BindStyledParameterWithOptions("simple", "id", c.Params("id"), &id, runtime.BindStyledParameterOptions{Explode: false, Required: true})
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Errorf("Invalid format for parameter id: %w", err).Error())
|
||||
}
|
||||
|
||||
c.Context().SetUserValue(BearerAuthScopes, []string{})
|
||||
|
||||
return siw.Handler.DeleteContest(c, id)
|
||||
}
|
||||
|
||||
// GetContest operation middleware
|
||||
func (siw *ServerInterfaceWrapper) GetContest(c *fiber.Ctx) error {
|
||||
|
||||
var err error
|
||||
|
||||
// ------------- Path parameter "id" -------------
|
||||
var id int32
|
||||
|
||||
err = runtime.BindStyledParameterWithOptions("simple", "id", c.Params("id"), &id, runtime.BindStyledParameterOptions{Explode: false, Required: true})
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Errorf("Invalid format for parameter id: %w", err).Error())
|
||||
}
|
||||
|
||||
c.Context().SetUserValue(BearerAuthScopes, []string{})
|
||||
|
||||
return siw.Handler.GetContest(c, id)
|
||||
}
|
||||
|
||||
// DeleteParticipant operation middleware
|
||||
func (siw *ServerInterfaceWrapper) DeleteParticipant(c *fiber.Ctx) error {
|
||||
|
||||
var err error
|
||||
|
||||
// ------------- Path parameter "id" -------------
|
||||
var id int32
|
||||
|
||||
err = runtime.BindStyledParameterWithOptions("simple", "id", c.Params("id"), &id, runtime.BindStyledParameterOptions{Explode: false, Required: true})
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Errorf("Invalid format for parameter id: %w", err).Error())
|
||||
}
|
||||
|
||||
c.Context().SetUserValue(BearerAuthScopes, []string{})
|
||||
|
||||
// Parameter object where we will unmarshal all parameters from the context
|
||||
var params DeleteParticipantParams
|
||||
|
||||
var query url.Values
|
||||
query, err = url.ParseQuery(string(c.Request().URI().QueryString()))
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Errorf("Invalid format for query string: %w", err).Error())
|
||||
}
|
||||
|
||||
// ------------- Required query parameter "participant_id" -------------
|
||||
|
||||
if paramValue := c.Query("participant_id"); paramValue != "" {
|
||||
|
||||
} else {
|
||||
err = fmt.Errorf("Query argument participant_id is required, but not found")
|
||||
c.Status(fiber.StatusBadRequest).JSON(err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = runtime.BindQueryParameter("form", true, true, "participant_id", query, ¶ms.ParticipantId)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Errorf("Invalid format for parameter participant_id: %w", err).Error())
|
||||
}
|
||||
|
||||
return siw.Handler.DeleteParticipant(c, id, params)
|
||||
}
|
||||
|
||||
// AddParticipant operation middleware
|
||||
func (siw *ServerInterfaceWrapper) AddParticipant(c *fiber.Ctx) error {
|
||||
|
||||
var err error
|
||||
|
||||
// ------------- Path parameter "id" -------------
|
||||
var id int32
|
||||
|
||||
err = runtime.BindStyledParameterWithOptions("simple", "id", c.Params("id"), &id, runtime.BindStyledParameterOptions{Explode: false, Required: true})
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Errorf("Invalid format for parameter id: %w", err).Error())
|
||||
}
|
||||
|
||||
c.Context().SetUserValue(BearerAuthScopes, []string{})
|
||||
|
||||
// Parameter object where we will unmarshal all parameters from the context
|
||||
var params AddParticipantParams
|
||||
|
||||
var query url.Values
|
||||
query, err = url.ParseQuery(string(c.Request().URI().QueryString()))
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Errorf("Invalid format for query string: %w", err).Error())
|
||||
}
|
||||
|
||||
// ------------- Required query parameter "user_id" -------------
|
||||
|
||||
if paramValue := c.Query("user_id"); paramValue != "" {
|
||||
|
||||
} else {
|
||||
err = fmt.Errorf("Query argument user_id is required, but not found")
|
||||
c.Status(fiber.StatusBadRequest).JSON(err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = runtime.BindQueryParameter("form", true, true, "user_id", query, ¶ms.UserId)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Errorf("Invalid format for parameter user_id: %w", err).Error())
|
||||
}
|
||||
|
||||
return siw.Handler.AddParticipant(c, id, params)
|
||||
}
|
||||
|
||||
// DeleteTask operation middleware
|
||||
func (siw *ServerInterfaceWrapper) DeleteTask(c *fiber.Ctx) error {
|
||||
|
||||
var err error
|
||||
|
||||
// ------------- Path parameter "id" -------------
|
||||
var id int32
|
||||
|
||||
err = runtime.BindStyledParameterWithOptions("simple", "id", c.Params("id"), &id, runtime.BindStyledParameterOptions{Explode: false, Required: true})
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Errorf("Invalid format for parameter id: %w", err).Error())
|
||||
}
|
||||
|
||||
c.Context().SetUserValue(BearerAuthScopes, []string{})
|
||||
|
||||
// Parameter object where we will unmarshal all parameters from the context
|
||||
var params DeleteTaskParams
|
||||
|
||||
var query url.Values
|
||||
query, err = url.ParseQuery(string(c.Request().URI().QueryString()))
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Errorf("Invalid format for query string: %w", err).Error())
|
||||
}
|
||||
|
||||
// ------------- Required query parameter "task_id" -------------
|
||||
|
||||
if paramValue := c.Query("task_id"); paramValue != "" {
|
||||
|
||||
} else {
|
||||
err = fmt.Errorf("Query argument task_id is required, but not found")
|
||||
c.Status(fiber.StatusBadRequest).JSON(err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = runtime.BindQueryParameter("form", true, true, "task_id", query, ¶ms.TaskId)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Errorf("Invalid format for parameter task_id: %w", err).Error())
|
||||
}
|
||||
|
||||
return siw.Handler.DeleteTask(c, id, params)
|
||||
}
|
||||
|
||||
// AddTask operation middleware
|
||||
func (siw *ServerInterfaceWrapper) AddTask(c *fiber.Ctx) error {
|
||||
|
||||
var err error
|
||||
|
||||
// ------------- Path parameter "id" -------------
|
||||
var id int32
|
||||
|
||||
err = runtime.BindStyledParameterWithOptions("simple", "id", c.Params("id"), &id, runtime.BindStyledParameterOptions{Explode: false, Required: true})
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Errorf("Invalid format for parameter id: %w", err).Error())
|
||||
}
|
||||
|
||||
c.Context().SetUserValue(BearerAuthScopes, []string{})
|
||||
|
||||
// Parameter object where we will unmarshal all parameters from the context
|
||||
var params AddTaskParams
|
||||
|
||||
var query url.Values
|
||||
query, err = url.ParseQuery(string(c.Request().URI().QueryString()))
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Errorf("Invalid format for query string: %w", err).Error())
|
||||
}
|
||||
|
||||
// ------------- Required query parameter "problem_id" -------------
|
||||
|
||||
if paramValue := c.Query("problem_id"); paramValue != "" {
|
||||
|
||||
} else {
|
||||
err = fmt.Errorf("Query argument problem_id is required, but not found")
|
||||
c.Status(fiber.StatusBadRequest).JSON(err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = runtime.BindQueryParameter("form", true, true, "problem_id", query, ¶ms.ProblemId)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Errorf("Invalid format for parameter problem_id: %w", err).Error())
|
||||
}
|
||||
|
||||
return siw.Handler.AddTask(c, id, params)
|
||||
}
|
||||
|
||||
// ListProblems operation middleware
|
||||
func (siw *ServerInterfaceWrapper) ListProblems(c *fiber.Ctx) error {
|
||||
|
||||
c.Context().SetUserValue(BearerAuthScopes, []string{})
|
||||
|
||||
return siw.Handler.ListProblems(c)
|
||||
}
|
||||
|
||||
// CreateProblem operation middleware
|
||||
func (siw *ServerInterfaceWrapper) CreateProblem(c *fiber.Ctx) error {
|
||||
|
||||
c.Context().SetUserValue(BearerAuthScopes, []string{})
|
||||
|
||||
return siw.Handler.CreateProblem(c)
|
||||
}
|
||||
|
||||
// DeleteProblem operation middleware
|
||||
func (siw *ServerInterfaceWrapper) DeleteProblem(c *fiber.Ctx) error {
|
||||
|
||||
var err error
|
||||
|
||||
// ------------- Path parameter "id" -------------
|
||||
var id int32
|
||||
|
||||
err = runtime.BindStyledParameterWithOptions("simple", "id", c.Params("id"), &id, runtime.BindStyledParameterOptions{Explode: false, Required: true})
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Errorf("Invalid format for parameter id: %w", err).Error())
|
||||
}
|
||||
|
||||
c.Context().SetUserValue(BearerAuthScopes, []string{})
|
||||
|
||||
return siw.Handler.DeleteProblem(c, id)
|
||||
}
|
||||
|
||||
// GetProblem operation middleware
|
||||
func (siw *ServerInterfaceWrapper) GetProblem(c *fiber.Ctx) error {
|
||||
|
||||
var err error
|
||||
|
||||
// ------------- Path parameter "id" -------------
|
||||
var id int32
|
||||
|
||||
err = runtime.BindStyledParameterWithOptions("simple", "id", c.Params("id"), &id, runtime.BindStyledParameterOptions{Explode: false, Required: true})
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Errorf("Invalid format for parameter id: %w", err).Error())
|
||||
}
|
||||
|
||||
c.Context().SetUserValue(BearerAuthScopes, []string{})
|
||||
|
||||
return siw.Handler.GetProblem(c, id)
|
||||
}
|
||||
|
||||
// FiberServerOptions provides options for the Fiber server.
|
||||
type FiberServerOptions struct {
|
||||
BaseURL string
|
||||
Middlewares []MiddlewareFunc
|
||||
}
|
||||
|
||||
// RegisterHandlers creates http.Handler with routing matching OpenAPI spec.
|
||||
func RegisterHandlers(router fiber.Router, si ServerInterface) {
|
||||
RegisterHandlersWithOptions(router, si, FiberServerOptions{})
|
||||
}
|
||||
|
||||
// RegisterHandlersWithOptions creates http.Handler with additional options
|
||||
func RegisterHandlersWithOptions(router fiber.Router, si ServerInterface, options FiberServerOptions) {
|
||||
wrapper := ServerInterfaceWrapper{
|
||||
Handler: si,
|
||||
}
|
||||
|
||||
for _, m := range options.Middlewares {
|
||||
router.Use(fiber.Handler(m))
|
||||
}
|
||||
|
||||
router.Get(options.BaseURL+"/contests", wrapper.ListContests)
|
||||
|
||||
router.Post(options.BaseURL+"/contests", wrapper.CreateContest)
|
||||
|
||||
router.Delete(options.BaseURL+"/contests/:id", wrapper.DeleteContest)
|
||||
|
||||
router.Get(options.BaseURL+"/contests/:id", wrapper.GetContest)
|
||||
|
||||
router.Delete(options.BaseURL+"/contests/:id/participants", wrapper.DeleteParticipant)
|
||||
|
||||
router.Post(options.BaseURL+"/contests/:id/participants", wrapper.AddParticipant)
|
||||
|
||||
router.Delete(options.BaseURL+"/contests/:id/tasks", wrapper.DeleteTask)
|
||||
|
||||
router.Post(options.BaseURL+"/contests/:id/tasks", wrapper.AddTask)
|
||||
|
||||
router.Get(options.BaseURL+"/problems", wrapper.ListProblems)
|
||||
|
||||
router.Post(options.BaseURL+"/problems", wrapper.CreateProblem)
|
||||
|
||||
router.Delete(options.BaseURL+"/problems/:id", wrapper.DeleteProblem)
|
||||
|
||||
router.Get(options.BaseURL+"/problems/:id", wrapper.GetProblem)
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue