api

package
v0.0.0-...-43686f6 Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package api 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.

Index

Constants

View Source
const (
	BearerAuthScopes = "BearerAuth.Scopes"
)

Variables

View Source
var ErrInvalidToken = errors.New("invalid or expired token")

Functions

func GetSwagger

func GetSwagger() (swagger *openapi3.T, err error)

GetSwagger returns the Swagger specification corresponding to the generated code in this file. The external references of Swagger specification are resolved. The logic of resolving external references is tightly connected to "import-mapping" feature. Externally referenced files must be embedded in the corresponding golang packages. Urls can be supported but this task was out of the scope.

func Handler

func Handler(si ServerInterface) http.Handler

Handler creates http.Handler with routing matching OpenAPI spec.

func HandlerFromMux

func HandlerFromMux(si ServerInterface, r chi.Router) http.Handler

HandlerFromMux creates http.Handler with routing matching OpenAPI spec based on the provided mux.

func HandlerFromMuxWithBaseURL

func HandlerFromMuxWithBaseURL(si ServerInterface, r chi.Router, baseURL string) http.Handler

func HandlerWithOptions

func HandlerWithOptions(si ServerInterface, options ChiServerOptions) http.Handler

HandlerWithOptions creates http.Handler with additional options

func PathToRawSpec

func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error)

Constructs a synthetic filesystem for resolving external references when loading openapi specifications.

Types

type AuthResponse

type AuthResponse struct {
	// AccessToken JWT access token
	AccessToken string `json:"accessToken"`

	// ExpiresIn Token expiration time in seconds
	ExpiresIn int `json:"expiresIn"`

	// RefreshToken JWT refresh token
	RefreshToken string `json:"refreshToken"`
}

AuthResponse defines model for AuthResponse.

func (AuthResponse) Render

type BadRequest

type BadRequest = Error

BadRequest defines model for BadRequest.

type ChiServerOptions

type ChiServerOptions struct {
	BaseURL          string
	BaseRouter       chi.Router
	Middlewares      []MiddlewareFunc
	ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
}

type CreateUserJSONRequestBody

type CreateUserJSONRequestBody = UserCreate

CreateUserJSONRequestBody defines body for CreateUser for application/json ContentType.

type Error

type Error struct {
	Error      *string `json:"error,omitempty"`
	Status     string  `json:"status"`
	StatusCode int32   `json:"statusCode"`
}

Error defines model for Error.

type Forbidden

type Forbidden = Error

Forbidden defines model for Forbidden.

type InvalidParamFormatError

type InvalidParamFormatError struct {
	ParamName string
	Err       error
}

func (*InvalidParamFormatError) Error

func (e *InvalidParamFormatError) Error() string

func (*InvalidParamFormatError) Unwrap

func (e *InvalidParamFormatError) Unwrap() error

type ListUsersParams

type ListUsersParams struct {
	Offset *int `form:"offset,omitempty" json:"offset,omitempty"`
	Limit  *int `form:"limit,omitempty" json:"limit,omitempty"`
}

ListUsersParams defines parameters for ListUsers.

type LoginRequest

type LoginRequest struct {
	// Email User's email address
	Email openapi_types.Email `json:"email"`

	// Password User's password
	Password string `json:"password"`
}

LoginRequest defines model for LoginRequest.

func (LoginRequest) Bind

func (c LoginRequest) Bind(r *http.Request) error

type LoginUserJSONRequestBody

type LoginUserJSONRequestBody = LoginRequest

LoginUserJSONRequestBody defines body for LoginUser for application/json ContentType.

type MiddlewareFunc

type MiddlewareFunc func(http.Handler) http.Handler

type NotFound

type NotFound = Error

NotFound defines model for NotFound.

type PasswordResetConfirmation

type PasswordResetConfirmation struct {
	// ConfirmPassword Confirm the new password
	ConfirmPassword string `json:"confirmPassword"`

	// NewPassword New password to set
	NewPassword string `json:"newPassword"`
}

PasswordResetConfirmation defines model for PasswordResetConfirmation.

func (PasswordResetConfirmation) Bind

type PasswordResetRequest

type PasswordResetRequest struct {
	// Email The email address of the account to reset
	Email openapi_types.Email `json:"email"`
}

PasswordResetRequest defines model for PasswordResetRequest.

func (PasswordResetRequest) Bind

type RefreshTokenJSONRequestBody

type RefreshTokenJSONRequestBody = RefreshTokenRequest

RefreshTokenJSONRequestBody defines body for RefreshToken for application/json ContentType.

type RefreshTokenRequest

type RefreshTokenRequest struct {
	// RefreshToken JWT refresh token
	RefreshToken string `json:"refreshToken"`
}

RefreshTokenRequest defines model for RefreshTokenRequest.

func (RefreshTokenRequest) Bind

type RequestPasswordResetJSONRequestBody

type RequestPasswordResetJSONRequestBody = PasswordResetRequest

RequestPasswordResetJSONRequestBody defines body for RequestPasswordReset for application/json ContentType.

type RequiredHeaderError

type RequiredHeaderError struct {
	ParamName string
	Err       error
}

func (*RequiredHeaderError) Error

func (e *RequiredHeaderError) Error() string

func (*RequiredHeaderError) Unwrap

func (e *RequiredHeaderError) Unwrap() error

type RequiredParamError

type RequiredParamError struct {
	ParamName string
}

func (*RequiredParamError) Error

func (e *RequiredParamError) Error() string

type ResetPasswordJSONRequestBody

type ResetPasswordJSONRequestBody = PasswordResetConfirmation

ResetPasswordJSONRequestBody defines body for ResetPassword for application/json ContentType.

type Server

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

func NewServer

func NewServer(
	engine store.Engine,
	clock clock.PassiveClock,
	jwsVerifier auth.JWSVerifier,
	jwsSigner auth.JWSSigner,
	producer transport.Producer,
) (*Server, error)

func (*Server) CreateUser

func (s *Server) CreateUser(w http.ResponseWriter, r *http.Request)

func (*Server) DeleteUser

func (s *Server) DeleteUser(w http.ResponseWriter, r *http.Request, ID openapi_types.UUID)

func (*Server) GetCurrentUser

func (s *Server) GetCurrentUser(w http.ResponseWriter, r *http.Request)

func (*Server) ListUsers

func (s *Server) ListUsers(w http.ResponseWriter, r *http.Request, params ListUsersParams)

func (*Server) LoginUser

func (s *Server) LoginUser(w http.ResponseWriter, r *http.Request)

func (*Server) LogoutUser

func (s *Server) LogoutUser(w http.ResponseWriter, r *http.Request)

func (*Server) LookupUser

func (s *Server) LookupUser(w http.ResponseWriter, r *http.Request, ID openapi_types.UUID)

func (*Server) RefreshToken

func (s *Server) RefreshToken(w http.ResponseWriter, r *http.Request)

func (*Server) RequestPasswordReset

func (s *Server) RequestPasswordReset(w http.ResponseWriter, r *http.Request)

func (*Server) ResetPassword

func (s *Server) ResetPassword(w http.ResponseWriter, r *http.Request, token string)

func (*Server) UpdateCurrentUser

func (s *Server) UpdateCurrentUser(w http.ResponseWriter, r *http.Request)

func (*Server) UpdateUser

func (s *Server) UpdateUser(w http.ResponseWriter, r *http.Request, ID openapi_types.UUID)

func (*Server) VerifyAccount

func (s *Server) VerifyAccount(w http.ResponseWriter, r *http.Request, token string)

type ServerError

type ServerError = Error

ServerError defines model for ServerError.

type ServerInterface

type ServerInterface interface {
	// User login
	// (POST /auth/login)
	LoginUser(w http.ResponseWriter, r *http.Request)
	// User logout
	// (POST /auth/logout)
	LogoutUser(w http.ResponseWriter, r *http.Request)
	// Request password reset
	// (POST /auth/password-reset)
	RequestPasswordReset(w http.ResponseWriter, r *http.Request)
	// Reset password
	// (POST /auth/password-reset/{token})
	ResetPassword(w http.ResponseWriter, r *http.Request, token string)
	// Refresh access token
	// (POST /auth/refresh)
	RefreshToken(w http.ResponseWriter, r *http.Request)
	// Verify user account
	// (GET /auth/verify/{token})
	VerifyAccount(w http.ResponseWriter, r *http.Request, token string)
	// Get all users
	// (GET /users)
	ListUsers(w http.ResponseWriter, r *http.Request, params ListUsersParams)
	// Create a new user
	// (POST /users)
	CreateUser(w http.ResponseWriter, r *http.Request)
	// Get current user
	// (GET /users/me)
	GetCurrentUser(w http.ResponseWriter, r *http.Request)
	// Update current user
	// (PUT /users/me)
	UpdateCurrentUser(w http.ResponseWriter, r *http.Request)
	// Delete user
	// (DELETE /users/{userId})
	DeleteUser(w http.ResponseWriter, r *http.Request, userId openapi_types.UUID)
	// Get user by ID
	// (GET /users/{userId})
	LookupUser(w http.ResponseWriter, r *http.Request, userId openapi_types.UUID)
	// Update user
	// (PUT /users/{userId})
	UpdateUser(w http.ResponseWriter, r *http.Request, userId openapi_types.UUID)
}

ServerInterface represents all server handlers.

type ServerInterfaceWrapper

type ServerInterfaceWrapper struct {
	Handler            ServerInterface
	HandlerMiddlewares []MiddlewareFunc
	ErrorHandlerFunc   func(w http.ResponseWriter, r *http.Request, err error)
}

ServerInterfaceWrapper converts contexts to parameters.

func (*ServerInterfaceWrapper) CreateUser

func (siw *ServerInterfaceWrapper) CreateUser(w http.ResponseWriter, r *http.Request)

CreateUser operation middleware

func (*ServerInterfaceWrapper) DeleteUser

func (siw *ServerInterfaceWrapper) DeleteUser(w http.ResponseWriter, r *http.Request)

DeleteUser operation middleware

func (*ServerInterfaceWrapper) GetCurrentUser

func (siw *ServerInterfaceWrapper) GetCurrentUser(w http.ResponseWriter, r *http.Request)

GetCurrentUser operation middleware

func (*ServerInterfaceWrapper) ListUsers

func (siw *ServerInterfaceWrapper) ListUsers(w http.ResponseWriter, r *http.Request)

ListUsers operation middleware

func (*ServerInterfaceWrapper) LoginUser

func (siw *ServerInterfaceWrapper) LoginUser(w http.ResponseWriter, r *http.Request)

LoginUser operation middleware

func (*ServerInterfaceWrapper) LogoutUser

func (siw *ServerInterfaceWrapper) LogoutUser(w http.ResponseWriter, r *http.Request)

LogoutUser operation middleware

func (*ServerInterfaceWrapper) LookupUser

func (siw *ServerInterfaceWrapper) LookupUser(w http.ResponseWriter, r *http.Request)

LookupUser operation middleware

func (*ServerInterfaceWrapper) RefreshToken

func (siw *ServerInterfaceWrapper) RefreshToken(w http.ResponseWriter, r *http.Request)

RefreshToken operation middleware

func (*ServerInterfaceWrapper) RequestPasswordReset

func (siw *ServerInterfaceWrapper) RequestPasswordReset(w http.ResponseWriter, r *http.Request)

RequestPasswordReset operation middleware

func (*ServerInterfaceWrapper) ResetPassword

func (siw *ServerInterfaceWrapper) ResetPassword(w http.ResponseWriter, r *http.Request)

ResetPassword operation middleware

func (*ServerInterfaceWrapper) UpdateCurrentUser

func (siw *ServerInterfaceWrapper) UpdateCurrentUser(w http.ResponseWriter, r *http.Request)

UpdateCurrentUser operation middleware

func (*ServerInterfaceWrapper) UpdateUser

func (siw *ServerInterfaceWrapper) UpdateUser(w http.ResponseWriter, r *http.Request)

UpdateUser operation middleware

func (*ServerInterfaceWrapper) VerifyAccount

func (siw *ServerInterfaceWrapper) VerifyAccount(w http.ResponseWriter, r *http.Request)

VerifyAccount operation middleware

type TooManyValuesForParamError

type TooManyValuesForParamError struct {
	ParamName string
	Count     int
}

func (*TooManyValuesForParamError) Error

type Unauthorized

type Unauthorized = Error

Unauthorized defines model for Unauthorized.

type UnescapedCookieParamError

type UnescapedCookieParamError struct {
	ParamName string
	Err       error
}

func (*UnescapedCookieParamError) Error

func (e *UnescapedCookieParamError) Error() string

func (*UnescapedCookieParamError) Unwrap

func (e *UnescapedCookieParamError) Unwrap() error

type Unimplemented

type Unimplemented struct{}

func (Unimplemented) CreateUser

func (_ Unimplemented) CreateUser(w http.ResponseWriter, r *http.Request)

Create a new user (POST /users)

func (Unimplemented) DeleteUser

func (_ Unimplemented) DeleteUser(w http.ResponseWriter, r *http.Request, userId openapi_types.UUID)

Delete user (DELETE /users/{userId})

func (Unimplemented) GetCurrentUser

func (_ Unimplemented) GetCurrentUser(w http.ResponseWriter, r *http.Request)

Get current user (GET /users/me)

func (Unimplemented) ListUsers

func (_ Unimplemented) ListUsers(w http.ResponseWriter, r *http.Request, params ListUsersParams)

Get all users (GET /users)

func (Unimplemented) LoginUser

func (_ Unimplemented) LoginUser(w http.ResponseWriter, r *http.Request)

User login (POST /auth/login)

func (Unimplemented) LogoutUser

func (_ Unimplemented) LogoutUser(w http.ResponseWriter, r *http.Request)

User logout (POST /auth/logout)

func (Unimplemented) LookupUser

func (_ Unimplemented) LookupUser(w http.ResponseWriter, r *http.Request, userId openapi_types.UUID)

Get user by ID (GET /users/{userId})

func (Unimplemented) RefreshToken

func (_ Unimplemented) RefreshToken(w http.ResponseWriter, r *http.Request)

Refresh access token (POST /auth/refresh)

func (Unimplemented) RequestPasswordReset

func (_ Unimplemented) RequestPasswordReset(w http.ResponseWriter, r *http.Request)

Request password reset (POST /auth/password-reset)

func (Unimplemented) ResetPassword

func (_ Unimplemented) ResetPassword(w http.ResponseWriter, r *http.Request, token string)

Reset password (POST /auth/password-reset/{token})

func (Unimplemented) UpdateCurrentUser

func (_ Unimplemented) UpdateCurrentUser(w http.ResponseWriter, r *http.Request)

Update current user (PUT /users/me)

func (Unimplemented) UpdateUser

func (_ Unimplemented) UpdateUser(w http.ResponseWriter, r *http.Request, userId openapi_types.UUID)

Update user (PUT /users/{userId})

func (Unimplemented) VerifyAccount

func (_ Unimplemented) VerifyAccount(w http.ResponseWriter, r *http.Request, token string)

Verify user account (GET /auth/verify/{token})

type UnmarshalingParamError

type UnmarshalingParamError struct {
	ParamName string
	Err       error
}

func (*UnmarshalingParamError) Error

func (e *UnmarshalingParamError) Error() string

func (*UnmarshalingParamError) Unwrap

func (e *UnmarshalingParamError) Unwrap() error

type UpdateCurrentUserJSONRequestBody

type UpdateCurrentUserJSONRequestBody = UserUpdateCurrent

UpdateCurrentUserJSONRequestBody defines body for UpdateCurrentUser for application/json ContentType.

type UpdateUserJSONRequestBody

type UpdateUserJSONRequestBody = UserUpdate

UpdateUserJSONRequestBody defines body for UpdateUser for application/json ContentType.

type User

type User struct {
	// Email User's email address
	Email openapi_types.Email `json:"email"`

	// FirstName User's first name
	FirstName string `json:"firstName"`

	// Id Unique identifier for the user
	Id openapi_types.UUID `json:"id"`

	// LastName User's last name
	LastName string `json:"lastName"`

	// Role User's role in the system
	Role UserRole `json:"role"`

	// Status User's account status
	Status UserStatus `json:"status"`
}

User defines model for User.

func (User) Render

func (c User) Render(w http.ResponseWriter, r *http.Request) error

type UserCreate

type UserCreate struct {
	// Email User's email address
	Email openapi_types.Email `json:"email"`

	// FirstName User's first name
	FirstName string `json:"firstName"`

	// LastName User's last name
	LastName string `json:"lastName"`

	// Password User's password
	Password string `json:"password"`
}

UserCreate defines model for UserCreate.

func (UserCreate) Bind

func (c UserCreate) Bind(r *http.Request) error

type UserRole

type UserRole string

UserRole User's role in the system

const (
	UserRoleAdmin UserRole = "admin"
	UserRoleUser  UserRole = "user"
)

Defines values for UserRole.

type UserStatus

type UserStatus string

UserStatus User's account status

const (
	UserStatusActive  UserStatus = "active"
	UserStatusBanned  UserStatus = "banned"
	UserStatusPending UserStatus = "pending"
)

Defines values for UserStatus.

type UserUpdate

type UserUpdate struct {
	// Email User's email address
	Email *openapi_types.Email `json:"email,omitempty"`

	// FirstName User's first name
	FirstName *string `json:"firstName,omitempty"`

	// LastName User's last name
	LastName *string `json:"lastName,omitempty"`

	// Role User's role in the system
	Role *UserUpdateRole `json:"role,omitempty"`

	// Status User's account status
	Status *UserUpdateStatus `json:"status,omitempty"`
}

UserUpdate defines model for UserUpdate.

func (UserUpdate) Bind

func (c UserUpdate) Bind(r *http.Request) error

type UserUpdateCurrent

type UserUpdateCurrent struct {
	// CurrentPassword User's current password (required when changing password)
	CurrentPassword string `json:"currentPassword"`

	// Email User's email address
	Email *openapi_types.Email `json:"email,omitempty"`

	// FirstName User's first name
	FirstName *string `json:"firstName,omitempty"`

	// LastName User's last name
	LastName *string `json:"lastName,omitempty"`

	// Password User's new password
	Password *string `json:"password,omitempty"`
}

UserUpdateCurrent defines model for UserUpdateCurrent.

func (UserUpdateCurrent) Bind

func (c UserUpdateCurrent) Bind(r *http.Request) error

type UserUpdateRole

type UserUpdateRole string

UserUpdateRole User's role in the system

const (
	UserUpdateRoleAdmin UserUpdateRole = "admin"
	UserUpdateRoleUser  UserUpdateRole = "user"
)

Defines values for UserUpdateRole.

type UserUpdateStatus

type UserUpdateStatus string

UserUpdateStatus User's account status

const (
	UserUpdateStatusActive  UserUpdateStatus = "active"
	UserUpdateStatusBanned  UserUpdateStatus = "banned"
	UserUpdateStatusPending UserUpdateStatus = "pending"
)

Defines values for UserUpdateStatus.

Jump to

Keyboard shortcuts

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