1104 lines
33 KiB
Go
1104 lines
33 KiB
Go
//go:build go1.22
|
|
|
|
// Package v1 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 v1
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/oapi-codegen/runtime"
|
|
strictnethttp "github.com/oapi-codegen/runtime/strictmiddleware/nethttp"
|
|
)
|
|
|
|
const (
|
|
BearerAuthScopes = "BearerAuth.Scopes"
|
|
)
|
|
|
|
// Activity defines model for Activity.
|
|
type Activity struct {
|
|
ActivityType string `json:"activity_type"`
|
|
DocumentId string `json:"document_id"`
|
|
Id string `json:"id"`
|
|
Timestamp time.Time `json:"timestamp"`
|
|
UserId string `json:"user_id"`
|
|
}
|
|
|
|
// ActivityResponse defines model for ActivityResponse.
|
|
type ActivityResponse struct {
|
|
Activities []Activity `json:"activities"`
|
|
User UserData `json:"user"`
|
|
}
|
|
|
|
// Document defines model for Document.
|
|
type Document struct {
|
|
Author string `json:"author"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
Deleted bool `json:"deleted"`
|
|
Id string `json:"id"`
|
|
Title string `json:"title"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
Words *int64 `json:"words,omitempty"`
|
|
}
|
|
|
|
// DocumentResponse defines model for DocumentResponse.
|
|
type DocumentResponse struct {
|
|
Document Document `json:"document"`
|
|
Progress *Progress `json:"progress,omitempty"`
|
|
User UserData `json:"user"`
|
|
}
|
|
|
|
// DocumentsResponse defines model for DocumentsResponse.
|
|
type DocumentsResponse struct {
|
|
Documents []Document `json:"documents"`
|
|
Limit int64 `json:"limit"`
|
|
NextPage *int64 `json:"next_page,omitempty"`
|
|
Page int64 `json:"page"`
|
|
PreviousPage *int64 `json:"previous_page,omitempty"`
|
|
Search *string `json:"search,omitempty"`
|
|
Total int64 `json:"total"`
|
|
User UserData `json:"user"`
|
|
WordCounts []WordCount `json:"word_counts"`
|
|
}
|
|
|
|
// ErrorResponse defines model for ErrorResponse.
|
|
type ErrorResponse struct {
|
|
Code int `json:"code"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
// LoginRequest defines model for LoginRequest.
|
|
type LoginRequest struct {
|
|
Password string `json:"password"`
|
|
Username string `json:"username"`
|
|
}
|
|
|
|
// LoginResponse defines model for LoginResponse.
|
|
type LoginResponse struct {
|
|
IsAdmin bool `json:"is_admin"`
|
|
Username string `json:"username"`
|
|
}
|
|
|
|
// Progress defines model for Progress.
|
|
type Progress struct {
|
|
CreatedAt time.Time `json:"created_at"`
|
|
DeviceId string `json:"device_id"`
|
|
DocumentId string `json:"document_id"`
|
|
Percentage float64 `json:"percentage"`
|
|
Progress string `json:"progress"`
|
|
UserId string `json:"user_id"`
|
|
}
|
|
|
|
// ProgressResponse defines model for ProgressResponse.
|
|
type ProgressResponse = Progress
|
|
|
|
// Setting defines model for Setting.
|
|
type Setting struct {
|
|
Id string `json:"id"`
|
|
Key string `json:"key"`
|
|
UserId string `json:"user_id"`
|
|
Value string `json:"value"`
|
|
}
|
|
|
|
// SettingsResponse defines model for SettingsResponse.
|
|
type SettingsResponse struct {
|
|
Settings []Setting `json:"settings"`
|
|
Timezone *string `json:"timezone,omitempty"`
|
|
User UserData `json:"user"`
|
|
}
|
|
|
|
// UserData defines model for UserData.
|
|
type UserData struct {
|
|
IsAdmin bool `json:"is_admin"`
|
|
Username string `json:"username"`
|
|
}
|
|
|
|
// WordCount defines model for WordCount.
|
|
type WordCount struct {
|
|
Count int64 `json:"count"`
|
|
DocumentId string `json:"document_id"`
|
|
}
|
|
|
|
// GetActivityParams defines parameters for GetActivity.
|
|
type GetActivityParams struct {
|
|
DocFilter *bool `form:"doc_filter,omitempty" json:"doc_filter,omitempty"`
|
|
DocumentId *string `form:"document_id,omitempty" json:"document_id,omitempty"`
|
|
Offset *int64 `form:"offset,omitempty" json:"offset,omitempty"`
|
|
Limit *int64 `form:"limit,omitempty" json:"limit,omitempty"`
|
|
}
|
|
|
|
// GetDocumentsParams defines parameters for GetDocuments.
|
|
type GetDocumentsParams struct {
|
|
Page *int64 `form:"page,omitempty" json:"page,omitempty"`
|
|
Limit *int64 `form:"limit,omitempty" json:"limit,omitempty"`
|
|
Search *string `form:"search,omitempty" json:"search,omitempty"`
|
|
}
|
|
|
|
// LoginJSONRequestBody defines body for Login for application/json ContentType.
|
|
type LoginJSONRequestBody = LoginRequest
|
|
|
|
// ServerInterface represents all server handlers.
|
|
type ServerInterface interface {
|
|
// Get activity data
|
|
// (GET /activity)
|
|
GetActivity(w http.ResponseWriter, r *http.Request, params GetActivityParams)
|
|
// User login
|
|
// (POST /auth/login)
|
|
Login(w http.ResponseWriter, r *http.Request)
|
|
// User logout
|
|
// (POST /auth/logout)
|
|
Logout(w http.ResponseWriter, r *http.Request)
|
|
// Get current user info
|
|
// (GET /auth/me)
|
|
GetMe(w http.ResponseWriter, r *http.Request)
|
|
// List documents
|
|
// (GET /documents)
|
|
GetDocuments(w http.ResponseWriter, r *http.Request, params GetDocumentsParams)
|
|
// Get a single document
|
|
// (GET /documents/{id})
|
|
GetDocument(w http.ResponseWriter, r *http.Request, id string)
|
|
// Get document progress
|
|
// (GET /progress/{id})
|
|
GetProgress(w http.ResponseWriter, r *http.Request, id string)
|
|
// Get user settings
|
|
// (GET /settings)
|
|
GetSettings(w http.ResponseWriter, r *http.Request)
|
|
}
|
|
|
|
// 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
|
|
|
|
// GetActivity operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetActivity(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var err error
|
|
|
|
ctx := r.Context()
|
|
|
|
ctx = context.WithValue(ctx, BearerAuthScopes, []string{})
|
|
|
|
r = r.WithContext(ctx)
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params GetActivityParams
|
|
|
|
// ------------- Optional query parameter "doc_filter" -------------
|
|
|
|
err = runtime.BindQueryParameterWithOptions("form", true, false, "doc_filter", r.URL.Query(), ¶ms.DocFilter, runtime.BindQueryParameterOptions{Type: "boolean", Format: ""})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "doc_filter", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "document_id" -------------
|
|
|
|
err = runtime.BindQueryParameterWithOptions("form", true, false, "document_id", r.URL.Query(), ¶ms.DocumentId, runtime.BindQueryParameterOptions{Type: "string", Format: ""})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "document_id", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "offset" -------------
|
|
|
|
err = runtime.BindQueryParameterWithOptions("form", true, false, "offset", r.URL.Query(), ¶ms.Offset, runtime.BindQueryParameterOptions{Type: "integer", Format: "int64"})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "offset", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "limit" -------------
|
|
|
|
err = runtime.BindQueryParameterWithOptions("form", true, false, "limit", r.URL.Query(), ¶ms.Limit, runtime.BindQueryParameterOptions{Type: "integer", Format: "int64"})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "limit", Err: err})
|
|
return
|
|
}
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.GetActivity(w, r, params)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// Login operation middleware
|
|
func (siw *ServerInterfaceWrapper) Login(w http.ResponseWriter, r *http.Request) {
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.Login(w, r)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// Logout operation middleware
|
|
func (siw *ServerInterfaceWrapper) Logout(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ctx := r.Context()
|
|
|
|
ctx = context.WithValue(ctx, BearerAuthScopes, []string{})
|
|
|
|
r = r.WithContext(ctx)
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.Logout(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) {
|
|
|
|
ctx := r.Context()
|
|
|
|
ctx = context.WithValue(ctx, BearerAuthScopes, []string{})
|
|
|
|
r = r.WithContext(ctx)
|
|
|
|
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)
|
|
}
|
|
|
|
// GetDocuments operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetDocuments(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var err error
|
|
|
|
ctx := r.Context()
|
|
|
|
ctx = context.WithValue(ctx, BearerAuthScopes, []string{})
|
|
|
|
r = r.WithContext(ctx)
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params GetDocumentsParams
|
|
|
|
// ------------- Optional query parameter "page" -------------
|
|
|
|
err = runtime.BindQueryParameterWithOptions("form", true, false, "page", r.URL.Query(), ¶ms.Page, runtime.BindQueryParameterOptions{Type: "integer", Format: "int64"})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "page", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "limit" -------------
|
|
|
|
err = runtime.BindQueryParameterWithOptions("form", true, false, "limit", r.URL.Query(), ¶ms.Limit, runtime.BindQueryParameterOptions{Type: "integer", Format: "int64"})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "limit", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "search" -------------
|
|
|
|
err = runtime.BindQueryParameterWithOptions("form", true, false, "search", r.URL.Query(), ¶ms.Search, runtime.BindQueryParameterOptions{Type: "string", Format: ""})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "search", Err: err})
|
|
return
|
|
}
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.GetDocuments(w, r, params)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// GetDocument operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetDocument(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var err error
|
|
|
|
// ------------- Path parameter "id" -------------
|
|
var id string
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "id", r.PathValue("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: ""})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "id", Err: err})
|
|
return
|
|
}
|
|
|
|
ctx := r.Context()
|
|
|
|
ctx = context.WithValue(ctx, BearerAuthScopes, []string{})
|
|
|
|
r = r.WithContext(ctx)
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.GetDocument(w, r, id)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// GetProgress operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetProgress(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var err error
|
|
|
|
// ------------- Path parameter "id" -------------
|
|
var id string
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "id", r.PathValue("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: ""})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "id", Err: err})
|
|
return
|
|
}
|
|
|
|
ctx := r.Context()
|
|
|
|
ctx = context.WithValue(ctx, BearerAuthScopes, []string{})
|
|
|
|
r = r.WithContext(ctx)
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.GetProgress(w, r, id)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// GetSettings operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetSettings(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ctx := r.Context()
|
|
|
|
ctx = context.WithValue(ctx, BearerAuthScopes, []string{})
|
|
|
|
r = r.WithContext(ctx)
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.GetSettings(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, StdHTTPServerOptions{})
|
|
}
|
|
|
|
// ServeMux is an abstraction of http.ServeMux.
|
|
type ServeMux interface {
|
|
HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
|
|
ServeHTTP(w http.ResponseWriter, r *http.Request)
|
|
}
|
|
|
|
type StdHTTPServerOptions struct {
|
|
BaseURL string
|
|
BaseRouter ServeMux
|
|
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, m ServeMux) http.Handler {
|
|
return HandlerWithOptions(si, StdHTTPServerOptions{
|
|
BaseRouter: m,
|
|
})
|
|
}
|
|
|
|
func HandlerFromMuxWithBaseURL(si ServerInterface, m ServeMux, baseURL string) http.Handler {
|
|
return HandlerWithOptions(si, StdHTTPServerOptions{
|
|
BaseURL: baseURL,
|
|
BaseRouter: m,
|
|
})
|
|
}
|
|
|
|
// HandlerWithOptions creates http.Handler with additional options
|
|
func HandlerWithOptions(si ServerInterface, options StdHTTPServerOptions) http.Handler {
|
|
m := options.BaseRouter
|
|
|
|
if m == nil {
|
|
m = http.NewServeMux()
|
|
}
|
|
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,
|
|
}
|
|
|
|
m.HandleFunc("GET "+options.BaseURL+"/activity", wrapper.GetActivity)
|
|
m.HandleFunc("POST "+options.BaseURL+"/auth/login", wrapper.Login)
|
|
m.HandleFunc("POST "+options.BaseURL+"/auth/logout", wrapper.Logout)
|
|
m.HandleFunc("GET "+options.BaseURL+"/auth/me", wrapper.GetMe)
|
|
m.HandleFunc("GET "+options.BaseURL+"/documents", wrapper.GetDocuments)
|
|
m.HandleFunc("GET "+options.BaseURL+"/documents/{id}", wrapper.GetDocument)
|
|
m.HandleFunc("GET "+options.BaseURL+"/progress/{id}", wrapper.GetProgress)
|
|
m.HandleFunc("GET "+options.BaseURL+"/settings", wrapper.GetSettings)
|
|
|
|
return m
|
|
}
|
|
|
|
type GetActivityRequestObject struct {
|
|
Params GetActivityParams
|
|
}
|
|
|
|
type GetActivityResponseObject interface {
|
|
VisitGetActivityResponse(w http.ResponseWriter) error
|
|
}
|
|
|
|
type GetActivity200JSONResponse ActivityResponse
|
|
|
|
func (response GetActivity200JSONResponse) VisitGetActivityResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(200)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetActivity401JSONResponse ErrorResponse
|
|
|
|
func (response GetActivity401JSONResponse) VisitGetActivityResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(401)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetActivity500JSONResponse ErrorResponse
|
|
|
|
func (response GetActivity500JSONResponse) VisitGetActivityResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(500)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type LoginRequestObject struct {
|
|
Body *LoginJSONRequestBody
|
|
}
|
|
|
|
type LoginResponseObject interface {
|
|
VisitLoginResponse(w http.ResponseWriter) error
|
|
}
|
|
|
|
type Login200JSONResponse LoginResponse
|
|
|
|
func (response Login200JSONResponse) VisitLoginResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(200)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type Login400JSONResponse ErrorResponse
|
|
|
|
func (response Login400JSONResponse) VisitLoginResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(400)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type Login401JSONResponse ErrorResponse
|
|
|
|
func (response Login401JSONResponse) VisitLoginResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(401)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type Login500JSONResponse ErrorResponse
|
|
|
|
func (response Login500JSONResponse) VisitLoginResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(500)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type LogoutRequestObject struct {
|
|
}
|
|
|
|
type LogoutResponseObject interface {
|
|
VisitLogoutResponse(w http.ResponseWriter) error
|
|
}
|
|
|
|
type Logout200Response struct {
|
|
}
|
|
|
|
func (response Logout200Response) VisitLogoutResponse(w http.ResponseWriter) error {
|
|
w.WriteHeader(200)
|
|
return nil
|
|
}
|
|
|
|
type Logout401JSONResponse ErrorResponse
|
|
|
|
func (response Logout401JSONResponse) VisitLogoutResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(401)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetMeRequestObject struct {
|
|
}
|
|
|
|
type GetMeResponseObject interface {
|
|
VisitGetMeResponse(w http.ResponseWriter) error
|
|
}
|
|
|
|
type GetMe200JSONResponse LoginResponse
|
|
|
|
func (response GetMe200JSONResponse) VisitGetMeResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(200)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetMe401JSONResponse ErrorResponse
|
|
|
|
func (response GetMe401JSONResponse) VisitGetMeResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(401)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetDocumentsRequestObject struct {
|
|
Params GetDocumentsParams
|
|
}
|
|
|
|
type GetDocumentsResponseObject interface {
|
|
VisitGetDocumentsResponse(w http.ResponseWriter) error
|
|
}
|
|
|
|
type GetDocuments200JSONResponse DocumentsResponse
|
|
|
|
func (response GetDocuments200JSONResponse) VisitGetDocumentsResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(200)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetDocuments401JSONResponse ErrorResponse
|
|
|
|
func (response GetDocuments401JSONResponse) VisitGetDocumentsResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(401)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetDocuments500JSONResponse ErrorResponse
|
|
|
|
func (response GetDocuments500JSONResponse) VisitGetDocumentsResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(500)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetDocumentRequestObject struct {
|
|
Id string `json:"id"`
|
|
}
|
|
|
|
type GetDocumentResponseObject interface {
|
|
VisitGetDocumentResponse(w http.ResponseWriter) error
|
|
}
|
|
|
|
type GetDocument200JSONResponse DocumentResponse
|
|
|
|
func (response GetDocument200JSONResponse) VisitGetDocumentResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(200)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetDocument401JSONResponse ErrorResponse
|
|
|
|
func (response GetDocument401JSONResponse) VisitGetDocumentResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(401)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetDocument404JSONResponse ErrorResponse
|
|
|
|
func (response GetDocument404JSONResponse) VisitGetDocumentResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(404)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetDocument500JSONResponse ErrorResponse
|
|
|
|
func (response GetDocument500JSONResponse) VisitGetDocumentResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(500)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetProgressRequestObject struct {
|
|
Id string `json:"id"`
|
|
}
|
|
|
|
type GetProgressResponseObject interface {
|
|
VisitGetProgressResponse(w http.ResponseWriter) error
|
|
}
|
|
|
|
type GetProgress200JSONResponse ProgressResponse
|
|
|
|
func (response GetProgress200JSONResponse) VisitGetProgressResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(200)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetProgress401JSONResponse ErrorResponse
|
|
|
|
func (response GetProgress401JSONResponse) VisitGetProgressResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(401)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetProgress404JSONResponse ErrorResponse
|
|
|
|
func (response GetProgress404JSONResponse) VisitGetProgressResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(404)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetProgress500JSONResponse ErrorResponse
|
|
|
|
func (response GetProgress500JSONResponse) VisitGetProgressResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(500)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetSettingsRequestObject struct {
|
|
}
|
|
|
|
type GetSettingsResponseObject interface {
|
|
VisitGetSettingsResponse(w http.ResponseWriter) error
|
|
}
|
|
|
|
type GetSettings200JSONResponse SettingsResponse
|
|
|
|
func (response GetSettings200JSONResponse) VisitGetSettingsResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(200)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetSettings401JSONResponse ErrorResponse
|
|
|
|
func (response GetSettings401JSONResponse) VisitGetSettingsResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(401)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetSettings500JSONResponse ErrorResponse
|
|
|
|
func (response GetSettings500JSONResponse) VisitGetSettingsResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(500)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
// StrictServerInterface represents all server handlers.
|
|
type StrictServerInterface interface {
|
|
// Get activity data
|
|
// (GET /activity)
|
|
GetActivity(ctx context.Context, request GetActivityRequestObject) (GetActivityResponseObject, error)
|
|
// User login
|
|
// (POST /auth/login)
|
|
Login(ctx context.Context, request LoginRequestObject) (LoginResponseObject, error)
|
|
// User logout
|
|
// (POST /auth/logout)
|
|
Logout(ctx context.Context, request LogoutRequestObject) (LogoutResponseObject, error)
|
|
// Get current user info
|
|
// (GET /auth/me)
|
|
GetMe(ctx context.Context, request GetMeRequestObject) (GetMeResponseObject, error)
|
|
// List documents
|
|
// (GET /documents)
|
|
GetDocuments(ctx context.Context, request GetDocumentsRequestObject) (GetDocumentsResponseObject, error)
|
|
// Get a single document
|
|
// (GET /documents/{id})
|
|
GetDocument(ctx context.Context, request GetDocumentRequestObject) (GetDocumentResponseObject, error)
|
|
// Get document progress
|
|
// (GET /progress/{id})
|
|
GetProgress(ctx context.Context, request GetProgressRequestObject) (GetProgressResponseObject, error)
|
|
// Get user settings
|
|
// (GET /settings)
|
|
GetSettings(ctx context.Context, request GetSettingsRequestObject) (GetSettingsResponseObject, error)
|
|
}
|
|
|
|
type StrictHandlerFunc = strictnethttp.StrictHTTPHandlerFunc
|
|
type StrictMiddlewareFunc = strictnethttp.StrictHTTPMiddlewareFunc
|
|
|
|
type StrictHTTPServerOptions struct {
|
|
RequestErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
|
|
ResponseErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
|
|
}
|
|
|
|
func NewStrictHandler(ssi StrictServerInterface, middlewares []StrictMiddlewareFunc) ServerInterface {
|
|
return &strictHandler{ssi: ssi, middlewares: middlewares, options: StrictHTTPServerOptions{
|
|
RequestErrorHandlerFunc: func(w http.ResponseWriter, r *http.Request, err error) {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
},
|
|
ResponseErrorHandlerFunc: func(w http.ResponseWriter, r *http.Request, err error) {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
},
|
|
}}
|
|
}
|
|
|
|
func NewStrictHandlerWithOptions(ssi StrictServerInterface, middlewares []StrictMiddlewareFunc, options StrictHTTPServerOptions) ServerInterface {
|
|
return &strictHandler{ssi: ssi, middlewares: middlewares, options: options}
|
|
}
|
|
|
|
type strictHandler struct {
|
|
ssi StrictServerInterface
|
|
middlewares []StrictMiddlewareFunc
|
|
options StrictHTTPServerOptions
|
|
}
|
|
|
|
// GetActivity operation middleware
|
|
func (sh *strictHandler) GetActivity(w http.ResponseWriter, r *http.Request, params GetActivityParams) {
|
|
var request GetActivityRequestObject
|
|
|
|
request.Params = params
|
|
|
|
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
|
|
return sh.ssi.GetActivity(ctx, request.(GetActivityRequestObject))
|
|
}
|
|
for _, middleware := range sh.middlewares {
|
|
handler = middleware(handler, "GetActivity")
|
|
}
|
|
|
|
response, err := handler(r.Context(), w, r, request)
|
|
|
|
if err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
} else if validResponse, ok := response.(GetActivityResponseObject); ok {
|
|
if err := validResponse.VisitGetActivityResponse(w); err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
}
|
|
} else if response != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response))
|
|
}
|
|
}
|
|
|
|
// Login operation middleware
|
|
func (sh *strictHandler) Login(w http.ResponseWriter, r *http.Request) {
|
|
var request LoginRequestObject
|
|
|
|
var body LoginJSONRequestBody
|
|
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
|
sh.options.RequestErrorHandlerFunc(w, r, fmt.Errorf("can't decode JSON body: %w", err))
|
|
return
|
|
}
|
|
request.Body = &body
|
|
|
|
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
|
|
return sh.ssi.Login(ctx, request.(LoginRequestObject))
|
|
}
|
|
for _, middleware := range sh.middlewares {
|
|
handler = middleware(handler, "Login")
|
|
}
|
|
|
|
response, err := handler(r.Context(), w, r, request)
|
|
|
|
if err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
} else if validResponse, ok := response.(LoginResponseObject); ok {
|
|
if err := validResponse.VisitLoginResponse(w); err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
}
|
|
} else if response != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response))
|
|
}
|
|
}
|
|
|
|
// Logout operation middleware
|
|
func (sh *strictHandler) Logout(w http.ResponseWriter, r *http.Request) {
|
|
var request LogoutRequestObject
|
|
|
|
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
|
|
return sh.ssi.Logout(ctx, request.(LogoutRequestObject))
|
|
}
|
|
for _, middleware := range sh.middlewares {
|
|
handler = middleware(handler, "Logout")
|
|
}
|
|
|
|
response, err := handler(r.Context(), w, r, request)
|
|
|
|
if err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
} else if validResponse, ok := response.(LogoutResponseObject); ok {
|
|
if err := validResponse.VisitLogoutResponse(w); err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
}
|
|
} else if response != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response))
|
|
}
|
|
}
|
|
|
|
// GetMe operation middleware
|
|
func (sh *strictHandler) GetMe(w http.ResponseWriter, r *http.Request) {
|
|
var request GetMeRequestObject
|
|
|
|
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
|
|
return sh.ssi.GetMe(ctx, request.(GetMeRequestObject))
|
|
}
|
|
for _, middleware := range sh.middlewares {
|
|
handler = middleware(handler, "GetMe")
|
|
}
|
|
|
|
response, err := handler(r.Context(), w, r, request)
|
|
|
|
if err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
} else if validResponse, ok := response.(GetMeResponseObject); ok {
|
|
if err := validResponse.VisitGetMeResponse(w); err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
}
|
|
} else if response != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response))
|
|
}
|
|
}
|
|
|
|
// GetDocuments operation middleware
|
|
func (sh *strictHandler) GetDocuments(w http.ResponseWriter, r *http.Request, params GetDocumentsParams) {
|
|
var request GetDocumentsRequestObject
|
|
|
|
request.Params = params
|
|
|
|
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
|
|
return sh.ssi.GetDocuments(ctx, request.(GetDocumentsRequestObject))
|
|
}
|
|
for _, middleware := range sh.middlewares {
|
|
handler = middleware(handler, "GetDocuments")
|
|
}
|
|
|
|
response, err := handler(r.Context(), w, r, request)
|
|
|
|
if err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
} else if validResponse, ok := response.(GetDocumentsResponseObject); ok {
|
|
if err := validResponse.VisitGetDocumentsResponse(w); err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
}
|
|
} else if response != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response))
|
|
}
|
|
}
|
|
|
|
// GetDocument operation middleware
|
|
func (sh *strictHandler) GetDocument(w http.ResponseWriter, r *http.Request, id string) {
|
|
var request GetDocumentRequestObject
|
|
|
|
request.Id = id
|
|
|
|
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
|
|
return sh.ssi.GetDocument(ctx, request.(GetDocumentRequestObject))
|
|
}
|
|
for _, middleware := range sh.middlewares {
|
|
handler = middleware(handler, "GetDocument")
|
|
}
|
|
|
|
response, err := handler(r.Context(), w, r, request)
|
|
|
|
if err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
} else if validResponse, ok := response.(GetDocumentResponseObject); ok {
|
|
if err := validResponse.VisitGetDocumentResponse(w); err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
}
|
|
} else if response != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response))
|
|
}
|
|
}
|
|
|
|
// GetProgress operation middleware
|
|
func (sh *strictHandler) GetProgress(w http.ResponseWriter, r *http.Request, id string) {
|
|
var request GetProgressRequestObject
|
|
|
|
request.Id = id
|
|
|
|
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
|
|
return sh.ssi.GetProgress(ctx, request.(GetProgressRequestObject))
|
|
}
|
|
for _, middleware := range sh.middlewares {
|
|
handler = middleware(handler, "GetProgress")
|
|
}
|
|
|
|
response, err := handler(r.Context(), w, r, request)
|
|
|
|
if err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
} else if validResponse, ok := response.(GetProgressResponseObject); ok {
|
|
if err := validResponse.VisitGetProgressResponse(w); err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
}
|
|
} else if response != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response))
|
|
}
|
|
}
|
|
|
|
// GetSettings operation middleware
|
|
func (sh *strictHandler) GetSettings(w http.ResponseWriter, r *http.Request) {
|
|
var request GetSettingsRequestObject
|
|
|
|
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
|
|
return sh.ssi.GetSettings(ctx, request.(GetSettingsRequestObject))
|
|
}
|
|
for _, middleware := range sh.middlewares {
|
|
handler = middleware(handler, "GetSettings")
|
|
}
|
|
|
|
response, err := handler(r.Context(), w, r, request)
|
|
|
|
if err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
} else if validResponse, ok := response.(GetSettingsResponseObject); ok {
|
|
if err := validResponse.VisitGetSettingsResponse(w); err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
}
|
|
} else if response != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response))
|
|
}
|
|
}
|