451 lines
12 KiB
Go
451 lines
12 KiB
Go
// Package api provides primitives to interact with the openapi HTTP API.
|
|
//
|
|
// Code generated by github.com/deepmap/oapi-codegen version v1.8.2 DO NOT EDIT.
|
|
package api
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/deepmap/oapi-codegen/pkg/runtime"
|
|
"github.com/go-chi/chi/v5"
|
|
)
|
|
|
|
// ServerInterface represents all server handlers.
|
|
type ServerInterface interface {
|
|
|
|
// (GET /auth/authorize)
|
|
AuthorizeCallback(w http.ResponseWriter, r *http.Request, params AuthorizeCallbackParams)
|
|
|
|
// (GET /auth/code)
|
|
GenOauth(w http.ResponseWriter, r *http.Request, params GenOauthParams)
|
|
|
|
// (DELETE /auth/token)
|
|
DeleteToken(w http.ResponseWriter, r *http.Request, params DeleteTokenParams)
|
|
|
|
// (GET /users/all)
|
|
GetAllUsers(w http.ResponseWriter, r *http.Request, params GetAllUsersParams)
|
|
|
|
// (GET /users/email)
|
|
GetUserByEmail(w http.ResponseWriter, r *http.Request, params GetUserByEmailParams)
|
|
|
|
// (PATCH /users/email)
|
|
ModifyOtherUser(w http.ResponseWriter, r *http.Request, params ModifyOtherUserParams)
|
|
|
|
// (GET /users/me)
|
|
GetMe(w http.ResponseWriter, r *http.Request, params GetMeParams)
|
|
|
|
// (PATCH /users/me)
|
|
ModifyUser(w http.ResponseWriter, r *http.Request, params ModifyUserParams)
|
|
}
|
|
|
|
// ServerInterfaceWrapper converts contexts to parameters.
|
|
type ServerInterfaceWrapper struct {
|
|
Handler ServerInterface
|
|
HandlerMiddlewares []MiddlewareFunc
|
|
}
|
|
|
|
type MiddlewareFunc func(http.HandlerFunc) http.HandlerFunc
|
|
|
|
// AuthorizeCallback operation middleware
|
|
func (siw *ServerInterfaceWrapper) AuthorizeCallback(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
var err error
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params AuthorizeCallbackParams
|
|
|
|
// ------------- Required query parameter "state" -------------
|
|
if paramValue := r.URL.Query().Get("state"); paramValue != "" {
|
|
|
|
} else {
|
|
http.Error(w, "Query argument state is required, but not found", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
err = runtime.BindQueryParameter("form", true, true, "state", r.URL.Query(), ¶ms.State)
|
|
if err != nil {
|
|
http.Error(w, fmt.Sprintf("Invalid format for parameter state: %s", err), http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
// ------------- Required query parameter "code" -------------
|
|
if paramValue := r.URL.Query().Get("code"); paramValue != "" {
|
|
|
|
} else {
|
|
http.Error(w, "Query argument code is required, but not found", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
err = runtime.BindQueryParameter("form", true, true, "code", r.URL.Query(), ¶ms.Code)
|
|
if err != nil {
|
|
http.Error(w, fmt.Sprintf("Invalid format for parameter code: %s", err), http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
var handler = func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.AuthorizeCallback(w, r, params)
|
|
}
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler(w, r.WithContext(ctx))
|
|
}
|
|
|
|
// GenOauth operation middleware
|
|
func (siw *ServerInterfaceWrapper) GenOauth(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
var err error
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params GenOauthParams
|
|
|
|
// ------------- Required query parameter "callback" -------------
|
|
if paramValue := r.URL.Query().Get("callback"); paramValue != "" {
|
|
|
|
} else {
|
|
http.Error(w, "Query argument callback is required, but not found", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
err = runtime.BindQueryParameter("form", true, true, "callback", r.URL.Query(), ¶ms.Callback)
|
|
if err != nil {
|
|
http.Error(w, fmt.Sprintf("Invalid format for parameter callback: %s", err), http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
var handler = func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.GenOauth(w, r, params)
|
|
}
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler(w, r.WithContext(ctx))
|
|
}
|
|
|
|
// DeleteToken operation middleware
|
|
func (siw *ServerInterfaceWrapper) DeleteToken(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
var err error
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params DeleteTokenParams
|
|
|
|
// ------------- Optional query parameter "all" -------------
|
|
if paramValue := r.URL.Query().Get("all"); paramValue != "" {
|
|
|
|
}
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "all", r.URL.Query(), ¶ms.All)
|
|
if err != nil {
|
|
http.Error(w, fmt.Sprintf("Invalid format for parameter all: %s", err), http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
var cookie *http.Cookie
|
|
|
|
if cookie, err = r.Cookie("token"); err == nil {
|
|
var value string
|
|
err = runtime.BindStyledParameter("simple", true, "token", cookie.Value, &value)
|
|
if err != nil {
|
|
http.Error(w, "Invalid format for parameter token: %s", http.StatusBadRequest)
|
|
return
|
|
}
|
|
params.Token = value
|
|
|
|
} else {
|
|
http.Error(w, "Query argument token is required, but not found", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
var handler = func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.DeleteToken(w, r, params)
|
|
}
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler(w, r.WithContext(ctx))
|
|
}
|
|
|
|
// GetAllUsers operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetAllUsers(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
var err error
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params GetAllUsersParams
|
|
|
|
var cookie *http.Cookie
|
|
|
|
if cookie, err = r.Cookie("token"); err == nil {
|
|
var value string
|
|
err = runtime.BindStyledParameter("simple", true, "token", cookie.Value, &value)
|
|
if err != nil {
|
|
http.Error(w, "Invalid format for parameter token: %s", http.StatusBadRequest)
|
|
return
|
|
}
|
|
params.Token = value
|
|
|
|
} else {
|
|
http.Error(w, "Query argument token is required, but not found", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
var handler = func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.GetAllUsers(w, r, params)
|
|
}
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler(w, r.WithContext(ctx))
|
|
}
|
|
|
|
// GetUserByEmail operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetUserByEmail(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
var err error
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params GetUserByEmailParams
|
|
|
|
// ------------- Required query parameter "email" -------------
|
|
if paramValue := r.URL.Query().Get("email"); paramValue != "" {
|
|
|
|
} else {
|
|
http.Error(w, "Query argument email is required, but not found", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
err = runtime.BindQueryParameter("form", true, true, "email", r.URL.Query(), ¶ms.Email)
|
|
if err != nil {
|
|
http.Error(w, fmt.Sprintf("Invalid format for parameter email: %s", err), http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
var cookie *http.Cookie
|
|
|
|
if cookie, err = r.Cookie("token"); err == nil {
|
|
var value string
|
|
err = runtime.BindStyledParameter("simple", true, "token", cookie.Value, &value)
|
|
if err != nil {
|
|
http.Error(w, "Invalid format for parameter token: %s", http.StatusBadRequest)
|
|
return
|
|
}
|
|
params.Token = value
|
|
|
|
} else {
|
|
http.Error(w, "Query argument token is required, but not found", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
var handler = func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.GetUserByEmail(w, r, params)
|
|
}
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler(w, r.WithContext(ctx))
|
|
}
|
|
|
|
// ModifyOtherUser operation middleware
|
|
func (siw *ServerInterfaceWrapper) ModifyOtherUser(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
var err error
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params ModifyOtherUserParams
|
|
|
|
// ------------- Required query parameter "email" -------------
|
|
if paramValue := r.URL.Query().Get("email"); paramValue != "" {
|
|
|
|
} else {
|
|
http.Error(w, "Query argument email is required, but not found", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
err = runtime.BindQueryParameter("form", true, true, "email", r.URL.Query(), ¶ms.Email)
|
|
if err != nil {
|
|
http.Error(w, fmt.Sprintf("Invalid format for parameter email: %s", err), http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
var cookie *http.Cookie
|
|
|
|
if cookie, err = r.Cookie("token"); err == nil {
|
|
var value string
|
|
err = runtime.BindStyledParameter("simple", true, "token", cookie.Value, &value)
|
|
if err != nil {
|
|
http.Error(w, "Invalid format for parameter token: %s", http.StatusBadRequest)
|
|
return
|
|
}
|
|
params.Token = value
|
|
|
|
} else {
|
|
http.Error(w, "Query argument token is required, but not found", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
var handler = func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.ModifyOtherUser(w, r, params)
|
|
}
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler(w, r.WithContext(ctx))
|
|
}
|
|
|
|
// GetMe operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetMe(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
var err error
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params GetMeParams
|
|
|
|
var cookie *http.Cookie
|
|
|
|
if cookie, err = r.Cookie("token"); err == nil {
|
|
var value string
|
|
err = runtime.BindStyledParameter("simple", true, "token", cookie.Value, &value)
|
|
if err != nil {
|
|
http.Error(w, "Invalid format for parameter token: %s", http.StatusBadRequest)
|
|
return
|
|
}
|
|
params.Token = value
|
|
|
|
} else {
|
|
http.Error(w, "Query argument token is required, but not found", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
var handler = func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.GetMe(w, r, params)
|
|
}
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler(w, r.WithContext(ctx))
|
|
}
|
|
|
|
// ModifyUser operation middleware
|
|
func (siw *ServerInterfaceWrapper) ModifyUser(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
var err error
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params ModifyUserParams
|
|
|
|
var cookie *http.Cookie
|
|
|
|
if cookie, err = r.Cookie("token"); err == nil {
|
|
var value string
|
|
err = runtime.BindStyledParameter("simple", true, "token", cookie.Value, &value)
|
|
if err != nil {
|
|
http.Error(w, "Invalid format for parameter token: %s", http.StatusBadRequest)
|
|
return
|
|
}
|
|
params.Token = value
|
|
|
|
} else {
|
|
http.Error(w, "Query argument token is required, but not found", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
var handler = func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.ModifyUser(w, r, params)
|
|
}
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler(w, r.WithContext(ctx))
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// 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()
|
|
}
|
|
wrapper := ServerInterfaceWrapper{
|
|
Handler: si,
|
|
HandlerMiddlewares: options.Middlewares,
|
|
}
|
|
|
|
r.Group(func(r chi.Router) {
|
|
r.Get(options.BaseURL+"/auth/authorize", wrapper.AuthorizeCallback)
|
|
})
|
|
r.Group(func(r chi.Router) {
|
|
r.Get(options.BaseURL+"/auth/code", wrapper.GenOauth)
|
|
})
|
|
r.Group(func(r chi.Router) {
|
|
r.Delete(options.BaseURL+"/auth/token", wrapper.DeleteToken)
|
|
})
|
|
r.Group(func(r chi.Router) {
|
|
r.Get(options.BaseURL+"/users/all", wrapper.GetAllUsers)
|
|
})
|
|
r.Group(func(r chi.Router) {
|
|
r.Get(options.BaseURL+"/users/email", wrapper.GetUserByEmail)
|
|
})
|
|
r.Group(func(r chi.Router) {
|
|
r.Patch(options.BaseURL+"/users/email", wrapper.ModifyOtherUser)
|
|
})
|
|
r.Group(func(r chi.Router) {
|
|
r.Get(options.BaseURL+"/users/me", wrapper.GetMe)
|
|
})
|
|
r.Group(func(r chi.Router) {
|
|
r.Patch(options.BaseURL+"/users/me", wrapper.ModifyUser)
|
|
})
|
|
|
|
return r
|
|
}
|