424 lines
12 KiB
Go
424 lines
12 KiB
Go
// Package api provides primitives to interact with the openapi HTTP API.
|
|
//
|
|
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.6.0 DO NOT EDIT.
|
|
package api
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
openapi_types "github.com/oapi-codegen/runtime/types"
|
|
)
|
|
|
|
// Defines values for RegisterRequestRole.
|
|
const (
|
|
Admin RegisterRequestRole = "admin"
|
|
Client RegisterRequestRole = "client"
|
|
Driver RegisterRequestRole = "driver"
|
|
Manager RegisterRequestRole = "manager"
|
|
)
|
|
|
|
// Valid indicates whether the value is a known member of the RegisterRequestRole enum.
|
|
func (e RegisterRequestRole) Valid() bool {
|
|
switch e {
|
|
case Admin:
|
|
return true
|
|
case Client:
|
|
return true
|
|
case Driver:
|
|
return true
|
|
case Manager:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// ApiResponse defines model for ApiResponse.
|
|
type ApiResponse struct {
|
|
Data *map[string]interface{} `json:"data,omitempty"`
|
|
RequestID *string `json:"requestID,omitempty"`
|
|
Status *int `json:"status,omitempty"`
|
|
Success *bool `json:"success,omitempty"`
|
|
}
|
|
|
|
// ErrorResponse defines model for ErrorResponse.
|
|
type ErrorResponse struct {
|
|
Message *string `json:"message,omitempty"`
|
|
RequestID *string `json:"requestID,omitempty"`
|
|
Status *int `json:"status,omitempty"`
|
|
}
|
|
|
|
// LoginRequest defines model for LoginRequest.
|
|
type LoginRequest struct {
|
|
Email openapi_types.Email `json:"email"`
|
|
Password string `json:"password"`
|
|
}
|
|
|
|
// RegisterRequest defines model for RegisterRequest.
|
|
type RegisterRequest struct {
|
|
Email openapi_types.Email `json:"email"`
|
|
FullName string `json:"fullName"`
|
|
Password string `json:"password"`
|
|
Role RegisterRequestRole `json:"role"`
|
|
}
|
|
|
|
// RegisterRequestRole defines model for RegisterRequest.Role.
|
|
type RegisterRequestRole string
|
|
|
|
// TokenRefreshRequest defines model for TokenRefreshRequest.
|
|
type TokenRefreshRequest struct {
|
|
// RefreshToken Refresh токен, полученный при логине
|
|
RefreshToken string `json:"refreshToken"`
|
|
}
|
|
|
|
// UserDeleteRequest defines model for UserDeleteRequest.
|
|
type UserDeleteRequest struct {
|
|
// Password Текущий пароль для подтверждения удаления
|
|
Password string `json:"password"`
|
|
}
|
|
|
|
// UserUpdate defines model for UserUpdate.
|
|
type UserUpdate struct {
|
|
AvatarUrl *string `json:"avatarUrl,omitempty"`
|
|
|
|
// CurrentPassword Текущий пароль (обязателен при смене пароля)
|
|
CurrentPassword *string `json:"currentPassword,omitempty"`
|
|
FullName *string `json:"fullName,omitempty"`
|
|
|
|
// Password Новый пароль (если меняется)
|
|
Password *string `json:"password,omitempty"`
|
|
}
|
|
|
|
// AuthLoginJSONRequestBody defines body for AuthLogin for application/json ContentType.
|
|
type AuthLoginJSONRequestBody = LoginRequest
|
|
|
|
// AuthRefreshJSONRequestBody defines body for AuthRefresh for application/json ContentType.
|
|
type AuthRefreshJSONRequestBody = TokenRefreshRequest
|
|
|
|
// AuthRegisterJSONRequestBody defines body for AuthRegister for application/json ContentType.
|
|
type AuthRegisterJSONRequestBody = RegisterRequest
|
|
|
|
// DeleteMeJSONRequestBody defines body for DeleteMe for application/json ContentType.
|
|
type DeleteMeJSONRequestBody = UserDeleteRequest
|
|
|
|
// UpdateMeJSONRequestBody defines body for UpdateMe for application/json ContentType.
|
|
type UpdateMeJSONRequestBody = UserUpdate
|
|
|
|
// ServerInterface represents all server handlers.
|
|
type ServerInterface interface {
|
|
// Авторизация пользователя
|
|
// (POST /auth/login)
|
|
AuthLogin(w http.ResponseWriter, r *http.Request)
|
|
// Выход из системы
|
|
// (POST /auth/logout)
|
|
AuthLogout(w http.ResponseWriter, r *http.Request)
|
|
// Обновление access-токена через refresh-токен
|
|
// (POST /auth/refresh)
|
|
AuthRefresh(w http.ResponseWriter, r *http.Request)
|
|
// Регистрация нового пользователя
|
|
// (POST /auth/register)
|
|
AuthRegister(w http.ResponseWriter, r *http.Request)
|
|
// Удалить аккаунт
|
|
// (DELETE /me)
|
|
DeleteMe(w http.ResponseWriter, r *http.Request)
|
|
// Получить текущего пользователя
|
|
// (GET /me)
|
|
GetMe(w http.ResponseWriter, r *http.Request)
|
|
// Обновить данные текущего пользователя
|
|
// (PATCH /me)
|
|
UpdateMe(w http.ResponseWriter, r *http.Request)
|
|
}
|
|
|
|
// Unimplemented server implementation that returns http.StatusNotImplemented for each endpoint.
|
|
|
|
type Unimplemented struct{}
|
|
|
|
// Авторизация пользователя
|
|
// (POST /auth/login)
|
|
func (_ Unimplemented) AuthLogin(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusNotImplemented)
|
|
}
|
|
|
|
// Выход из системы
|
|
// (POST /auth/logout)
|
|
func (_ Unimplemented) AuthLogout(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusNotImplemented)
|
|
}
|
|
|
|
// Обновление access-токена через refresh-токен
|
|
// (POST /auth/refresh)
|
|
func (_ Unimplemented) AuthRefresh(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusNotImplemented)
|
|
}
|
|
|
|
// Регистрация нового пользователя
|
|
// (POST /auth/register)
|
|
func (_ Unimplemented) AuthRegister(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusNotImplemented)
|
|
}
|
|
|
|
// Удалить аккаунт
|
|
// (DELETE /me)
|
|
func (_ Unimplemented) DeleteMe(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusNotImplemented)
|
|
}
|
|
|
|
// Получить текущего пользователя
|
|
// (GET /me)
|
|
func (_ Unimplemented) GetMe(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusNotImplemented)
|
|
}
|
|
|
|
// Обновить данные текущего пользователя
|
|
// (PATCH /me)
|
|
func (_ Unimplemented) UpdateMe(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusNotImplemented)
|
|
}
|
|
|
|
// ServerInterfaceWrapper converts contexts to parameters.
|
|
type ServerInterfaceWrapper struct {
|
|
Handler ServerInterface
|
|
HandlerMiddlewares []MiddlewareFunc
|
|
ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
|
|
}
|
|
|
|
type MiddlewareFunc func(http.Handler) http.Handler
|
|
|
|
// AuthLogin operation middleware
|
|
func (siw *ServerInterfaceWrapper) AuthLogin(w http.ResponseWriter, r *http.Request) {
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.AuthLogin(w, r)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// AuthLogout operation middleware
|
|
func (siw *ServerInterfaceWrapper) AuthLogout(w http.ResponseWriter, r *http.Request) {
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.AuthLogout(w, r)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// AuthRefresh operation middleware
|
|
func (siw *ServerInterfaceWrapper) AuthRefresh(w http.ResponseWriter, r *http.Request) {
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.AuthRefresh(w, r)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// AuthRegister operation middleware
|
|
func (siw *ServerInterfaceWrapper) AuthRegister(w http.ResponseWriter, r *http.Request) {
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.AuthRegister(w, r)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// DeleteMe operation middleware
|
|
func (siw *ServerInterfaceWrapper) DeleteMe(w http.ResponseWriter, r *http.Request) {
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.DeleteMe(w, r)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// GetMe operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetMe(w http.ResponseWriter, r *http.Request) {
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.GetMe(w, r)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// UpdateMe operation middleware
|
|
func (siw *ServerInterfaceWrapper) UpdateMe(w http.ResponseWriter, r *http.Request) {
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.UpdateMe(w, r)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
type UnescapedCookieParamError struct {
|
|
ParamName string
|
|
Err error
|
|
}
|
|
|
|
func (e *UnescapedCookieParamError) Error() string {
|
|
return fmt.Sprintf("error unescaping cookie parameter '%s'", e.ParamName)
|
|
}
|
|
|
|
func (e *UnescapedCookieParamError) Unwrap() error {
|
|
return e.Err
|
|
}
|
|
|
|
type UnmarshalingParamError struct {
|
|
ParamName string
|
|
Err error
|
|
}
|
|
|
|
func (e *UnmarshalingParamError) Error() string {
|
|
return fmt.Sprintf("Error unmarshaling parameter %s as JSON: %s", e.ParamName, e.Err.Error())
|
|
}
|
|
|
|
func (e *UnmarshalingParamError) Unwrap() error {
|
|
return e.Err
|
|
}
|
|
|
|
type RequiredParamError struct {
|
|
ParamName string
|
|
}
|
|
|
|
func (e *RequiredParamError) Error() string {
|
|
return fmt.Sprintf("Query argument %s is required, but not found", e.ParamName)
|
|
}
|
|
|
|
type RequiredHeaderError struct {
|
|
ParamName string
|
|
Err error
|
|
}
|
|
|
|
func (e *RequiredHeaderError) Error() string {
|
|
return fmt.Sprintf("Header parameter %s is required, but not found", e.ParamName)
|
|
}
|
|
|
|
func (e *RequiredHeaderError) Unwrap() error {
|
|
return e.Err
|
|
}
|
|
|
|
type InvalidParamFormatError struct {
|
|
ParamName string
|
|
Err error
|
|
}
|
|
|
|
func (e *InvalidParamFormatError) Error() string {
|
|
return fmt.Sprintf("Invalid format for parameter %s: %s", e.ParamName, e.Err.Error())
|
|
}
|
|
|
|
func (e *InvalidParamFormatError) Unwrap() error {
|
|
return e.Err
|
|
}
|
|
|
|
type TooManyValuesForParamError struct {
|
|
ParamName string
|
|
Count int
|
|
}
|
|
|
|
func (e *TooManyValuesForParamError) Error() string {
|
|
return fmt.Sprintf("Expected one value for %s, got %d", e.ParamName, e.Count)
|
|
}
|
|
|
|
// Handler creates http.Handler with routing matching OpenAPI spec.
|
|
func Handler(si ServerInterface) http.Handler {
|
|
return HandlerWithOptions(si, ChiServerOptions{})
|
|
}
|
|
|
|
type ChiServerOptions struct {
|
|
BaseURL string
|
|
BaseRouter chi.Router
|
|
Middlewares []MiddlewareFunc
|
|
ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
|
|
}
|
|
|
|
// HandlerFromMux creates http.Handler with routing matching OpenAPI spec based on the provided mux.
|
|
func HandlerFromMux(si ServerInterface, r chi.Router) http.Handler {
|
|
return HandlerWithOptions(si, ChiServerOptions{
|
|
BaseRouter: r,
|
|
})
|
|
}
|
|
|
|
func HandlerFromMuxWithBaseURL(si ServerInterface, r chi.Router, baseURL string) http.Handler {
|
|
return HandlerWithOptions(si, ChiServerOptions{
|
|
BaseURL: baseURL,
|
|
BaseRouter: r,
|
|
})
|
|
}
|
|
|
|
// HandlerWithOptions creates http.Handler with additional options
|
|
func HandlerWithOptions(si ServerInterface, options ChiServerOptions) http.Handler {
|
|
r := options.BaseRouter
|
|
|
|
if r == nil {
|
|
r = chi.NewRouter()
|
|
}
|
|
if options.ErrorHandlerFunc == nil {
|
|
options.ErrorHandlerFunc = func(w http.ResponseWriter, r *http.Request, err error) {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
}
|
|
}
|
|
wrapper := ServerInterfaceWrapper{
|
|
Handler: si,
|
|
HandlerMiddlewares: options.Middlewares,
|
|
ErrorHandlerFunc: options.ErrorHandlerFunc,
|
|
}
|
|
|
|
r.Group(func(r chi.Router) {
|
|
r.Post(options.BaseURL+"/auth/login", wrapper.AuthLogin)
|
|
})
|
|
r.Group(func(r chi.Router) {
|
|
r.Post(options.BaseURL+"/auth/logout", wrapper.AuthLogout)
|
|
})
|
|
r.Group(func(r chi.Router) {
|
|
r.Post(options.BaseURL+"/auth/refresh", wrapper.AuthRefresh)
|
|
})
|
|
r.Group(func(r chi.Router) {
|
|
r.Post(options.BaseURL+"/auth/register", wrapper.AuthRegister)
|
|
})
|
|
r.Group(func(r chi.Router) {
|
|
r.Delete(options.BaseURL+"/me", wrapper.DeleteMe)
|
|
})
|
|
r.Group(func(r chi.Router) {
|
|
r.Get(options.BaseURL+"/me", wrapper.GetMe)
|
|
})
|
|
r.Group(func(r chi.Router) {
|
|
r.Patch(options.BaseURL+"/me", wrapper.UpdateMe)
|
|
})
|
|
|
|
return r
|
|
}
|