fix: regen oapi for auth
All checks were successful
Build and Deploy Go App / build (push) Successful in 5m51s
Build and Deploy Go App / deploy (push) Successful in 25s

This commit is contained in:
nihonium 2025-12-04 07:20:10 +03:00
parent e316617175
commit b03f9c9704
Signed by: nihonium
GPG key ID: 0251623741027CFC
2 changed files with 60 additions and 60 deletions

View file

@ -13,32 +13,32 @@ import (
strictgin "github.com/oapi-codegen/runtime/strictmiddleware/gin" strictgin "github.com/oapi-codegen/runtime/strictmiddleware/gin"
) )
// PostAuthSignInJSONBody defines parameters for PostAuthSignIn. // PostSignInJSONBody defines parameters for PostSignIn.
type PostAuthSignInJSONBody struct { type PostSignInJSONBody struct {
Nickname string `json:"nickname"` Nickname string `json:"nickname"`
Pass string `json:"pass"` Pass string `json:"pass"`
} }
// PostAuthSignUpJSONBody defines parameters for PostAuthSignUp. // PostSignUpJSONBody defines parameters for PostSignUp.
type PostAuthSignUpJSONBody struct { type PostSignUpJSONBody struct {
Nickname string `json:"nickname"` Nickname string `json:"nickname"`
Pass string `json:"pass"` Pass string `json:"pass"`
} }
// PostAuthSignInJSONRequestBody defines body for PostAuthSignIn for application/json ContentType. // PostSignInJSONRequestBody defines body for PostSignIn for application/json ContentType.
type PostAuthSignInJSONRequestBody PostAuthSignInJSONBody type PostSignInJSONRequestBody PostSignInJSONBody
// PostAuthSignUpJSONRequestBody defines body for PostAuthSignUp for application/json ContentType. // PostSignUpJSONRequestBody defines body for PostSignUp for application/json ContentType.
type PostAuthSignUpJSONRequestBody PostAuthSignUpJSONBody type PostSignUpJSONRequestBody PostSignUpJSONBody
// ServerInterface represents all server handlers. // ServerInterface represents all server handlers.
type ServerInterface interface { type ServerInterface interface {
// Sign in a user and return JWT // Sign in a user and return JWT
// (POST /auth/sign-in) // (POST /sign-in)
PostAuthSignIn(c *gin.Context) PostSignIn(c *gin.Context)
// Sign up a new user // Sign up a new user
// (POST /auth/sign-up) // (POST /sign-up)
PostAuthSignUp(c *gin.Context) PostSignUp(c *gin.Context)
} }
// ServerInterfaceWrapper converts contexts to parameters. // ServerInterfaceWrapper converts contexts to parameters.
@ -50,8 +50,8 @@ type ServerInterfaceWrapper struct {
type MiddlewareFunc func(c *gin.Context) type MiddlewareFunc func(c *gin.Context)
// PostAuthSignIn operation middleware // PostSignIn operation middleware
func (siw *ServerInterfaceWrapper) PostAuthSignIn(c *gin.Context) { func (siw *ServerInterfaceWrapper) PostSignIn(c *gin.Context) {
for _, middleware := range siw.HandlerMiddlewares { for _, middleware := range siw.HandlerMiddlewares {
middleware(c) middleware(c)
@ -60,11 +60,11 @@ func (siw *ServerInterfaceWrapper) PostAuthSignIn(c *gin.Context) {
} }
} }
siw.Handler.PostAuthSignIn(c) siw.Handler.PostSignIn(c)
} }
// PostAuthSignUp operation middleware // PostSignUp operation middleware
func (siw *ServerInterfaceWrapper) PostAuthSignUp(c *gin.Context) { func (siw *ServerInterfaceWrapper) PostSignUp(c *gin.Context) {
for _, middleware := range siw.HandlerMiddlewares { for _, middleware := range siw.HandlerMiddlewares {
middleware(c) middleware(c)
@ -73,7 +73,7 @@ func (siw *ServerInterfaceWrapper) PostAuthSignUp(c *gin.Context) {
} }
} }
siw.Handler.PostAuthSignUp(c) siw.Handler.PostSignUp(c)
} }
// GinServerOptions provides options for the Gin server. // GinServerOptions provides options for the Gin server.
@ -103,54 +103,54 @@ func RegisterHandlersWithOptions(router gin.IRouter, si ServerInterface, options
ErrorHandler: errorHandler, ErrorHandler: errorHandler,
} }
router.POST(options.BaseURL+"/auth/sign-in", wrapper.PostAuthSignIn) router.POST(options.BaseURL+"/sign-in", wrapper.PostSignIn)
router.POST(options.BaseURL+"/auth/sign-up", wrapper.PostAuthSignUp) router.POST(options.BaseURL+"/sign-up", wrapper.PostSignUp)
} }
type PostAuthSignInRequestObject struct { type PostSignInRequestObject struct {
Body *PostAuthSignInJSONRequestBody Body *PostSignInJSONRequestBody
} }
type PostAuthSignInResponseObject interface { type PostSignInResponseObject interface {
VisitPostAuthSignInResponse(w http.ResponseWriter) error VisitPostSignInResponse(w http.ResponseWriter) error
} }
type PostAuthSignIn200JSONResponse struct { type PostSignIn200JSONResponse struct {
UserId int64 `json:"user_id"` UserId int64 `json:"user_id"`
UserName string `json:"user_name"` UserName string `json:"user_name"`
} }
func (response PostAuthSignIn200JSONResponse) VisitPostAuthSignInResponse(w http.ResponseWriter) error { func (response PostSignIn200JSONResponse) VisitPostSignInResponse(w http.ResponseWriter) error {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.WriteHeader(200) w.WriteHeader(200)
return json.NewEncoder(w).Encode(response) return json.NewEncoder(w).Encode(response)
} }
type PostAuthSignIn401JSONResponse struct { type PostSignIn401JSONResponse struct {
Error *string `json:"error,omitempty"` Error *string `json:"error,omitempty"`
} }
func (response PostAuthSignIn401JSONResponse) VisitPostAuthSignInResponse(w http.ResponseWriter) error { func (response PostSignIn401JSONResponse) VisitPostSignInResponse(w http.ResponseWriter) error {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.WriteHeader(401) w.WriteHeader(401)
return json.NewEncoder(w).Encode(response) return json.NewEncoder(w).Encode(response)
} }
type PostAuthSignUpRequestObject struct { type PostSignUpRequestObject struct {
Body *PostAuthSignUpJSONRequestBody Body *PostSignUpJSONRequestBody
} }
type PostAuthSignUpResponseObject interface { type PostSignUpResponseObject interface {
VisitPostAuthSignUpResponse(w http.ResponseWriter) error VisitPostSignUpResponse(w http.ResponseWriter) error
} }
type PostAuthSignUp200JSONResponse struct { type PostSignUp200JSONResponse struct {
UserId int64 `json:"user_id"` UserId int64 `json:"user_id"`
} }
func (response PostAuthSignUp200JSONResponse) VisitPostAuthSignUpResponse(w http.ResponseWriter) error { func (response PostSignUp200JSONResponse) VisitPostSignUpResponse(w http.ResponseWriter) error {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.WriteHeader(200) w.WriteHeader(200)
@ -160,11 +160,11 @@ func (response PostAuthSignUp200JSONResponse) VisitPostAuthSignUpResponse(w http
// StrictServerInterface represents all server handlers. // StrictServerInterface represents all server handlers.
type StrictServerInterface interface { type StrictServerInterface interface {
// Sign in a user and return JWT // Sign in a user and return JWT
// (POST /auth/sign-in) // (POST /sign-in)
PostAuthSignIn(ctx context.Context, request PostAuthSignInRequestObject) (PostAuthSignInResponseObject, error) PostSignIn(ctx context.Context, request PostSignInRequestObject) (PostSignInResponseObject, error)
// Sign up a new user // Sign up a new user
// (POST /auth/sign-up) // (POST /sign-up)
PostAuthSignUp(ctx context.Context, request PostAuthSignUpRequestObject) (PostAuthSignUpResponseObject, error) PostSignUp(ctx context.Context, request PostSignUpRequestObject) (PostSignUpResponseObject, error)
} }
type StrictHandlerFunc = strictgin.StrictGinHandlerFunc type StrictHandlerFunc = strictgin.StrictGinHandlerFunc
@ -179,11 +179,11 @@ type strictHandler struct {
middlewares []StrictMiddlewareFunc middlewares []StrictMiddlewareFunc
} }
// PostAuthSignIn operation middleware // PostSignIn operation middleware
func (sh *strictHandler) PostAuthSignIn(ctx *gin.Context) { func (sh *strictHandler) PostSignIn(ctx *gin.Context) {
var request PostAuthSignInRequestObject var request PostSignInRequestObject
var body PostAuthSignInJSONRequestBody var body PostSignInJSONRequestBody
if err := ctx.ShouldBindJSON(&body); err != nil { if err := ctx.ShouldBindJSON(&body); err != nil {
ctx.Status(http.StatusBadRequest) ctx.Status(http.StatusBadRequest)
ctx.Error(err) ctx.Error(err)
@ -192,10 +192,10 @@ func (sh *strictHandler) PostAuthSignIn(ctx *gin.Context) {
request.Body = &body request.Body = &body
handler := func(ctx *gin.Context, request interface{}) (interface{}, error) { handler := func(ctx *gin.Context, request interface{}) (interface{}, error) {
return sh.ssi.PostAuthSignIn(ctx, request.(PostAuthSignInRequestObject)) return sh.ssi.PostSignIn(ctx, request.(PostSignInRequestObject))
} }
for _, middleware := range sh.middlewares { for _, middleware := range sh.middlewares {
handler = middleware(handler, "PostAuthSignIn") handler = middleware(handler, "PostSignIn")
} }
response, err := handler(ctx, request) response, err := handler(ctx, request)
@ -203,8 +203,8 @@ func (sh *strictHandler) PostAuthSignIn(ctx *gin.Context) {
if err != nil { if err != nil {
ctx.Error(err) ctx.Error(err)
ctx.Status(http.StatusInternalServerError) ctx.Status(http.StatusInternalServerError)
} else if validResponse, ok := response.(PostAuthSignInResponseObject); ok { } else if validResponse, ok := response.(PostSignInResponseObject); ok {
if err := validResponse.VisitPostAuthSignInResponse(ctx.Writer); err != nil { if err := validResponse.VisitPostSignInResponse(ctx.Writer); err != nil {
ctx.Error(err) ctx.Error(err)
} }
} else if response != nil { } else if response != nil {
@ -212,11 +212,11 @@ func (sh *strictHandler) PostAuthSignIn(ctx *gin.Context) {
} }
} }
// PostAuthSignUp operation middleware // PostSignUp operation middleware
func (sh *strictHandler) PostAuthSignUp(ctx *gin.Context) { func (sh *strictHandler) PostSignUp(ctx *gin.Context) {
var request PostAuthSignUpRequestObject var request PostSignUpRequestObject
var body PostAuthSignUpJSONRequestBody var body PostSignUpJSONRequestBody
if err := ctx.ShouldBindJSON(&body); err != nil { if err := ctx.ShouldBindJSON(&body); err != nil {
ctx.Status(http.StatusBadRequest) ctx.Status(http.StatusBadRequest)
ctx.Error(err) ctx.Error(err)
@ -225,10 +225,10 @@ func (sh *strictHandler) PostAuthSignUp(ctx *gin.Context) {
request.Body = &body request.Body = &body
handler := func(ctx *gin.Context, request interface{}) (interface{}, error) { handler := func(ctx *gin.Context, request interface{}) (interface{}, error) {
return sh.ssi.PostAuthSignUp(ctx, request.(PostAuthSignUpRequestObject)) return sh.ssi.PostSignUp(ctx, request.(PostSignUpRequestObject))
} }
for _, middleware := range sh.middlewares { for _, middleware := range sh.middlewares {
handler = middleware(handler, "PostAuthSignUp") handler = middleware(handler, "PostSignUp")
} }
response, err := handler(ctx, request) response, err := handler(ctx, request)
@ -236,8 +236,8 @@ func (sh *strictHandler) PostAuthSignUp(ctx *gin.Context) {
if err != nil { if err != nil {
ctx.Error(err) ctx.Error(err)
ctx.Status(http.StatusInternalServerError) ctx.Status(http.StatusInternalServerError)
} else if validResponse, ok := response.(PostAuthSignUpResponseObject); ok { } else if validResponse, ok := response.(PostSignUpResponseObject); ok {
if err := validResponse.VisitPostAuthSignUpResponse(ctx.Writer); err != nil { if err := validResponse.VisitPostSignUpResponse(ctx.Writer); err != nil {
ctx.Error(err) ctx.Error(err)
} }
} else if response != nil { } else if response != nil {

View file

@ -78,7 +78,7 @@ func (s Server) generateTokens(userID string) (accessToken string, refreshToken
return accessToken, refreshToken, csrfToken, nil return accessToken, refreshToken, csrfToken, nil
} }
func (s Server) PostAuthSignUp(ctx context.Context, req auth.PostAuthSignUpRequestObject) (auth.PostAuthSignUpResponseObject, error) { func (s Server) PostSignUp(ctx context.Context, req auth.PostSignUpRequestObject) (auth.PostSignUpResponseObject, error) {
passhash, err := HashPassword(req.Body.Pass) passhash, err := HashPassword(req.Body.Pass)
if err != nil { if err != nil {
log.Errorf("failed to hash password: %v", err) log.Errorf("failed to hash password: %v", err)
@ -94,17 +94,17 @@ func (s Server) PostAuthSignUp(ctx context.Context, req auth.PostAuthSignUpReque
// TODO: check err and retyrn 400/500 // TODO: check err and retyrn 400/500
} }
return auth.PostAuthSignUp200JSONResponse{ return auth.PostSignUp200JSONResponse{
UserId: user_id, UserId: user_id,
}, nil }, nil
} }
func (s Server) PostAuthSignIn(ctx context.Context, req auth.PostAuthSignInRequestObject) (auth.PostAuthSignInResponseObject, error) { func (s Server) PostSignIn(ctx context.Context, req auth.PostSignInRequestObject) (auth.PostSignInResponseObject, error) {
ginCtx, ok := ctx.Value(gin.ContextKey).(*gin.Context) ginCtx, ok := ctx.Value(gin.ContextKey).(*gin.Context)
if !ok { if !ok {
log.Print("failed to get gin context") log.Print("failed to get gin context")
// TODO: change to 500 // TODO: change to 500
return auth.PostAuthSignIn200JSONResponse{}, fmt.Errorf("failed to get gin.Context from context.Context") return auth.PostSignIn200JSONResponse{}, fmt.Errorf("failed to get gin.Context from context.Context")
} }
user, err := s.db.GetUserByNickname(context.Background(), req.Body.Nickname) user, err := s.db.GetUserByNickname(context.Background(), req.Body.Nickname)
@ -120,7 +120,7 @@ func (s Server) PostAuthSignIn(ctx context.Context, req auth.PostAuthSignInReque
} }
if !ok { if !ok {
err_msg := "invalid credentials" err_msg := "invalid credentials"
return auth.PostAuthSignIn401JSONResponse{ return auth.PostSignIn401JSONResponse{
Error: &err_msg, Error: &err_msg,
}, nil }, nil
} }
@ -137,7 +137,7 @@ func (s Server) PostAuthSignIn(ctx context.Context, req auth.PostAuthSignInReque
ginCtx.SetCookie("refresh_token", refreshToken, 1209600, "/auth", "", false, true) ginCtx.SetCookie("refresh_token", refreshToken, 1209600, "/auth", "", false, true)
ginCtx.SetCookie("xsrf_token", csrfToken, 1209600, "/api", "", false, false) ginCtx.SetCookie("xsrf_token", csrfToken, 1209600, "/api", "", false, false)
result := auth.PostAuthSignIn200JSONResponse{ result := auth.PostSignIn200JSONResponse{
UserId: user.ID, UserId: user.ID,
UserName: user.Nickname, UserName: user.Nickname,
} }