From 0ad7b9e54615eedfffa41709900d8e86814d2471 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 1 Aug 2024 21:06:50 +0900 Subject: feat: explicitly define 401 responses in OpenAPI spec --- backend/api/generated.go | 124 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 95 insertions(+), 29 deletions(-) (limited to 'backend/api/generated.go') diff --git a/backend/api/generated.go b/backend/api/generated.go index a2fa329..c786f56 100644 --- a/backend/api/generated.go +++ b/backend/api/generated.go @@ -973,6 +973,17 @@ func (response GetAdminGames200JSONResponse) VisitGetAdminGamesResponse(w http.R return json.NewEncoder(w).Encode(response) } +type GetAdminGames401JSONResponse struct { + Message string `json:"message"` +} + +func (response GetAdminGames401JSONResponse) VisitGetAdminGamesResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(401) + + return json.NewEncoder(w).Encode(response) +} + type GetAdminGames403JSONResponse struct { Message string `json:"message"` } @@ -1004,6 +1015,17 @@ func (response GetAdminGamesGameId200JSONResponse) VisitGetAdminGamesGameIdRespo return json.NewEncoder(w).Encode(response) } +type GetAdminGamesGameId401JSONResponse struct { + Message string `json:"message"` +} + +func (response GetAdminGamesGameId401JSONResponse) VisitGetAdminGamesGameIdResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(401) + + return json.NewEncoder(w).Encode(response) +} + type GetAdminGamesGameId403JSONResponse struct { Message string `json:"message"` } @@ -1055,6 +1077,17 @@ func (response PutAdminGamesGameId400JSONResponse) VisitPutAdminGamesGameIdRespo return json.NewEncoder(w).Encode(response) } +type PutAdminGamesGameId401JSONResponse struct { + Message string `json:"message"` +} + +func (response PutAdminGamesGameId401JSONResponse) VisitPutAdminGamesGameIdResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(401) + + return json.NewEncoder(w).Encode(response) +} + type PutAdminGamesGameId403JSONResponse struct { Message string `json:"message"` } @@ -1096,6 +1129,17 @@ func (response GetAdminUsers200JSONResponse) VisitGetAdminUsersResponse(w http.R return json.NewEncoder(w).Encode(response) } +type GetAdminUsers401JSONResponse struct { + Message string `json:"message"` +} + +func (response GetAdminUsers401JSONResponse) VisitGetAdminUsersResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(401) + + return json.NewEncoder(w).Encode(response) +} + type GetAdminUsers403JSONResponse struct { Message string `json:"message"` } @@ -1126,6 +1170,17 @@ func (response GetGames200JSONResponse) VisitGetGamesResponse(w http.ResponseWri return json.NewEncoder(w).Encode(response) } +type GetGames401JSONResponse struct { + Message string `json:"message"` +} + +func (response GetGames401JSONResponse) VisitGetGamesResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(401) + + return json.NewEncoder(w).Encode(response) +} + type GetGames403JSONResponse struct { Message string `json:"message"` } @@ -1157,6 +1212,17 @@ func (response GetGamesGameId200JSONResponse) VisitGetGamesGameIdResponse(w http return json.NewEncoder(w).Encode(response) } +type GetGamesGameId401JSONResponse struct { + Message string `json:"message"` +} + +func (response GetGamesGameId401JSONResponse) VisitGetGamesGameIdResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(401) + + return json.NewEncoder(w).Encode(response) +} + type GetGamesGameId403JSONResponse struct { Message string `json:"message"` } @@ -1228,13 +1294,13 @@ func (response GetToken200JSONResponse) VisitGetTokenResponse(w http.ResponseWri return json.NewEncoder(w).Encode(response) } -type GetToken403JSONResponse struct { +type GetToken401JSONResponse struct { Message string `json:"message"` } -func (response GetToken403JSONResponse) VisitGetTokenResponse(w http.ResponseWriter) error { +func (response GetToken401JSONResponse) VisitGetTokenResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") - w.WriteHeader(403) + w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } @@ -1495,32 +1561,32 @@ func (sh *strictHandler) GetToken(ctx echo.Context, params GetTokenParams) error // Base64 encoded, gzipped, json marshaled Swagger object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+ "8qKDIopuVLwclWtM5D7h2DyzmsIadpfRNxLEPiOr3/mCBb9wcFlKIs4mKVaLukiPJHgOsnfHF+zkLp07", + "ReUExwmp+3eGqazIP+WcAmZ6dSYd5WV46vKoXtq0QkNp9WfxlTUljWFRibvpW62OsBk3DayNKzqnU6wE", + "lzLQEAXDNLiHaXA+vkIh+ghCmhRD/ZPBSV+j5ykwnBI0Qqcn/ZM+CpF2rwlRz3y3N8eJDdkcDCl0FM34", + "6ipGI3QJ6lwvuzSrtLTACSgQ0pyNtL/RAnAMAoXIugmdZ2rBBfnXaEHrLrG12BaRqi2v3HerF8uUM2kh", + "Dfv9vIAoYAYdTlNKIqO5dyctnSp99RwsLSMKEulT0qqqhbAQeOmc/cktoaqRHL0hUgV8FliJVYjO+oNH", + "2JJUZ94qCW8Yzl3tMbYsNPiAryk22E+7xv4rF1MSx8CCMuE6NaHUb7TILEmwWBZxyYOyCmsk6H3KR7sr", + "PzroH1fxFlKYKlZSopoZt5Jhbed5BvzyY5WDRV5BPDeROrLnS7JH4z/rGv+fXAUznrFuHV9prXP+ElSA", + "y1RKMwexx9nzJ/aHDKT6mdv594HReqqrxu1nWq/OreUu0a/7+0ruFh1pXQ/8qlG1zxpNBbq2feoso3QZ", + "ZGmMVVF8+l2T94p9xJTEQZ5xnVJ4U/ex9B9L/2NK/41hQln9qxOf7sja254bs+p5tT2lZV5tj2nf29oe", + "q3KftsdKHNn7VbU9mNIiMJoIrZ3/rqb/Qwbm7j5P/tqE8nm3NMeRwZE7O0cGewwLjnOC45zgeFh8jnMC", + "TXTK5/ZCIeXSNTPgUr0xS7rqvlMs5T0X8caVdf50MDx1td+PvKDI7yHKT98e1JE+pj4o/g9s3Is96H8n", + "az/brwqNEp/o1zplzUBgSkMtSDj4XP1yJCDW38JUfpaeuYhmwEVQhnOjHZIgApvWJsNL12/bwN6ZBc+r", + "Afq/59MTbUiO0igXXKgfKfkIcYCN1YH102q1Wv0XAAD//zFOGlvXMAAA", } // GetSwagger returns the content of the embedded swagger specification file -- cgit v1.2.3-70-g09d2 From 5e6775c9c1efbbd3b08363ffda421a5996dc7143 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 1 Aug 2024 21:07:37 +0900 Subject: refactor: specify `operationId` in OpenAPI spec --- backend/api/generated.go | 370 +++++++-------- backend/api/handlers.go | 36 +- frontend/app/.server/api/schema.d.ts | 889 ++++++++++++++++++----------------- openapi.yaml | 8 + 4 files changed, 660 insertions(+), 643 deletions(-) (limited to 'backend/api/generated.go') diff --git a/backend/api/generated.go b/backend/api/generated.go index c786f56..fe693f8 100644 --- a/backend/api/generated.go +++ b/backend/api/generated.go @@ -43,15 +43,15 @@ const ( GameWatcherMessageS2CExecResultPayloadStatusSuccess GameWatcherMessageS2CExecResultPayloadStatus = "success" ) -// Defines values for PutAdminGamesGameIdJSONBodyState. +// Defines values for AdminPutGameJSONBodyState. const ( - PutAdminGamesGameIdJSONBodyStateClosed PutAdminGamesGameIdJSONBodyState = "closed" - PutAdminGamesGameIdJSONBodyStateFinished PutAdminGamesGameIdJSONBodyState = "finished" - PutAdminGamesGameIdJSONBodyStateGaming PutAdminGamesGameIdJSONBodyState = "gaming" - PutAdminGamesGameIdJSONBodyStatePrepare PutAdminGamesGameIdJSONBodyState = "prepare" - PutAdminGamesGameIdJSONBodyStateStarting PutAdminGamesGameIdJSONBodyState = "starting" - PutAdminGamesGameIdJSONBodyStateWaitingEntries PutAdminGamesGameIdJSONBodyState = "waiting_entries" - PutAdminGamesGameIdJSONBodyStateWaitingStart PutAdminGamesGameIdJSONBodyState = "waiting_start" + AdminPutGameJSONBodyStateClosed AdminPutGameJSONBodyState = "closed" + AdminPutGameJSONBodyStateFinished AdminPutGameJSONBodyState = "finished" + AdminPutGameJSONBodyStateGaming AdminPutGameJSONBodyState = "gaming" + AdminPutGameJSONBodyStatePrepare AdminPutGameJSONBodyState = "prepare" + AdminPutGameJSONBodyStateStarting AdminPutGameJSONBodyState = "starting" + AdminPutGameJSONBodyStateWaitingEntries AdminPutGameJSONBodyState = "waiting_entries" + AdminPutGameJSONBodyStateWaitingStart AdminPutGameJSONBodyState = "waiting_start" ) // Game defines model for Game. @@ -207,35 +207,35 @@ type User struct { Username string `json:"username"` } -// GetAdminGamesParams defines parameters for GetAdminGames. -type GetAdminGamesParams struct { +// AdminGetGamesParams defines parameters for AdminGetGames. +type AdminGetGamesParams struct { Authorization string `json:"Authorization"` } -// GetAdminGamesGameIdParams defines parameters for GetAdminGamesGameId. -type GetAdminGamesGameIdParams struct { +// AdminGetGameParams defines parameters for AdminGetGame. +type AdminGetGameParams struct { Authorization string `json:"Authorization"` } -// PutAdminGamesGameIdJSONBody defines parameters for PutAdminGamesGameId. -type PutAdminGamesGameIdJSONBody struct { - DisplayName *string `json:"display_name,omitempty"` - DurationSeconds *int `json:"duration_seconds,omitempty"` - ProblemId nullable.Nullable[int] `json:"problem_id,omitempty"` - StartedAt nullable.Nullable[int] `json:"started_at,omitempty"` - State *PutAdminGamesGameIdJSONBodyState `json:"state,omitempty"` +// AdminPutGameJSONBody defines parameters for AdminPutGame. +type AdminPutGameJSONBody struct { + DisplayName *string `json:"display_name,omitempty"` + DurationSeconds *int `json:"duration_seconds,omitempty"` + ProblemId nullable.Nullable[int] `json:"problem_id,omitempty"` + StartedAt nullable.Nullable[int] `json:"started_at,omitempty"` + State *AdminPutGameJSONBodyState `json:"state,omitempty"` } -// PutAdminGamesGameIdParams defines parameters for PutAdminGamesGameId. -type PutAdminGamesGameIdParams struct { +// AdminPutGameParams defines parameters for AdminPutGame. +type AdminPutGameParams struct { Authorization string `json:"Authorization"` } -// PutAdminGamesGameIdJSONBodyState defines parameters for PutAdminGamesGameId. -type PutAdminGamesGameIdJSONBodyState string +// AdminPutGameJSONBodyState defines parameters for AdminPutGame. +type AdminPutGameJSONBodyState string -// GetAdminUsersParams defines parameters for GetAdminUsers. -type GetAdminUsersParams struct { +// AdminGetUsersParams defines parameters for AdminGetUsers. +type AdminGetUsersParams struct { Authorization string `json:"Authorization"` } @@ -245,8 +245,8 @@ type GetGamesParams struct { Authorization string `json:"Authorization"` } -// GetGamesGameIdParams defines parameters for GetGamesGameId. -type GetGamesGameIdParams struct { +// GetGameParams defines parameters for GetGame. +type GetGameParams struct { Authorization string `json:"Authorization"` } @@ -261,8 +261,8 @@ type GetTokenParams struct { Authorization string `json:"Authorization"` } -// PutAdminGamesGameIdJSONRequestBody defines body for PutAdminGamesGameId for application/json ContentType. -type PutAdminGamesGameIdJSONRequestBody PutAdminGamesGameIdJSONBody +// AdminPutGameJSONRequestBody defines body for AdminPutGame for application/json ContentType. +type AdminPutGameJSONRequestBody AdminPutGameJSONBody // PostLoginJSONRequestBody defines body for PostLogin for application/json ContentType. type PostLoginJSONRequestBody PostLoginJSONBody @@ -633,22 +633,22 @@ func (t *GameWatcherMessageS2C) UnmarshalJSON(b []byte) error { type ServerInterface interface { // List games // (GET /admin/games) - GetAdminGames(ctx echo.Context, params GetAdminGamesParams) error + AdminGetGames(ctx echo.Context, params AdminGetGamesParams) error // Get a game // (GET /admin/games/{game_id}) - GetAdminGamesGameId(ctx echo.Context, gameId int, params GetAdminGamesGameIdParams) error + AdminGetGame(ctx echo.Context, gameId int, params AdminGetGameParams) error // Update a game // (PUT /admin/games/{game_id}) - PutAdminGamesGameId(ctx echo.Context, gameId int, params PutAdminGamesGameIdParams) error + AdminPutGame(ctx echo.Context, gameId int, params AdminPutGameParams) error // List all users // (GET /admin/users) - GetAdminUsers(ctx echo.Context, params GetAdminUsersParams) error + AdminGetUsers(ctx echo.Context, params AdminGetUsersParams) error // List games // (GET /games) GetGames(ctx echo.Context, params GetGamesParams) error // Get a game // (GET /games/{game_id}) - GetGamesGameId(ctx echo.Context, gameId int, params GetGamesGameIdParams) error + GetGame(ctx echo.Context, gameId int, params GetGameParams) error // User login // (POST /login) PostLogin(ctx echo.Context) error @@ -662,12 +662,12 @@ type ServerInterfaceWrapper struct { Handler ServerInterface } -// GetAdminGames converts echo context to params. -func (w *ServerInterfaceWrapper) GetAdminGames(ctx echo.Context) error { +// AdminGetGames converts echo context to params. +func (w *ServerInterfaceWrapper) AdminGetGames(ctx echo.Context) error { var err error // Parameter object where we will unmarshal all parameters from the context - var params GetAdminGamesParams + var params AdminGetGamesParams headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- @@ -689,12 +689,12 @@ func (w *ServerInterfaceWrapper) GetAdminGames(ctx echo.Context) error { } // Invoke the callback with all the unmarshaled arguments - err = w.Handler.GetAdminGames(ctx, params) + err = w.Handler.AdminGetGames(ctx, params) return err } -// GetAdminGamesGameId converts echo context to params. -func (w *ServerInterfaceWrapper) GetAdminGamesGameId(ctx echo.Context) error { +// AdminGetGame converts echo context to params. +func (w *ServerInterfaceWrapper) AdminGetGame(ctx echo.Context) error { var err error // ------------- Path parameter "game_id" ------------- var gameId int @@ -705,7 +705,7 @@ func (w *ServerInterfaceWrapper) GetAdminGamesGameId(ctx echo.Context) error { } // Parameter object where we will unmarshal all parameters from the context - var params GetAdminGamesGameIdParams + var params AdminGetGameParams headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- @@ -727,12 +727,12 @@ func (w *ServerInterfaceWrapper) GetAdminGamesGameId(ctx echo.Context) error { } // Invoke the callback with all the unmarshaled arguments - err = w.Handler.GetAdminGamesGameId(ctx, gameId, params) + err = w.Handler.AdminGetGame(ctx, gameId, params) return err } -// PutAdminGamesGameId converts echo context to params. -func (w *ServerInterfaceWrapper) PutAdminGamesGameId(ctx echo.Context) error { +// AdminPutGame converts echo context to params. +func (w *ServerInterfaceWrapper) AdminPutGame(ctx echo.Context) error { var err error // ------------- Path parameter "game_id" ------------- var gameId int @@ -743,7 +743,7 @@ func (w *ServerInterfaceWrapper) PutAdminGamesGameId(ctx echo.Context) error { } // Parameter object where we will unmarshal all parameters from the context - var params PutAdminGamesGameIdParams + var params AdminPutGameParams headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- @@ -765,16 +765,16 @@ func (w *ServerInterfaceWrapper) PutAdminGamesGameId(ctx echo.Context) error { } // Invoke the callback with all the unmarshaled arguments - err = w.Handler.PutAdminGamesGameId(ctx, gameId, params) + err = w.Handler.AdminPutGame(ctx, gameId, params) return err } -// GetAdminUsers converts echo context to params. -func (w *ServerInterfaceWrapper) GetAdminUsers(ctx echo.Context) error { +// AdminGetUsers converts echo context to params. +func (w *ServerInterfaceWrapper) AdminGetUsers(ctx echo.Context) error { var err error // Parameter object where we will unmarshal all parameters from the context - var params GetAdminUsersParams + var params AdminGetUsersParams headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- @@ -796,7 +796,7 @@ func (w *ServerInterfaceWrapper) GetAdminUsers(ctx echo.Context) error { } // Invoke the callback with all the unmarshaled arguments - err = w.Handler.GetAdminUsers(ctx, params) + err = w.Handler.AdminGetUsers(ctx, params) return err } @@ -837,8 +837,8 @@ func (w *ServerInterfaceWrapper) GetGames(ctx echo.Context) error { return err } -// GetGamesGameId converts echo context to params. -func (w *ServerInterfaceWrapper) GetGamesGameId(ctx echo.Context) error { +// GetGame converts echo context to params. +func (w *ServerInterfaceWrapper) GetGame(ctx echo.Context) error { var err error // ------------- Path parameter "game_id" ------------- var gameId int @@ -849,7 +849,7 @@ func (w *ServerInterfaceWrapper) GetGamesGameId(ctx echo.Context) error { } // Parameter object where we will unmarshal all parameters from the context - var params GetGamesGameIdParams + var params GetGameParams headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- @@ -871,7 +871,7 @@ func (w *ServerInterfaceWrapper) GetGamesGameId(ctx echo.Context) error { } // Invoke the callback with all the unmarshaled arguments - err = w.Handler.GetGamesGameId(ctx, gameId, params) + err = w.Handler.GetGame(ctx, gameId, params) return err } @@ -943,208 +943,208 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL Handler: si, } - router.GET(baseURL+"/admin/games", wrapper.GetAdminGames) - router.GET(baseURL+"/admin/games/:game_id", wrapper.GetAdminGamesGameId) - router.PUT(baseURL+"/admin/games/:game_id", wrapper.PutAdminGamesGameId) - router.GET(baseURL+"/admin/users", wrapper.GetAdminUsers) + router.GET(baseURL+"/admin/games", wrapper.AdminGetGames) + router.GET(baseURL+"/admin/games/:game_id", wrapper.AdminGetGame) + router.PUT(baseURL+"/admin/games/:game_id", wrapper.AdminPutGame) + router.GET(baseURL+"/admin/users", wrapper.AdminGetUsers) router.GET(baseURL+"/games", wrapper.GetGames) - router.GET(baseURL+"/games/:game_id", wrapper.GetGamesGameId) + router.GET(baseURL+"/games/:game_id", wrapper.GetGame) router.POST(baseURL+"/login", wrapper.PostLogin) router.GET(baseURL+"/token", wrapper.GetToken) } -type GetAdminGamesRequestObject struct { - Params GetAdminGamesParams +type AdminGetGamesRequestObject struct { + Params AdminGetGamesParams } -type GetAdminGamesResponseObject interface { - VisitGetAdminGamesResponse(w http.ResponseWriter) error +type AdminGetGamesResponseObject interface { + VisitAdminGetGamesResponse(w http.ResponseWriter) error } -type GetAdminGames200JSONResponse struct { +type AdminGetGames200JSONResponse struct { Games []Game `json:"games"` } -func (response GetAdminGames200JSONResponse) VisitGetAdminGamesResponse(w http.ResponseWriter) error { +func (response AdminGetGames200JSONResponse) VisitAdminGetGamesResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(200) return json.NewEncoder(w).Encode(response) } -type GetAdminGames401JSONResponse struct { +type AdminGetGames401JSONResponse struct { Message string `json:"message"` } -func (response GetAdminGames401JSONResponse) VisitGetAdminGamesResponse(w http.ResponseWriter) error { +func (response AdminGetGames401JSONResponse) VisitAdminGetGamesResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } -type GetAdminGames403JSONResponse struct { +type AdminGetGames403JSONResponse struct { Message string `json:"message"` } -func (response GetAdminGames403JSONResponse) VisitGetAdminGamesResponse(w http.ResponseWriter) error { +func (response AdminGetGames403JSONResponse) VisitAdminGetGamesResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(403) return json.NewEncoder(w).Encode(response) } -type GetAdminGamesGameIdRequestObject struct { +type AdminGetGameRequestObject struct { GameId int `json:"game_id"` - Params GetAdminGamesGameIdParams + Params AdminGetGameParams } -type GetAdminGamesGameIdResponseObject interface { - VisitGetAdminGamesGameIdResponse(w http.ResponseWriter) error +type AdminGetGameResponseObject interface { + VisitAdminGetGameResponse(w http.ResponseWriter) error } -type GetAdminGamesGameId200JSONResponse struct { +type AdminGetGame200JSONResponse struct { Game Game `json:"game"` } -func (response GetAdminGamesGameId200JSONResponse) VisitGetAdminGamesGameIdResponse(w http.ResponseWriter) error { +func (response AdminGetGame200JSONResponse) VisitAdminGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(200) return json.NewEncoder(w).Encode(response) } -type GetAdminGamesGameId401JSONResponse struct { +type AdminGetGame401JSONResponse struct { Message string `json:"message"` } -func (response GetAdminGamesGameId401JSONResponse) VisitGetAdminGamesGameIdResponse(w http.ResponseWriter) error { +func (response AdminGetGame401JSONResponse) VisitAdminGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } -type GetAdminGamesGameId403JSONResponse struct { +type AdminGetGame403JSONResponse struct { Message string `json:"message"` } -func (response GetAdminGamesGameId403JSONResponse) VisitGetAdminGamesGameIdResponse(w http.ResponseWriter) error { +func (response AdminGetGame403JSONResponse) VisitAdminGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(403) return json.NewEncoder(w).Encode(response) } -type GetAdminGamesGameId404JSONResponse struct { +type AdminGetGame404JSONResponse struct { Message string `json:"message"` } -func (response GetAdminGamesGameId404JSONResponse) VisitGetAdminGamesGameIdResponse(w http.ResponseWriter) error { +func (response AdminGetGame404JSONResponse) VisitAdminGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(404) return json.NewEncoder(w).Encode(response) } -type PutAdminGamesGameIdRequestObject struct { +type AdminPutGameRequestObject struct { GameId int `json:"game_id"` - Params PutAdminGamesGameIdParams - Body *PutAdminGamesGameIdJSONRequestBody + Params AdminPutGameParams + Body *AdminPutGameJSONRequestBody } -type PutAdminGamesGameIdResponseObject interface { - VisitPutAdminGamesGameIdResponse(w http.ResponseWriter) error +type AdminPutGameResponseObject interface { + VisitAdminPutGameResponse(w http.ResponseWriter) error } -type PutAdminGamesGameId204Response struct { +type AdminPutGame204Response struct { } -func (response PutAdminGamesGameId204Response) VisitPutAdminGamesGameIdResponse(w http.ResponseWriter) error { +func (response AdminPutGame204Response) VisitAdminPutGameResponse(w http.ResponseWriter) error { w.WriteHeader(204) return nil } -type PutAdminGamesGameId400JSONResponse struct { +type AdminPutGame400JSONResponse struct { Message string `json:"message"` } -func (response PutAdminGamesGameId400JSONResponse) VisitPutAdminGamesGameIdResponse(w http.ResponseWriter) error { +func (response AdminPutGame400JSONResponse) VisitAdminPutGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(400) return json.NewEncoder(w).Encode(response) } -type PutAdminGamesGameId401JSONResponse struct { +type AdminPutGame401JSONResponse struct { Message string `json:"message"` } -func (response PutAdminGamesGameId401JSONResponse) VisitPutAdminGamesGameIdResponse(w http.ResponseWriter) error { +func (response AdminPutGame401JSONResponse) VisitAdminPutGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } -type PutAdminGamesGameId403JSONResponse struct { +type AdminPutGame403JSONResponse struct { Message string `json:"message"` } -func (response PutAdminGamesGameId403JSONResponse) VisitPutAdminGamesGameIdResponse(w http.ResponseWriter) error { +func (response AdminPutGame403JSONResponse) VisitAdminPutGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(403) return json.NewEncoder(w).Encode(response) } -type PutAdminGamesGameId404JSONResponse struct { +type AdminPutGame404JSONResponse struct { Message string `json:"message"` } -func (response PutAdminGamesGameId404JSONResponse) VisitPutAdminGamesGameIdResponse(w http.ResponseWriter) error { +func (response AdminPutGame404JSONResponse) VisitAdminPutGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(404) return json.NewEncoder(w).Encode(response) } -type GetAdminUsersRequestObject struct { - Params GetAdminUsersParams +type AdminGetUsersRequestObject struct { + Params AdminGetUsersParams } -type GetAdminUsersResponseObject interface { - VisitGetAdminUsersResponse(w http.ResponseWriter) error +type AdminGetUsersResponseObject interface { + VisitAdminGetUsersResponse(w http.ResponseWriter) error } -type GetAdminUsers200JSONResponse struct { +type AdminGetUsers200JSONResponse struct { Users []User `json:"users"` } -func (response GetAdminUsers200JSONResponse) VisitGetAdminUsersResponse(w http.ResponseWriter) error { +func (response AdminGetUsers200JSONResponse) VisitAdminGetUsersResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(200) return json.NewEncoder(w).Encode(response) } -type GetAdminUsers401JSONResponse struct { +type AdminGetUsers401JSONResponse struct { Message string `json:"message"` } -func (response GetAdminUsers401JSONResponse) VisitGetAdminUsersResponse(w http.ResponseWriter) error { +func (response AdminGetUsers401JSONResponse) VisitAdminGetUsersResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } -type GetAdminUsers403JSONResponse struct { +type AdminGetUsers403JSONResponse struct { Message string `json:"message"` } -func (response GetAdminUsers403JSONResponse) VisitGetAdminUsersResponse(w http.ResponseWriter) error { +func (response AdminGetUsers403JSONResponse) VisitAdminGetUsersResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(403) @@ -1192,53 +1192,53 @@ func (response GetGames403JSONResponse) VisitGetGamesResponse(w http.ResponseWri return json.NewEncoder(w).Encode(response) } -type GetGamesGameIdRequestObject struct { +type GetGameRequestObject struct { GameId int `json:"game_id"` - Params GetGamesGameIdParams + Params GetGameParams } -type GetGamesGameIdResponseObject interface { - VisitGetGamesGameIdResponse(w http.ResponseWriter) error +type GetGameResponseObject interface { + VisitGetGameResponse(w http.ResponseWriter) error } -type GetGamesGameId200JSONResponse struct { +type GetGame200JSONResponse struct { Game Game `json:"game"` } -func (response GetGamesGameId200JSONResponse) VisitGetGamesGameIdResponse(w http.ResponseWriter) error { +func (response GetGame200JSONResponse) VisitGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(200) return json.NewEncoder(w).Encode(response) } -type GetGamesGameId401JSONResponse struct { +type GetGame401JSONResponse struct { Message string `json:"message"` } -func (response GetGamesGameId401JSONResponse) VisitGetGamesGameIdResponse(w http.ResponseWriter) error { +func (response GetGame401JSONResponse) VisitGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } -type GetGamesGameId403JSONResponse struct { +type GetGame403JSONResponse struct { Message string `json:"message"` } -func (response GetGamesGameId403JSONResponse) VisitGetGamesGameIdResponse(w http.ResponseWriter) error { +func (response GetGame403JSONResponse) VisitGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(403) return json.NewEncoder(w).Encode(response) } -type GetGamesGameId404JSONResponse struct { +type GetGame404JSONResponse struct { Message string `json:"message"` } -func (response GetGamesGameId404JSONResponse) VisitGetGamesGameIdResponse(w http.ResponseWriter) error { +func (response GetGame404JSONResponse) VisitGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(404) @@ -1309,22 +1309,22 @@ func (response GetToken401JSONResponse) VisitGetTokenResponse(w http.ResponseWri type StrictServerInterface interface { // List games // (GET /admin/games) - GetAdminGames(ctx context.Context, request GetAdminGamesRequestObject) (GetAdminGamesResponseObject, error) + AdminGetGames(ctx context.Context, request AdminGetGamesRequestObject) (AdminGetGamesResponseObject, error) // Get a game // (GET /admin/games/{game_id}) - GetAdminGamesGameId(ctx context.Context, request GetAdminGamesGameIdRequestObject) (GetAdminGamesGameIdResponseObject, error) + AdminGetGame(ctx context.Context, request AdminGetGameRequestObject) (AdminGetGameResponseObject, error) // Update a game // (PUT /admin/games/{game_id}) - PutAdminGamesGameId(ctx context.Context, request PutAdminGamesGameIdRequestObject) (PutAdminGamesGameIdResponseObject, error) + AdminPutGame(ctx context.Context, request AdminPutGameRequestObject) (AdminPutGameResponseObject, error) // List all users // (GET /admin/users) - GetAdminUsers(ctx context.Context, request GetAdminUsersRequestObject) (GetAdminUsersResponseObject, error) + AdminGetUsers(ctx context.Context, request AdminGetUsersRequestObject) (AdminGetUsersResponseObject, error) // List games // (GET /games) GetGames(ctx context.Context, request GetGamesRequestObject) (GetGamesResponseObject, error) // Get a game // (GET /games/{game_id}) - GetGamesGameId(ctx context.Context, request GetGamesGameIdRequestObject) (GetGamesGameIdResponseObject, error) + GetGame(ctx context.Context, request GetGameRequestObject) (GetGameResponseObject, error) // User login // (POST /login) PostLogin(ctx context.Context, request PostLoginRequestObject) (PostLoginResponseObject, error) @@ -1345,108 +1345,108 @@ type strictHandler struct { middlewares []StrictMiddlewareFunc } -// GetAdminGames operation middleware -func (sh *strictHandler) GetAdminGames(ctx echo.Context, params GetAdminGamesParams) error { - var request GetAdminGamesRequestObject +// AdminGetGames operation middleware +func (sh *strictHandler) AdminGetGames(ctx echo.Context, params AdminGetGamesParams) error { + var request AdminGetGamesRequestObject request.Params = params handler := func(ctx echo.Context, request interface{}) (interface{}, error) { - return sh.ssi.GetAdminGames(ctx.Request().Context(), request.(GetAdminGamesRequestObject)) + return sh.ssi.AdminGetGames(ctx.Request().Context(), request.(AdminGetGamesRequestObject)) } for _, middleware := range sh.middlewares { - handler = middleware(handler, "GetAdminGames") + handler = middleware(handler, "AdminGetGames") } response, err := handler(ctx, request) if err != nil { return err - } else if validResponse, ok := response.(GetAdminGamesResponseObject); ok { - return validResponse.VisitGetAdminGamesResponse(ctx.Response()) + } else if validResponse, ok := response.(AdminGetGamesResponseObject); ok { + return validResponse.VisitAdminGetGamesResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } return nil } -// GetAdminGamesGameId operation middleware -func (sh *strictHandler) GetAdminGamesGameId(ctx echo.Context, gameId int, params GetAdminGamesGameIdParams) error { - var request GetAdminGamesGameIdRequestObject +// AdminGetGame operation middleware +func (sh *strictHandler) AdminGetGame(ctx echo.Context, gameId int, params AdminGetGameParams) error { + var request AdminGetGameRequestObject request.GameId = gameId request.Params = params handler := func(ctx echo.Context, request interface{}) (interface{}, error) { - return sh.ssi.GetAdminGamesGameId(ctx.Request().Context(), request.(GetAdminGamesGameIdRequestObject)) + return sh.ssi.AdminGetGame(ctx.Request().Context(), request.(AdminGetGameRequestObject)) } for _, middleware := range sh.middlewares { - handler = middleware(handler, "GetAdminGamesGameId") + handler = middleware(handler, "AdminGetGame") } response, err := handler(ctx, request) if err != nil { return err - } else if validResponse, ok := response.(GetAdminGamesGameIdResponseObject); ok { - return validResponse.VisitGetAdminGamesGameIdResponse(ctx.Response()) + } else if validResponse, ok := response.(AdminGetGameResponseObject); ok { + return validResponse.VisitAdminGetGameResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } return nil } -// PutAdminGamesGameId operation middleware -func (sh *strictHandler) PutAdminGamesGameId(ctx echo.Context, gameId int, params PutAdminGamesGameIdParams) error { - var request PutAdminGamesGameIdRequestObject +// AdminPutGame operation middleware +func (sh *strictHandler) AdminPutGame(ctx echo.Context, gameId int, params AdminPutGameParams) error { + var request AdminPutGameRequestObject request.GameId = gameId request.Params = params - var body PutAdminGamesGameIdJSONRequestBody + var body AdminPutGameJSONRequestBody if err := ctx.Bind(&body); err != nil { return err } request.Body = &body handler := func(ctx echo.Context, request interface{}) (interface{}, error) { - return sh.ssi.PutAdminGamesGameId(ctx.Request().Context(), request.(PutAdminGamesGameIdRequestObject)) + return sh.ssi.AdminPutGame(ctx.Request().Context(), request.(AdminPutGameRequestObject)) } for _, middleware := range sh.middlewares { - handler = middleware(handler, "PutAdminGamesGameId") + handler = middleware(handler, "AdminPutGame") } response, err := handler(ctx, request) if err != nil { return err - } else if validResponse, ok := response.(PutAdminGamesGameIdResponseObject); ok { - return validResponse.VisitPutAdminGamesGameIdResponse(ctx.Response()) + } else if validResponse, ok := response.(AdminPutGameResponseObject); ok { + return validResponse.VisitAdminPutGameResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } return nil } -// GetAdminUsers operation middleware -func (sh *strictHandler) GetAdminUsers(ctx echo.Context, params GetAdminUsersParams) error { - var request GetAdminUsersRequestObject +// AdminGetUsers operation middleware +func (sh *strictHandler) AdminGetUsers(ctx echo.Context, params AdminGetUsersParams) error { + var request AdminGetUsersRequestObject request.Params = params handler := func(ctx echo.Context, request interface{}) (interface{}, error) { - return sh.ssi.GetAdminUsers(ctx.Request().Context(), request.(GetAdminUsersRequestObject)) + return sh.ssi.AdminGetUsers(ctx.Request().Context(), request.(AdminGetUsersRequestObject)) } for _, middleware := range sh.middlewares { - handler = middleware(handler, "GetAdminUsers") + handler = middleware(handler, "AdminGetUsers") } response, err := handler(ctx, request) if err != nil { return err - } else if validResponse, ok := response.(GetAdminUsersResponseObject); ok { - return validResponse.VisitGetAdminUsersResponse(ctx.Response()) + } else if validResponse, ok := response.(AdminGetUsersResponseObject); ok { + return validResponse.VisitAdminGetUsersResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } @@ -1478,26 +1478,26 @@ func (sh *strictHandler) GetGames(ctx echo.Context, params GetGamesParams) error return nil } -// GetGamesGameId operation middleware -func (sh *strictHandler) GetGamesGameId(ctx echo.Context, gameId int, params GetGamesGameIdParams) error { - var request GetGamesGameIdRequestObject +// GetGame operation middleware +func (sh *strictHandler) GetGame(ctx echo.Context, gameId int, params GetGameParams) error { + var request GetGameRequestObject request.GameId = gameId request.Params = params handler := func(ctx echo.Context, request interface{}) (interface{}, error) { - return sh.ssi.GetGamesGameId(ctx.Request().Context(), request.(GetGamesGameIdRequestObject)) + return sh.ssi.GetGame(ctx.Request().Context(), request.(GetGameRequestObject)) } for _, middleware := range sh.middlewares { - handler = middleware(handler, "GetGamesGameId") + handler = middleware(handler, "GetGame") } response, err := handler(ctx, request) if err != nil { return err - } else if validResponse, ok := response.(GetGamesGameIdResponseObject); ok { - return validResponse.VisitGetGamesGameIdResponse(ctx.Response()) + } else if validResponse, ok := response.(GetGameResponseObject); ok { + return validResponse.VisitGetGameResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } @@ -1561,32 +1561,32 @@ func (sh *strictHandler) GetToken(ctx echo.Context, params GetTokenParams) error // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/+xZbW/bNhD+Kxo3oBugxS8Jis7fsqzLMnSb0TTYhyIwaOlsM6NIlaSaeIX/+0BSL5ZF", - "W7Sjps3gfkgTiXd67uU58o6fUMSTlDNgSqLRJySjBSTY/HqJE9D/p4KnIBQB8zQmMqV4OWH5W3jASUoB", - "jcz6YIBCpJap/lsqQdgcrUIUZwIrwtlEQsRZLGtypy/7pQhhCuYgtMwcJzAhcW3pwLUwFXxKIdELvxMw", - "QyP0ba+yqZcb1Bvny1YhkgoLBfEEq5r2n85evnx19qrvhCMVVtZeliVo9B5FlEuIUYjuMVGEzSfAlNA+", - "qp6Y7yCNEFIsAOVf1k4x9tlfZoQRuYAY3YZrzizVbzhzFSIBHzIiINYoCi8VAMN6fByuvy1V8ukdREob", - "pyM3pngJ4g+QEs+NoZzBXzM0er/brQ3R6+EFWoV7Cl0Mr9Hq1oVEvzkczMXw+jVTYnkQoreA48MkL3gM", - "2+0xb5u8wgq35fA2bWO8pBzHOpQ2tprVTCo0QqlZPoqGchTp77YllHkbWjReqbIBoWFXlFtbpXYqCFPf", - "v/gNKOVhcM8Fjb958UMrMqPIF5KNegPMDu+AkfByjy8Im0D7gBBGojsQmoyPovI4L117s+B6eHFtyt8h", - "kq8fIHoLMq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WJVV", + "Z9g3a1+xD5iSOCgyrlfubuo+1vxjzX9Mzb8xTKjKft3j6Rmse9C5Maue1qBTWeY16JiBvWvQsSr3GXSs", + "xJG9X9WggyktA6OJsHvW7xjz32dgbuuL5HfOJJ/2LHM8JDhyZ+chge/xwPFk4HgycOwSn9rJgGY45Qt7", + "d5By2ULsCZfqtVnS19idYinvuYg3bqeLp6ejs7a5+5F3EaysTcWnbw8aRR9THxT/BzauwB70v5O1/7tv", + "BY0Sn+g7I7JmIDCloZYkPP1Ug3IkINbfwlR+kmG5jGbARVCFc2MOkiACm9YmwyvXb9u53poFT2vy+b/n", + "02fakFpKo1xyoX6k5APEATZWB9ZPeZ7n/wUAAP//whfwDcIwAAA=", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/backend/api/handlers.go b/backend/api/handlers.go index c96cd2a..a250629 100644 --- a/backend/api/handlers.go +++ b/backend/api/handlers.go @@ -33,10 +33,10 @@ func NewHandler(queries *db.Queries, hubs GameHubsInterface) *ApiHandler { } } -func (h *ApiHandler) GetAdminGames(ctx context.Context, request GetAdminGamesRequestObject) (GetAdminGamesResponseObject, error) { +func (h *ApiHandler) AdminGetGames(ctx context.Context, request AdminGetGamesRequestObject) (AdminGetGamesResponseObject, error) { user := ctx.Value("user").(*auth.JWTClaims) if !user.IsAdmin { - return GetAdminGames403JSONResponse{ + return AdminGetGames403JSONResponse{ Message: "Forbidden", }, nil } @@ -71,15 +71,15 @@ func (h *ApiHandler) GetAdminGames(ctx context.Context, request GetAdminGamesReq Problem: problem, } } - return GetAdminGames200JSONResponse{ + return AdminGetGames200JSONResponse{ Games: games, }, nil } -func (h *ApiHandler) GetAdminGamesGameId(ctx context.Context, request GetAdminGamesGameIdRequestObject) (GetAdminGamesGameIdResponseObject, error) { +func (h *ApiHandler) AdminGetGame(ctx context.Context, request AdminGetGameRequestObject) (AdminGetGameResponseObject, error) { user := ctx.Value("user").(*auth.JWTClaims) if !user.IsAdmin { - return GetAdminGamesGameId403JSONResponse{ + return AdminGetGame403JSONResponse{ Message: "Forbidden", }, nil } @@ -87,7 +87,7 @@ func (h *ApiHandler) GetAdminGamesGameId(ctx context.Context, request GetAdminGa row, err := h.q.GetGameById(ctx, int32(gameId)) if err != nil { if errors.Is(err, pgx.ErrNoRows) { - return GetAdminGamesGameId404JSONResponse{ + return AdminGetGame404JSONResponse{ Message: "Game not found", }, nil } else { @@ -118,15 +118,15 @@ func (h *ApiHandler) GetAdminGamesGameId(ctx context.Context, request GetAdminGa StartedAt: startedAt, Problem: problem, } - return GetAdminGamesGameId200JSONResponse{ + return AdminGetGame200JSONResponse{ Game: game, }, nil } -func (h *ApiHandler) PutAdminGamesGameId(ctx context.Context, request PutAdminGamesGameIdRequestObject) (PutAdminGamesGameIdResponseObject, error) { +func (h *ApiHandler) AdminPutGame(ctx context.Context, request AdminPutGameRequestObject) (AdminPutGameResponseObject, error) { user := ctx.Value("user").(*auth.JWTClaims) if !user.IsAdmin { - return PutAdminGamesGameId403JSONResponse{ + return AdminPutGame403JSONResponse{ Message: "Forbidden", }, nil } @@ -140,7 +140,7 @@ func (h *ApiHandler) PutAdminGamesGameId(ctx context.Context, request PutAdminGa game, err := h.q.GetGameById(ctx, int32(gameID)) if err != nil { if err == pgx.ErrNoRows { - return PutAdminGamesGameId404JSONResponse{ + return AdminPutGame404JSONResponse{ Message: "Game not found", }, nil } else { @@ -202,18 +202,18 @@ func (h *ApiHandler) PutAdminGamesGameId(ctx context.Context, request PutAdminGa ProblemID: changedProblemID, }) if err != nil { - return PutAdminGamesGameId400JSONResponse{ + return AdminPutGame400JSONResponse{ Message: err.Error(), }, nil } - return PutAdminGamesGameId204Response{}, nil + return AdminPutGame204Response{}, nil } -func (h *ApiHandler) GetAdminUsers(ctx context.Context, request GetAdminUsersRequestObject) (GetAdminUsersResponseObject, error) { +func (h *ApiHandler) AdminGetUsers(ctx context.Context, request AdminGetUsersRequestObject) (AdminGetUsersResponseObject, error) { user := ctx.Value("user").(*auth.JWTClaims) if !user.IsAdmin { - return GetAdminUsers403JSONResponse{ + return AdminGetUsers403JSONResponse{ Message: "Forbidden", }, nil } @@ -231,7 +231,7 @@ func (h *ApiHandler) GetAdminUsers(ctx context.Context, request GetAdminUsersReq IsAdmin: u.IsAdmin, } } - return GetAdminUsers200JSONResponse{ + return AdminGetUsers200JSONResponse{ Users: responseUsers, }, nil } @@ -357,14 +357,14 @@ func (h *ApiHandler) GetGames(ctx context.Context, request GetGamesRequestObject } } -func (h *ApiHandler) GetGamesGameId(ctx context.Context, request GetGamesGameIdRequestObject) (GetGamesGameIdResponseObject, error) { +func (h *ApiHandler) GetGame(ctx context.Context, request GetGameRequestObject) (GetGameResponseObject, error) { user := ctx.Value("user").(*auth.JWTClaims) // TODO: check user permission gameId := request.GameId row, err := h.q.GetGameById(ctx, int32(gameId)) if err != nil { if errors.Is(err, pgx.ErrNoRows) { - return GetGamesGameId404JSONResponse{ + return GetGame404JSONResponse{ Message: "Game not found", }, nil } else { @@ -397,7 +397,7 @@ func (h *ApiHandler) GetGamesGameId(ctx context.Context, request GetGamesGameIdR StartedAt: startedAt, Problem: problem, } - return GetGamesGameId200JSONResponse{ + return GetGame200JSONResponse{ Game: game, }, nil } diff --git a/frontend/app/.server/api/schema.d.ts b/frontend/app/.server/api/schema.d.ts index abe2b59..3ef97ab 100644 --- a/frontend/app/.server/api/schema.d.ts +++ b/frontend/app/.server/api/schema.d.ts @@ -14,50 +14,7 @@ export interface paths { get?: never; put?: never; /** User login */ - post: { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; - }; - requestBody: { - content: { - "application/json": { - /** @example john */ - username: string; - /** @example password123 */ - password: string; - }; - }; - }; - responses: { - /** @description Successfully authenticated */ - 200: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example xxxxx.xxxxx.xxxxx */ - token: string; - }; - }; - }; - /** @description Invalid username or password */ - 401: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Invalid credentials */ - message: string; - }; - }; - }; - }; - }; + post: operations["postLogin"]; delete?: never; options?: never; head?: never; @@ -72,43 +29,7 @@ export interface paths { cookie?: never; }; /** Get a short-lived access token */ - get: { - parameters: { - query?: never; - header: { - Authorization: string; - }; - path?: never; - cookie?: never; - }; - requestBody?: never; - responses: { - /** @description Successfully authenticated */ - 200: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example xxxxx.xxxxx.xxxxx */ - token: string; - }; - }; - }; - /** @description Unauthorized */ - 401: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Unauthorized */ - message: string; - }; - }; - }; - }; - }; + get: operations["getToken"]; put?: never; post?: never; delete?: never; @@ -125,56 +46,7 @@ export interface paths { cookie?: never; }; /** List games */ - get: { - parameters: { - query?: { - player_id?: number; - }; - header: { - Authorization: string; - }; - path?: never; - cookie?: never; - }; - requestBody?: never; - responses: { - /** @description List of games */ - 200: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - games: components["schemas"]["Game"][]; - }; - }; - }; - /** @description Unauthorized */ - 401: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Unauthorized */ - message: string; - }; - }; - }; - /** @description Forbidden */ - 403: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Forbidden operation */ - message: string; - }; - }; - }; - }; - }; + get: operations["getGames"]; put?: never; post?: never; delete?: never; @@ -191,68 +63,7 @@ export interface paths { cookie?: never; }; /** Get a game */ - get: { - parameters: { - query?: never; - header: { - Authorization: string; - }; - path: { - game_id: number; - }; - cookie?: never; - }; - requestBody?: never; - responses: { - /** @description A game */ - 200: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - game: components["schemas"]["Game"]; - }; - }; - }; - /** @description Unauthorized */ - 401: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Unauthorized */ - message: string; - }; - }; - }; - /** @description Forbidden */ - 403: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Forbidden operation */ - message: string; - }; - }; - }; - /** @description Not found */ - 404: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Not found */ - message: string; - }; - }; - }; - }; - }; + get: operations["getGame"]; put?: never; post?: never; delete?: never; @@ -269,54 +80,7 @@ export interface paths { cookie?: never; }; /** List all users */ - get: { - parameters: { - query?: never; - header: { - Authorization: string; - }; - path?: never; - cookie?: never; - }; - requestBody?: never; - responses: { - /** @description List of users */ - 200: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - users: components["schemas"]["User"][]; - }; - }; - }; - /** @description Unauthorized */ - 401: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Unauthorized */ - message: string; - }; - }; - }; - /** @description Forbidden */ - 403: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Forbidden operation */ - message: string; - }; - }; - }; - }; - }; + get: operations["adminGetUsers"]; put?: never; post?: never; delete?: never; @@ -333,54 +97,7 @@ export interface paths { cookie?: never; }; /** List games */ - get: { - parameters: { - query?: never; - header: { - Authorization: string; - }; - path?: never; - cookie?: never; - }; - requestBody?: never; - responses: { - /** @description List of games */ - 200: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - games: components["schemas"]["Game"][]; - }; - }; - }; - /** @description Unauthorized */ - 401: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Unauthorized */ - message: string; - }; - }; - }; - /** @description Forbidden */ - 403: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Forbidden operation */ - message: string; - }; - }; - }; - }; - }; + get: operations["adminGetGames"]; put?: never; post?: never; delete?: never; @@ -397,157 +114,9 @@ export interface paths { cookie?: never; }; /** Get a game */ - get: { - parameters: { - query?: never; - header: { - Authorization: string; - }; - path: { - game_id: number; - }; - cookie?: never; - }; - requestBody?: never; - responses: { - /** @description A game */ - 200: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - game: components["schemas"]["Game"]; - }; - }; - }; - /** @description Unauthorized */ - 401: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Unauthorized */ - message: string; - }; - }; - }; - /** @description Forbidden */ - 403: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Forbidden operation */ - message: string; - }; - }; - }; - /** @description Not found */ - 404: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Not found */ - message: string; - }; - }; - }; - }; - }; + get: operations["adminGetGame"]; /** Update a game */ - put: { - parameters: { - query?: never; - header: { - Authorization: string; - }; - path: { - game_id: number; - }; - cookie?: never; - }; - requestBody: { - content: { - "application/json": { - /** - * @example closed - * @enum {string} - */ - state?: "closed" | "waiting_entries" | "waiting_start" | "prepare" | "starting" | "gaming" | "finished"; - /** @example Game 1 */ - display_name?: string; - /** @example 360 */ - duration_seconds?: number; - /** @example 946684800 */ - started_at?: number | null; - /** @example 1 */ - problem_id?: number | null; - }; - }; - }; - responses: { - /** @description Successfully updated */ - 204: { - headers: { - [name: string]: unknown; - }; - content?: never; - }; - /** @description Invalid request */ - 400: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Invalid request */ - message: string; - }; - }; - }; - /** @description Unauthorized */ - 401: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Unauthorized */ - message: string; - }; - }; - }; - /** @description Forbidden */ - 403: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Forbidden operation */ - message: string; - }; - }; - }; - /** @description Not found */ - 404: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Not found */ - message: string; - }; - }; - }; - }; - }; + put: operations["adminPutGame"]; post?: never; delete?: never; options?: never; @@ -696,4 +265,444 @@ export interface components { pathItems: never; } export type $defs = Record; -export type operations = Record; +export interface operations { + postLogin: { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + requestBody: { + content: { + "application/json": { + /** @example john */ + username: string; + /** @example password123 */ + password: string; + }; + }; + }; + responses: { + /** @description Successfully authenticated */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + /** @example xxxxx.xxxxx.xxxxx */ + token: string; + }; + }; + }; + /** @description Invalid username or password */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + /** @example Invalid credentials */ + message: string; + }; + }; + }; + }; + }; + getToken: { + parameters: { + query?: never; + header: { + Authorization: string; + }; + path?: never; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description Successfully authenticated */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + /** @example xxxxx.xxxxx.xxxxx */ + token: string; + }; + }; + }; + /** @description Unauthorized */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + /** @example Unauthorized */ + message: string; + }; + }; + }; + }; + }; + getGames: { + parameters: { + query?: { + player_id?: number; + }; + header: { + Authorization: string; + }; + path?: never; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description List of games */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + games: components["schemas"]["Game"][]; + }; + }; + }; + /** @description Unauthorized */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + /** @example Unauthorized */ + message: string; + }; + }; + }; + /** @description Forbidden */ + 403: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + /** @example Forbidden operation */ + message: string; + }; + }; + }; + }; + }; + getGame: { + parameters: { + query?: never; + header: { + Authorization: string; + }; + path: { + game_id: number; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description A game */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + game: components["schemas"]["Game"]; + }; + }; + }; + /** @description Unauthorized */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + /** @example Unauthorized */ + message: string; + }; + }; + }; + /** @description Forbidden */ + 403: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + /** @example Forbidden operation */ + message: string; + }; + }; + }; + /** @description Not found */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + /** @example Not found */ + message: string; + }; + }; + }; + }; + }; + adminGetUsers: { + parameters: { + query?: never; + header: { + Authorization: string; + }; + path?: never; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description List of users */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + users: components["schemas"]["User"][]; + }; + }; + }; + /** @description Unauthorized */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + /** @example Unauthorized */ + message: string; + }; + }; + }; + /** @description Forbidden */ + 403: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + /** @example Forbidden operation */ + message: string; + }; + }; + }; + }; + }; + adminGetGames: { + parameters: { + query?: never; + header: { + Authorization: string; + }; + path?: never; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description List of games */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + games: components["schemas"]["Game"][]; + }; + }; + }; + /** @description Unauthorized */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + /** @example Unauthorized */ + message: string; + }; + }; + }; + /** @description Forbidden */ + 403: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + /** @example Forbidden operation */ + message: string; + }; + }; + }; + }; + }; + adminGetGame: { + parameters: { + query?: never; + header: { + Authorization: string; + }; + path: { + game_id: number; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description A game */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + game: components["schemas"]["Game"]; + }; + }; + }; + /** @description Unauthorized */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + /** @example Unauthorized */ + message: string; + }; + }; + }; + /** @description Forbidden */ + 403: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + /** @example Forbidden operation */ + message: string; + }; + }; + }; + /** @description Not found */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + /** @example Not found */ + message: string; + }; + }; + }; + }; + }; + adminPutGame: { + parameters: { + query?: never; + header: { + Authorization: string; + }; + path: { + game_id: number; + }; + cookie?: never; + }; + requestBody: { + content: { + "application/json": { + /** + * @example closed + * @enum {string} + */ + state?: "closed" | "waiting_entries" | "waiting_start" | "prepare" | "starting" | "gaming" | "finished"; + /** @example Game 1 */ + display_name?: string; + /** @example 360 */ + duration_seconds?: number; + /** @example 946684800 */ + started_at?: number | null; + /** @example 1 */ + problem_id?: number | null; + }; + }; + }; + responses: { + /** @description Successfully updated */ + 204: { + headers: { + [name: string]: unknown; + }; + content?: never; + }; + /** @description Invalid request */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + /** @example Invalid request */ + message: string; + }; + }; + }; + /** @description Unauthorized */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + /** @example Unauthorized */ + message: string; + }; + }; + }; + /** @description Forbidden */ + 403: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + /** @example Forbidden operation */ + message: string; + }; + }; + }; + /** @description Not found */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + /** @example Not found */ + message: string; + }; + }; + }; + }; + }; +} diff --git a/openapi.yaml b/openapi.yaml index a19a673..fe1e4fa 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -5,6 +5,7 @@ info: paths: /login: post: + operationId: postLogin summary: User login requestBody: required: true @@ -49,6 +50,7 @@ paths: - message /token: get: + operationId: getToken summary: Get a short-lived access token parameters: - in: header @@ -83,6 +85,7 @@ paths: - message /games: get: + operationId: getGames summary: List games parameters: - in: query @@ -135,6 +138,7 @@ paths: - message /games/{game_id}: get: + operationId: getGame summary: Get a game parameters: - in: path @@ -197,6 +201,7 @@ paths: - message /admin/users: get: + operationId: adminGetUsers summary: List all users parameters: - in: header @@ -244,6 +249,7 @@ paths: - message /admin/games: get: + operationId: adminGetGames summary: List games parameters: - in: header @@ -291,6 +297,7 @@ paths: - message /admin/games/{game_id}: get: + operationId: adminGetGame summary: Get a game parameters: - in: path @@ -352,6 +359,7 @@ paths: required: - message put: + operationId: adminPutGame summary: Update a game parameters: - in: path -- cgit v1.2.3-70-g09d2 From 72012983718a8d1f1d850e24e9af3a29fb20374a Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 1 Aug 2024 21:09:36 +0900 Subject: refactor: remove `player_id` parameter from `/api/games` --- backend/api/generated.go | 59 ++++++++++----------- backend/api/handlers.go | 99 ++++++++++-------------------------- frontend/app/.server/api/schema.d.ts | 4 +- frontend/app/routes/dashboard.tsx | 3 -- openapi.yaml | 5 -- 5 files changed, 54 insertions(+), 116 deletions(-) (limited to 'backend/api/generated.go') diff --git a/backend/api/generated.go b/backend/api/generated.go index fe693f8..6de100a 100644 --- a/backend/api/generated.go +++ b/backend/api/generated.go @@ -241,7 +241,6 @@ type AdminGetUsersParams struct { // GetGamesParams defines parameters for GetGames. type GetGamesParams struct { - PlayerId *int `form:"player_id,omitempty" json:"player_id,omitempty"` Authorization string `json:"Authorization"` } @@ -806,12 +805,6 @@ func (w *ServerInterfaceWrapper) GetGames(ctx echo.Context) error { // Parameter object where we will unmarshal all parameters from the context var params GetGamesParams - // ------------- Optional query parameter "player_id" ------------- - - err = runtime.BindQueryParameter("form", true, false, "player_id", ctx.QueryParams(), ¶ms.PlayerId) - if err != nil { - return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter player_id: %s", err)) - } headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- @@ -1561,32 +1554,32 @@ func (sh *strictHandler) GetToken(ctx echo.Context, params GetTokenParams) error // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/+xZbW/bNhD+Kxo3oBugxY4TFJ2/ZVmXdeg2o2mwD0Vg0NLZZkaRKkk18Qr994GkXkxL", - "tmhHfcngfmgSiXd67uU53pEfUcSTlDNgSqLxRySjJSTY/HqFE9A/U8FTEIqAeRoTmVK8mrLiLTzgJKWA", - "xmZ9cIpCpFap/lsqQdgC5SGKM4EV4WwqIeIslo7c2fNhJUKYggUILbPACUxJ7Cw9bVuYCj6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DIYWOorm+", + "ehXr/fSaa1DXZpWWFjgBBUKa3kj7Gy0AxyBQiKyb0GWmFlyQf40WtOoSW4ttEanH8tp9d3qxTDmTFtKw", + "3y8KiAJm0OE0pSQymnv30tKp1tfMwcoyoiCRPiWtrloIC4GXzrs/uSFUDZKj10SqgM8CK5GH6KI/OMKW", + "pO556yS8Zbhwtce1ZanBB3xDscF+3jX2X7mYkjgGFlQJ16kJlX6jRWZJgsWyjEsRlDxskKD3sbjazb3o", + "sIENpnxVXKgvi3eyYOXIeQLE8qOTgz5e0bs0ITrR5kvSRuO/6Br/n1wFM56xbh1fa22S/RpUgKtUSrNN", + "jB5nT5PR7zOQ6mdub7wPDNPn+ri4uYv1mtV2fD30m/e+kq+JjnxuBj5vleuL1hiBbuxkOssoXQZZGmNV", + "Vp1+16x9xT5gSuKgyLhOubuu+1TzTzX/mJp/a5hQlf26x9Mz2O5B59aselqDTmWZ16BjBvZdg45Vuc+g", + "YyVO7P2qBh1MaRkYTYTts/5pzD+N+d/qmO874J9m+9Nsf+rzntpsrxlO+dze/qdcOog95lK9Nku6GpxT", + "LOUDF/Ha9+Xi6WB47pqcj/yawMraVGx9d9AweUx9UPwfWPuI9aj/na38v/u7nlHiE/3GkKsZCExpqCUJ", + "B59q1I0ExHovTOUnGXfLaAZcBFU41yYZCSKwaW0yvHL9ppPrrVnwtLq3bz2fPtOB5CiNcsGF+pGSDxAH", + "2FgdWD/leZ7/FwAA///GgvoRhDAAAA==", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/backend/api/handlers.go b/backend/api/handlers.go index ea9ddea..164682d 100644 --- a/backend/api/handlers.go +++ b/backend/api/handlers.go @@ -240,85 +240,40 @@ func (h *ApiHandler) GetToken(ctx context.Context, request GetTokenRequestObject } func (h *ApiHandler) GetGames(ctx context.Context, request GetGamesRequestObject, user *auth.JWTClaims) (GetGamesResponseObject, error) { - playerId := request.Params.PlayerId - if !user.IsAdmin { - if playerId == nil || *playerId != user.UserID { - return GetGames403JSONResponse{ - Message: "Forbidden", - }, nil - } + gameRows, err := h.q.ListGamesForPlayer(ctx, int32(user.UserID)) + if err != nil { + return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error()) } - if playerId == nil { - gameRows, err := h.q.ListGames(ctx) - if err != nil { - return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error()) + games := make([]Game, len(gameRows)) + for i, row := range gameRows { + var startedAt *int + if row.StartedAt.Valid { + startedAtTimestamp := int(row.StartedAt.Time.Unix()) + startedAt = &startedAtTimestamp } - games := make([]Game, len(gameRows)) - for i, row := range gameRows { - var startedAt *int - if row.StartedAt.Valid { - startedAtTimestamp := int(row.StartedAt.Time.Unix()) - startedAt = &startedAtTimestamp - } - var problem *Problem - if row.ProblemID != nil { - if row.Title == nil || row.Description == nil { - panic("inconsistent data") - } - problem = &Problem{ - ProblemId: int(*row.ProblemID), - Title: *row.Title, - Description: *row.Description, - } + var problem *Problem + if row.ProblemID != nil { + if row.Title == nil || row.Description == nil { + panic("inconsistent data") } - games[i] = Game{ - GameId: int(row.GameID), - State: GameState(row.State), - DisplayName: row.DisplayName, - DurationSeconds: int(row.DurationSeconds), - StartedAt: startedAt, - Problem: problem, + problem = &Problem{ + ProblemId: int(*row.ProblemID), + Title: *row.Title, + Description: *row.Description, } } - return GetGames200JSONResponse{ - Games: games, - }, nil - } else { - gameRows, err := h.q.ListGamesForPlayer(ctx, int32(*playerId)) - if err != nil { - return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error()) - } - games := make([]Game, len(gameRows)) - for i, row := range gameRows { - var startedAt *int - if row.StartedAt.Valid { - startedAtTimestamp := int(row.StartedAt.Time.Unix()) - startedAt = &startedAtTimestamp - } - var problem *Problem - if row.ProblemID != nil { - if row.Title == nil || row.Description == nil { - panic("inconsistent data") - } - problem = &Problem{ - ProblemId: int(*row.ProblemID), - Title: *row.Title, - Description: *row.Description, - } - } - games[i] = Game{ - GameId: int(row.GameID), - State: GameState(row.State), - DisplayName: row.DisplayName, - DurationSeconds: int(row.DurationSeconds), - StartedAt: startedAt, - Problem: problem, - } + games[i] = Game{ + GameId: int(row.GameID), + State: GameState(row.State), + DisplayName: row.DisplayName, + DurationSeconds: int(row.DurationSeconds), + StartedAt: startedAt, + Problem: problem, } - return GetGames200JSONResponse{ - Games: games, - }, nil } + return GetGames200JSONResponse{ + Games: games, + }, nil } func (h *ApiHandler) GetGame(ctx context.Context, request GetGameRequestObject, user *auth.JWTClaims) (GetGameResponseObject, error) { diff --git a/frontend/app/.server/api/schema.d.ts b/frontend/app/.server/api/schema.d.ts index 3ef97ab..1adfc86 100644 --- a/frontend/app/.server/api/schema.d.ts +++ b/frontend/app/.server/api/schema.d.ts @@ -349,9 +349,7 @@ export interface operations { }; getGames: { parameters: { - query?: { - player_id?: number; - }; + query?: never; header: { Authorization: string; }; diff --git a/frontend/app/routes/dashboard.tsx b/frontend/app/routes/dashboard.tsx index 3cc8e13..08780f9 100644 --- a/frontend/app/routes/dashboard.tsx +++ b/frontend/app/routes/dashboard.tsx @@ -17,9 +17,6 @@ export async function loader({ request }: LoaderFunctionArgs) { } const { data, error } = await apiClient.GET("/games", { params: { - query: { - player_id: user.user_id, - }, header: { Authorization: `Bearer ${token}`, }, diff --git a/openapi.yaml b/openapi.yaml index fe1e4fa..637ea3d 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -88,11 +88,6 @@ paths: operationId: getGames summary: List games parameters: - - in: query - name: player_id - schema: - type: integer - required: false - in: header name: Authorization schema: -- cgit v1.2.3-70-g09d2 From ebb1129ae9ef16139a32bf899d42009176642299 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 1 Aug 2024 21:10:42 +0900 Subject: refactor: simplify parameter definitions in OpenAPI spec --- backend/api/generated.go | 110 ++++++++++++++++++----------------- backend/api/handlers.go | 12 ++-- frontend/app/.server/api/schema.d.ts | 25 ++++---- openapi.yaml | 73 ++++++++--------------- 4 files changed, 101 insertions(+), 119 deletions(-) (limited to 'backend/api/generated.go') diff --git a/backend/api/generated.go b/backend/api/generated.go index 6de100a..47dd905 100644 --- a/backend/api/generated.go +++ b/backend/api/generated.go @@ -207,14 +207,20 @@ type User struct { Username string `json:"username"` } +// HeaderAuthorization defines model for header_authorization. +type HeaderAuthorization = string + +// PathGameId defines model for path_game_id. +type PathGameId = int + // AdminGetGamesParams defines parameters for AdminGetGames. type AdminGetGamesParams struct { - Authorization string `json:"Authorization"` + Authorization HeaderAuthorization `json:"Authorization"` } // AdminGetGameParams defines parameters for AdminGetGame. type AdminGetGameParams struct { - Authorization string `json:"Authorization"` + Authorization HeaderAuthorization `json:"Authorization"` } // AdminPutGameJSONBody defines parameters for AdminPutGame. @@ -228,7 +234,7 @@ type AdminPutGameJSONBody struct { // AdminPutGameParams defines parameters for AdminPutGame. type AdminPutGameParams struct { - Authorization string `json:"Authorization"` + Authorization HeaderAuthorization `json:"Authorization"` } // AdminPutGameJSONBodyState defines parameters for AdminPutGame. @@ -236,17 +242,17 @@ type AdminPutGameJSONBodyState string // AdminGetUsersParams defines parameters for AdminGetUsers. type AdminGetUsersParams struct { - Authorization string `json:"Authorization"` + Authorization HeaderAuthorization `json:"Authorization"` } // GetGamesParams defines parameters for GetGames. type GetGamesParams struct { - Authorization string `json:"Authorization"` + Authorization HeaderAuthorization `json:"Authorization"` } // GetGameParams defines parameters for GetGame. type GetGameParams struct { - Authorization string `json:"Authorization"` + Authorization HeaderAuthorization `json:"Authorization"` } // PostLoginJSONBody defines parameters for PostLogin. @@ -257,7 +263,7 @@ type PostLoginJSONBody struct { // GetTokenParams defines parameters for GetToken. type GetTokenParams struct { - Authorization string `json:"Authorization"` + Authorization HeaderAuthorization `json:"Authorization"` } // AdminPutGameJSONRequestBody defines body for AdminPutGame for application/json ContentType. @@ -635,10 +641,10 @@ type ServerInterface interface { AdminGetGames(ctx echo.Context, params AdminGetGamesParams) error // Get a game // (GET /admin/games/{game_id}) - AdminGetGame(ctx echo.Context, gameId int, params AdminGetGameParams) error + AdminGetGame(ctx echo.Context, gameId PathGameId, params AdminGetGameParams) error // Update a game // (PUT /admin/games/{game_id}) - AdminPutGame(ctx echo.Context, gameId int, params AdminPutGameParams) error + AdminPutGame(ctx echo.Context, gameId PathGameId, params AdminPutGameParams) error // List all users // (GET /admin/users) AdminGetUsers(ctx echo.Context, params AdminGetUsersParams) error @@ -647,7 +653,7 @@ type ServerInterface interface { GetGames(ctx echo.Context, params GetGamesParams) error // Get a game // (GET /games/{game_id}) - GetGame(ctx echo.Context, gameId int, params GetGameParams) error + GetGame(ctx echo.Context, gameId PathGameId, params GetGameParams) error // User login // (POST /login) PostLogin(ctx echo.Context) error @@ -671,7 +677,7 @@ func (w *ServerInterfaceWrapper) AdminGetGames(ctx echo.Context) error { headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { - var Authorization string + var Authorization HeaderAuthorization n := len(valueList) if n != 1 { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) @@ -696,7 +702,7 @@ func (w *ServerInterfaceWrapper) AdminGetGames(ctx echo.Context) error { func (w *ServerInterfaceWrapper) AdminGetGame(ctx echo.Context) error { var err error // ------------- Path parameter "game_id" ------------- - var gameId int + var gameId PathGameId err = runtime.BindStyledParameterWithOptions("simple", "game_id", ctx.Param("game_id"), &gameId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { @@ -709,7 +715,7 @@ func (w *ServerInterfaceWrapper) AdminGetGame(ctx echo.Context) error { headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { - var Authorization string + var Authorization HeaderAuthorization n := len(valueList) if n != 1 { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) @@ -734,7 +740,7 @@ func (w *ServerInterfaceWrapper) AdminGetGame(ctx echo.Context) error { func (w *ServerInterfaceWrapper) AdminPutGame(ctx echo.Context) error { var err error // ------------- Path parameter "game_id" ------------- - var gameId int + var gameId PathGameId err = runtime.BindStyledParameterWithOptions("simple", "game_id", ctx.Param("game_id"), &gameId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { @@ -747,7 +753,7 @@ func (w *ServerInterfaceWrapper) AdminPutGame(ctx echo.Context) error { headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { - var Authorization string + var Authorization HeaderAuthorization n := len(valueList) if n != 1 { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) @@ -778,7 +784,7 @@ func (w *ServerInterfaceWrapper) AdminGetUsers(ctx echo.Context) error { headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { - var Authorization string + var Authorization HeaderAuthorization n := len(valueList) if n != 1 { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) @@ -809,7 +815,7 @@ func (w *ServerInterfaceWrapper) GetGames(ctx echo.Context) error { headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { - var Authorization string + var Authorization HeaderAuthorization n := len(valueList) if n != 1 { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) @@ -834,7 +840,7 @@ func (w *ServerInterfaceWrapper) GetGames(ctx echo.Context) error { func (w *ServerInterfaceWrapper) GetGame(ctx echo.Context) error { var err error // ------------- Path parameter "game_id" ------------- - var gameId int + var gameId PathGameId err = runtime.BindStyledParameterWithOptions("simple", "game_id", ctx.Param("game_id"), &gameId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { @@ -847,7 +853,7 @@ func (w *ServerInterfaceWrapper) GetGame(ctx echo.Context) error { headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { - var Authorization string + var Authorization HeaderAuthorization n := len(valueList) if n != 1 { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) @@ -887,7 +893,7 @@ func (w *ServerInterfaceWrapper) GetToken(ctx echo.Context) error { headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { - var Authorization string + var Authorization HeaderAuthorization n := len(valueList) if n != 1 { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) @@ -989,7 +995,7 @@ func (response AdminGetGames403JSONResponse) VisitAdminGetGamesResponse(w http.R } type AdminGetGameRequestObject struct { - GameId int `json:"game_id"` + GameId PathGameId `json:"game_id"` Params AdminGetGameParams } @@ -1042,7 +1048,7 @@ func (response AdminGetGame404JSONResponse) VisitAdminGetGameResponse(w http.Res } type AdminPutGameRequestObject struct { - GameId int `json:"game_id"` + GameId PathGameId `json:"game_id"` Params AdminPutGameParams Body *AdminPutGameJSONRequestBody } @@ -1186,7 +1192,7 @@ func (response GetGames403JSONResponse) VisitGetGamesResponse(w http.ResponseWri } type GetGameRequestObject struct { - GameId int `json:"game_id"` + GameId PathGameId `json:"game_id"` Params GetGameParams } @@ -1364,7 +1370,7 @@ func (sh *strictHandler) AdminGetGames(ctx echo.Context, params AdminGetGamesPar } // AdminGetGame operation middleware -func (sh *strictHandler) AdminGetGame(ctx echo.Context, gameId int, params AdminGetGameParams) error { +func (sh *strictHandler) AdminGetGame(ctx echo.Context, gameId PathGameId, params AdminGetGameParams) error { var request AdminGetGameRequestObject request.GameId = gameId @@ -1390,7 +1396,7 @@ func (sh *strictHandler) AdminGetGame(ctx echo.Context, gameId int, params Admin } // AdminPutGame operation middleware -func (sh *strictHandler) AdminPutGame(ctx echo.Context, gameId int, params AdminPutGameParams) error { +func (sh *strictHandler) AdminPutGame(ctx echo.Context, gameId PathGameId, params AdminPutGameParams) error { var request AdminPutGameRequestObject request.GameId = gameId @@ -1472,7 +1478,7 @@ func (sh *strictHandler) GetGames(ctx echo.Context, params GetGamesParams) error } // GetGame operation middleware -func (sh *strictHandler) GetGame(ctx echo.Context, gameId int, params GetGameParams) error { +func (sh *strictHandler) GetGame(ctx echo.Context, gameId PathGameId, params GetGameParams) error { var request GetGameRequestObject request.GameId = gameId @@ -1554,32 +1560,32 @@ func (sh *strictHandler) GetToken(ctx echo.Context, params GetTokenParams) error // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/+xZa2/bNhf+K3r5DugGaPElQdH5W5Z1WYduM5oG+1AEBi0d28woUiWpJl6h/z6Q1MWy", - "aJu21UsK90OTSDyHz7k8h+dQH1HEk5QzYEqi0UckowUk2Px6jRPQP1PBUxCKgHkaE5lSvJyw4i084iSl", - "gEZmfTBAIVLLVP8tlSBsjvIQxZnAinA2kRBxFsuG3PnzfiVCmII5CC0zxwlMSNxYOnAtTAWfUkj0wu8E", - "zNAI/b9X29QrDOqNi2V5iKTCQkE8waqh/aeL589fXLzoO+FIhZW1l2UJGr1DEeUSYhSiB0wUYfMJMCW0", - "j+onZh+kEUKKBaBiZ+0UY5/9ZUYYkQuI0V244sxK/Zoz8xAJeJ8RAbFGUXqpBBg24+Nw/V2lkk/vIVLa", - "OB25McVLEH+AlHhuDOUM/pqh0bvtbm2J3gyvUB7uKXQ1vEH5nQuJfnM4mKvhzUumxPIgRG8Ax4dJXvEY", - "Nttj3rZ5hRXelcObtI3xknIc61Da2GpWM6nQCKVm+SgaylGk992VUOZtaNF4pcoahJZdUWFtndqpIEx9", - "/+w3oJSHwQMXNP7fsx92IjOKfCHZqLfAbPEOGAkv9/iCsAm0DwhhJLoDocl4FJXHRenamwU3w6sbU/4O", - "kXz5CNEbkBlVG1jUXNMNlxo6dzNKDqMRPEIkLIbOe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bvx5Tva5MJ", + "VQWvOy89/+weMq4N1UscMir8XkOGGYl3DRlW5D5DhuU45uiLGjIwpaVjdLhvn6aPg/RxkP53D9K+I/Rx", + "ej5Oz8f26xmnZ52slM/thXjKpSNHx1yq94akq3k2xVLecRGvPbkWXwfDU9dA+8gLdlaWmWLrm4NmvMfU", + "B8X/grV3nXv972Tl/91PXUaIj/cbs6fOQGBKQy2TcPC1JtBIQKz3wlR+lSm09GbARVC5c23AkCACG9Ym", + "wivTbzqEPhqCl9hu/dej5omOHUcBlAsu1PeUfIE4wEbrwNopz/P8nwAAAP//7jff808wAAA=", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/backend/api/handlers.go b/backend/api/handlers.go index 164682d..26f7a7d 100644 --- a/backend/api/handlers.go +++ b/backend/api/handlers.go @@ -61,8 +61,8 @@ func (h *ApiHandler) AdminGetGames(ctx context.Context, request AdminGetGamesReq } func (h *ApiHandler) AdminGetGame(ctx context.Context, request AdminGetGameRequestObject, user *auth.JWTClaims) (AdminGetGameResponseObject, error) { - gameId := request.GameId - row, err := h.q.GetGameById(ctx, int32(gameId)) + gameID := request.GameId + row, err := h.q.GetGameById(ctx, int32(gameID)) if err != nil { if errors.Is(err, pgx.ErrNoRows) { return AdminGetGame404JSONResponse{ @@ -205,14 +205,14 @@ func (h *ApiHandler) AdminGetUsers(ctx context.Context, request AdminGetUsersReq func (h *ApiHandler) PostLogin(ctx context.Context, request PostLoginRequestObject) (PostLoginResponseObject, error) { username := request.Body.Username password := request.Body.Password - userId, err := auth.Login(ctx, h.q, username, password) + userID, err := auth.Login(ctx, h.q, username, password) if err != nil { return PostLogin401JSONResponse{ Message: "Invalid username or password", }, nil } - user, err := h.q.GetUserById(ctx, int32(userId)) + user, err := h.q.GetUserById(ctx, int32(userID)) if err != nil { return PostLogin401JSONResponse{ Message: "Invalid username or password", @@ -278,8 +278,8 @@ func (h *ApiHandler) GetGames(ctx context.Context, request GetGamesRequestObject func (h *ApiHandler) GetGame(ctx context.Context, request GetGameRequestObject, user *auth.JWTClaims) (GetGameResponseObject, error) { // TODO: check user permission - gameId := request.GameId - row, err := h.q.GetGameById(ctx, int32(gameId)) + gameID := request.GameId + row, err := h.q.GetGameById(ctx, int32(gameID)) if err != nil { if errors.Is(err, pgx.ErrNoRows) { return GetGame404JSONResponse{ diff --git a/frontend/app/.server/api/schema.d.ts b/frontend/app/.server/api/schema.d.ts index 1adfc86..37e9b8c 100644 --- a/frontend/app/.server/api/schema.d.ts +++ b/frontend/app/.server/api/schema.d.ts @@ -259,7 +259,10 @@ export interface components { }; }; responses: never; - parameters: never; + parameters: { + header_authorization: string; + path_game_id: number; + }; requestBodies: never; headers: never; pathItems: never; @@ -314,7 +317,7 @@ export interface operations { parameters: { query?: never; header: { - Authorization: string; + Authorization: components["parameters"]["header_authorization"]; }; path?: never; cookie?: never; @@ -351,7 +354,7 @@ export interface operations { parameters: { query?: never; header: { - Authorization: string; + Authorization: components["parameters"]["header_authorization"]; }; path?: never; cookie?: never; @@ -399,10 +402,10 @@ export interface operations { parameters: { query?: never; header: { - Authorization: string; + Authorization: components["parameters"]["header_authorization"]; }; path: { - game_id: number; + game_id: components["parameters"]["path_game_id"]; }; cookie?: never; }; @@ -461,7 +464,7 @@ export interface operations { parameters: { query?: never; header: { - Authorization: string; + Authorization: components["parameters"]["header_authorization"]; }; path?: never; cookie?: never; @@ -509,7 +512,7 @@ export interface operations { parameters: { query?: never; header: { - Authorization: string; + Authorization: components["parameters"]["header_authorization"]; }; path?: never; cookie?: never; @@ -557,10 +560,10 @@ export interface operations { parameters: { query?: never; header: { - Authorization: string; + Authorization: components["parameters"]["header_authorization"]; }; path: { - game_id: number; + game_id: components["parameters"]["path_game_id"]; }; cookie?: never; }; @@ -619,10 +622,10 @@ export interface operations { parameters: { query?: never; header: { - Authorization: string; + Authorization: components["parameters"]["header_authorization"]; }; path: { - game_id: number; + game_id: components["parameters"]["path_game_id"]; }; cookie?: never; }; diff --git a/openapi.yaml b/openapi.yaml index 637ea3d..1dd4614 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -53,11 +53,7 @@ paths: operationId: getToken summary: Get a short-lived access token parameters: - - in: header - name: Authorization - schema: - type: string - required: true + - $ref: '#/components/parameters/header_authorization' responses: '200': description: Successfully authenticated @@ -88,11 +84,7 @@ paths: operationId: getGames summary: List games parameters: - - in: header - name: Authorization - schema: - type: string - required: true + - $ref: '#/components/parameters/header_authorization' responses: '200': description: List of games @@ -136,16 +128,8 @@ paths: operationId: getGame summary: Get a game parameters: - - in: path - name: game_id - schema: - type: integer - required: true - - in: header - name: Authorization - schema: - type: string - required: true + - $ref: '#/components/parameters/header_authorization' + - $ref: '#/components/parameters/path_game_id' responses: '200': description: A game @@ -199,11 +183,7 @@ paths: operationId: adminGetUsers summary: List all users parameters: - - in: header - name: Authorization - schema: - type: string - required: true + - $ref: '#/components/parameters/header_authorization' responses: '200': description: List of users @@ -247,11 +227,7 @@ paths: operationId: adminGetGames summary: List games parameters: - - in: header - name: Authorization - schema: - type: string - required: true + - $ref: '#/components/parameters/header_authorization' responses: '200': description: List of games @@ -295,16 +271,8 @@ paths: operationId: adminGetGame summary: Get a game parameters: - - in: path - name: game_id - schema: - type: integer - required: true - - in: header - name: Authorization - schema: - type: string - required: true + - $ref: '#/components/parameters/header_authorization' + - $ref: '#/components/parameters/path_game_id' responses: '200': description: A game @@ -357,16 +325,8 @@ paths: operationId: adminPutGame summary: Update a game parameters: - - in: path - name: game_id - schema: - type: integer - required: true - - in: header - name: Authorization - schema: - type: string - required: true + - $ref: '#/components/parameters/header_authorization' + - $ref: '#/components/parameters/path_game_id' requestBody: required: true content: @@ -451,6 +411,19 @@ paths: required: - message components: + parameters: + header_authorization: + in: header + name: Authorization + schema: + type: string + required: true + path_game_id: + in: path + name: game_id + schema: + type: integer + required: true schemas: User: type: object -- cgit v1.2.3-70-g09d2 From d4b76effa883fc191b82027e7d76d1f34fcc2992 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 1 Aug 2024 21:11:12 +0900 Subject: refactor: simplify error responses in OpenAPI spec --- backend/api/generated.go | 149 ++++++++---------- backend/api/handler_wrapper.go | 44 ++++-- backend/api/handlers.go | 24 ++- backend/gen/api_handler_wrapper_gen.go | 8 +- frontend/app/.server/api/schema.d.ts | 277 +++++++-------------------------- openapi.yaml | 249 ++++++----------------------- 6 files changed, 237 insertions(+), 514 deletions(-) (limited to 'backend/api/generated.go') diff --git a/backend/api/generated.go b/backend/api/generated.go index 47dd905..a643833 100644 --- a/backend/api/generated.go +++ b/backend/api/generated.go @@ -54,6 +54,11 @@ const ( AdminPutGameJSONBodyStateWaitingStart AdminPutGameJSONBodyState = "waiting_start" ) +// Error defines model for Error. +type Error struct { + Message string `json:"message"` +} + // Game defines model for Game. type Game struct { DisplayName string `json:"display_name"` @@ -213,6 +218,18 @@ type HeaderAuthorization = string // PathGameId defines model for path_game_id. type PathGameId = int +// BadRequest defines model for BadRequest. +type BadRequest = Error + +// Forbidden defines model for Forbidden. +type Forbidden = Error + +// NotFound defines model for NotFound. +type NotFound = Error + +// Unauthorized defines model for Unauthorized. +type Unauthorized = Error + // AdminGetGamesParams defines parameters for AdminGetGames. type AdminGetGamesParams struct { Authorization HeaderAuthorization `json:"Authorization"` @@ -953,6 +970,14 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL } +type BadRequestJSONResponse Error + +type ForbiddenJSONResponse Error + +type NotFoundJSONResponse Error + +type UnauthorizedJSONResponse Error + type AdminGetGamesRequestObject struct { Params AdminGetGamesParams } @@ -972,9 +997,7 @@ func (response AdminGetGames200JSONResponse) VisitAdminGetGamesResponse(w http.R return json.NewEncoder(w).Encode(response) } -type AdminGetGames401JSONResponse struct { - Message string `json:"message"` -} +type AdminGetGames401JSONResponse struct{ UnauthorizedJSONResponse } func (response AdminGetGames401JSONResponse) VisitAdminGetGamesResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") @@ -983,9 +1006,7 @@ func (response AdminGetGames401JSONResponse) VisitAdminGetGamesResponse(w http.R return json.NewEncoder(w).Encode(response) } -type AdminGetGames403JSONResponse struct { - Message string `json:"message"` -} +type AdminGetGames403JSONResponse struct{ ForbiddenJSONResponse } func (response AdminGetGames403JSONResponse) VisitAdminGetGamesResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") @@ -1014,9 +1035,7 @@ func (response AdminGetGame200JSONResponse) VisitAdminGetGameResponse(w http.Res return json.NewEncoder(w).Encode(response) } -type AdminGetGame401JSONResponse struct { - Message string `json:"message"` -} +type AdminGetGame401JSONResponse struct{ UnauthorizedJSONResponse } func (response AdminGetGame401JSONResponse) VisitAdminGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") @@ -1025,9 +1044,7 @@ func (response AdminGetGame401JSONResponse) VisitAdminGetGameResponse(w http.Res return json.NewEncoder(w).Encode(response) } -type AdminGetGame403JSONResponse struct { - Message string `json:"message"` -} +type AdminGetGame403JSONResponse struct{ ForbiddenJSONResponse } func (response AdminGetGame403JSONResponse) VisitAdminGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") @@ -1036,9 +1053,7 @@ func (response AdminGetGame403JSONResponse) VisitAdminGetGameResponse(w http.Res return json.NewEncoder(w).Encode(response) } -type AdminGetGame404JSONResponse struct { - Message string `json:"message"` -} +type AdminGetGame404JSONResponse struct{ NotFoundJSONResponse } func (response AdminGetGame404JSONResponse) VisitAdminGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") @@ -1065,9 +1080,7 @@ func (response AdminPutGame204Response) VisitAdminPutGameResponse(w http.Respons return nil } -type AdminPutGame400JSONResponse struct { - Message string `json:"message"` -} +type AdminPutGame400JSONResponse struct{ BadRequestJSONResponse } func (response AdminPutGame400JSONResponse) VisitAdminPutGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") @@ -1076,9 +1089,7 @@ func (response AdminPutGame400JSONResponse) VisitAdminPutGameResponse(w http.Res return json.NewEncoder(w).Encode(response) } -type AdminPutGame401JSONResponse struct { - Message string `json:"message"` -} +type AdminPutGame401JSONResponse struct{ UnauthorizedJSONResponse } func (response AdminPutGame401JSONResponse) VisitAdminPutGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") @@ -1087,9 +1098,7 @@ func (response AdminPutGame401JSONResponse) VisitAdminPutGameResponse(w http.Res return json.NewEncoder(w).Encode(response) } -type AdminPutGame403JSONResponse struct { - Message string `json:"message"` -} +type AdminPutGame403JSONResponse struct{ ForbiddenJSONResponse } func (response AdminPutGame403JSONResponse) VisitAdminPutGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") @@ -1098,9 +1107,7 @@ func (response AdminPutGame403JSONResponse) VisitAdminPutGameResponse(w http.Res return json.NewEncoder(w).Encode(response) } -type AdminPutGame404JSONResponse struct { - Message string `json:"message"` -} +type AdminPutGame404JSONResponse struct{ NotFoundJSONResponse } func (response AdminPutGame404JSONResponse) VisitAdminPutGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") @@ -1128,9 +1135,7 @@ func (response AdminGetUsers200JSONResponse) VisitAdminGetUsersResponse(w http.R return json.NewEncoder(w).Encode(response) } -type AdminGetUsers401JSONResponse struct { - Message string `json:"message"` -} +type AdminGetUsers401JSONResponse struct{ UnauthorizedJSONResponse } func (response AdminGetUsers401JSONResponse) VisitAdminGetUsersResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") @@ -1139,9 +1144,7 @@ func (response AdminGetUsers401JSONResponse) VisitAdminGetUsersResponse(w http.R return json.NewEncoder(w).Encode(response) } -type AdminGetUsers403JSONResponse struct { - Message string `json:"message"` -} +type AdminGetUsers403JSONResponse struct{ ForbiddenJSONResponse } func (response AdminGetUsers403JSONResponse) VisitAdminGetUsersResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") @@ -1169,9 +1172,7 @@ func (response GetGames200JSONResponse) VisitGetGamesResponse(w http.ResponseWri return json.NewEncoder(w).Encode(response) } -type GetGames401JSONResponse struct { - Message string `json:"message"` -} +type GetGames401JSONResponse struct{ UnauthorizedJSONResponse } func (response GetGames401JSONResponse) VisitGetGamesResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") @@ -1180,9 +1181,7 @@ func (response GetGames401JSONResponse) VisitGetGamesResponse(w http.ResponseWri return json.NewEncoder(w).Encode(response) } -type GetGames403JSONResponse struct { - Message string `json:"message"` -} +type GetGames403JSONResponse struct{ ForbiddenJSONResponse } func (response GetGames403JSONResponse) VisitGetGamesResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") @@ -1211,9 +1210,7 @@ func (response GetGame200JSONResponse) VisitGetGameResponse(w http.ResponseWrite return json.NewEncoder(w).Encode(response) } -type GetGame401JSONResponse struct { - Message string `json:"message"` -} +type GetGame401JSONResponse struct{ UnauthorizedJSONResponse } func (response GetGame401JSONResponse) VisitGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") @@ -1222,9 +1219,7 @@ func (response GetGame401JSONResponse) VisitGetGameResponse(w http.ResponseWrite return json.NewEncoder(w).Encode(response) } -type GetGame403JSONResponse struct { - Message string `json:"message"` -} +type GetGame403JSONResponse struct{ ForbiddenJSONResponse } func (response GetGame403JSONResponse) VisitGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") @@ -1233,9 +1228,7 @@ func (response GetGame403JSONResponse) VisitGetGameResponse(w http.ResponseWrite return json.NewEncoder(w).Encode(response) } -type GetGame404JSONResponse struct { - Message string `json:"message"` -} +type GetGame404JSONResponse struct{ NotFoundJSONResponse } func (response GetGame404JSONResponse) VisitGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") @@ -1263,9 +1256,7 @@ func (response PostLogin200JSONResponse) VisitPostLoginResponse(w http.ResponseW return json.NewEncoder(w).Encode(response) } -type PostLogin401JSONResponse struct { - Message string `json:"message"` -} +type PostLogin401JSONResponse struct{ UnauthorizedJSONResponse } func (response PostLogin401JSONResponse) VisitPostLoginResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") @@ -1293,9 +1284,7 @@ func (response GetToken200JSONResponse) VisitGetTokenResponse(w http.ResponseWri return json.NewEncoder(w).Encode(response) } -type GetToken401JSONResponse struct { - Message string `json:"message"` -} +type GetToken401JSONResponse struct{ UnauthorizedJSONResponse } func (response GetToken401JSONResponse) VisitGetTokenResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") @@ -1560,32 +1549,32 @@ func (sh *strictHandler) GetToken(ctx echo.Context, params GetTokenParams) error // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/+xZbW/bthP/KvrzP6AboMUPCYrO77Ksyzp0m9E02IsiMGjpbDOjSJWkmniBvvtAUg+W", - "Rdu0oybZ4L4oYvHu+LtH3pEPKOJJyhkwJdHoAaVY4AQUCPNrATgGMcGZWnBB/saKcKa/E4ZGxSIKEcMJ", - "oBE6b1CFSMDnjAiI0UiJDEIkowUkWLOrZaoZpBKEzVGehyjFajGZ4wQmJK420B9r8eWqh2DCFMxBoFyL", - "tqtGnUsj6QGlgqcgFAHzNSYypXg5YcUq3OMkpVqOpg8GKFwHHKI4E0bNiYSIs1g2+E5f98MWlBCtqFeR", - "DlyEqeBTCokm/EbADI3Q/3u1l3qFQr1xQaZ1VFgoiCdYNaT/cPb69ZuzN30nHKmwsvqyLEGjTyiiXIK2", - "7x0mirD5BJgS2kb1F7MP0gghxQJQsbM2itHP/jEjjMgFxOgmXDFmJb7t/dqhn1bcbAGGTf84TH9TieTT", - "W4iUVk57bkzxEsRvICWeG0U5gz9maPRpu1lbrFfDC5SHezJdDK9QfuNColcOB3MxvHrLlFgehOgD4Pgw", - "zgsew2Z9zGo7r7DCu2J4k7QxXlKOY+1K61tdp5hUuioY8lE0lKNI77sroMxqaNF4hcoahJZeUaFtHdqp", - "IEx9++oXoJSHwR0XNP7fq+92IjOCfCFZr7fAbLEOGA4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yfaS7NV4drwK8WteH8mrEUe+2C9b", + "i1Z+n7Z6InRp2ux5niSrIM9iLKtsGXZzf+0N7deRlVf6gHViNte26hO6i/GV3vUYi3GN36sY69axqxgb", + "lfsUYyPx5YoxTpIKg4rs7gbrW2/1FfVWvl3Vt4bqf9FQKUokbGF+dGZMOJgwYUK+1lv6anEyLMQt4/HG", + "WLN8ejw6cfU49/wRSysyl6avDyr792GhZH/DxuzkTv0drf3vHidpJT6UtNoRRTegUkGtGLc3Te3yL4AH", + "hjiaQ/Xhtl0m7/SGx1gh/lNxMbktlozLnxPyEeIAa3OBAVgURfFvAAAA//89QklP/CgAAA==", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/backend/api/handler_wrapper.go b/backend/api/handler_wrapper.go index 37a199b..939e37a 100644 --- a/backend/api/handler_wrapper.go +++ b/backend/api/handler_wrapper.go @@ -43,12 +43,16 @@ func (h *ApiHandlerWrapper) AdminGetGame(ctx context.Context, request AdminGetGa user, err := parseJWTClaimsFromAuthorizationHeader(request.Params.Authorization) if err != nil { return AdminGetGame401JSONResponse{ - Message: "Unauthorized", + UnauthorizedJSONResponse: UnauthorizedJSONResponse{ + Message: "Unauthorized", + }, }, nil } if !user.IsAdmin { return AdminGetGame403JSONResponse{ - Message: "Forbidden", + ForbiddenJSONResponse: ForbiddenJSONResponse{ + Message: "Forbidden", + }, }, nil } return h.innerHandler.AdminGetGame(ctx, request, user) @@ -58,12 +62,16 @@ func (h *ApiHandlerWrapper) AdminGetGames(ctx context.Context, request AdminGetG user, err := parseJWTClaimsFromAuthorizationHeader(request.Params.Authorization) if err != nil { return AdminGetGames401JSONResponse{ - Message: "Unauthorized", + UnauthorizedJSONResponse: UnauthorizedJSONResponse{ + Message: "Unauthorized", + }, }, nil } if !user.IsAdmin { return AdminGetGames403JSONResponse{ - Message: "Forbidden", + ForbiddenJSONResponse: ForbiddenJSONResponse{ + Message: "Forbidden", + }, }, nil } return h.innerHandler.AdminGetGames(ctx, request, user) @@ -73,12 +81,16 @@ func (h *ApiHandlerWrapper) AdminGetUsers(ctx context.Context, request AdminGetU user, err := parseJWTClaimsFromAuthorizationHeader(request.Params.Authorization) if err != nil { return AdminGetUsers401JSONResponse{ - Message: "Unauthorized", + UnauthorizedJSONResponse: UnauthorizedJSONResponse{ + Message: "Unauthorized", + }, }, nil } if !user.IsAdmin { return AdminGetUsers403JSONResponse{ - Message: "Forbidden", + ForbiddenJSONResponse: ForbiddenJSONResponse{ + Message: "Forbidden", + }, }, nil } return h.innerHandler.AdminGetUsers(ctx, request, user) @@ -88,12 +100,16 @@ func (h *ApiHandlerWrapper) AdminPutGame(ctx context.Context, request AdminPutGa user, err := parseJWTClaimsFromAuthorizationHeader(request.Params.Authorization) if err != nil { return AdminPutGame401JSONResponse{ - Message: "Unauthorized", + UnauthorizedJSONResponse: UnauthorizedJSONResponse{ + Message: "Unauthorized", + }, }, nil } if !user.IsAdmin { return AdminPutGame403JSONResponse{ - Message: "Forbidden", + ForbiddenJSONResponse: ForbiddenJSONResponse{ + Message: "Forbidden", + }, }, nil } return h.innerHandler.AdminPutGame(ctx, request, user) @@ -103,7 +119,9 @@ func (h *ApiHandlerWrapper) GetGame(ctx context.Context, request GetGameRequestO user, err := parseJWTClaimsFromAuthorizationHeader(request.Params.Authorization) if err != nil { return GetGame401JSONResponse{ - Message: "Unauthorized", + UnauthorizedJSONResponse: UnauthorizedJSONResponse{ + Message: "Unauthorized", + }, }, nil } return h.innerHandler.GetGame(ctx, request, user) @@ -113,7 +131,9 @@ func (h *ApiHandlerWrapper) GetGames(ctx context.Context, request GetGamesReques user, err := parseJWTClaimsFromAuthorizationHeader(request.Params.Authorization) if err != nil { return GetGames401JSONResponse{ - Message: "Unauthorized", + UnauthorizedJSONResponse: UnauthorizedJSONResponse{ + Message: "Unauthorized", + }, }, nil } return h.innerHandler.GetGames(ctx, request, user) @@ -123,7 +143,9 @@ func (h *ApiHandlerWrapper) GetToken(ctx context.Context, request GetTokenReques user, err := parseJWTClaimsFromAuthorizationHeader(request.Params.Authorization) if err != nil { return GetToken401JSONResponse{ - Message: "Unauthorized", + UnauthorizedJSONResponse: UnauthorizedJSONResponse{ + Message: "Unauthorized", + }, }, nil } return h.innerHandler.GetToken(ctx, request, user) diff --git a/backend/api/handlers.go b/backend/api/handlers.go index 26f7a7d..35fc9f7 100644 --- a/backend/api/handlers.go +++ b/backend/api/handlers.go @@ -66,7 +66,9 @@ func (h *ApiHandler) AdminGetGame(ctx context.Context, request AdminGetGameReque if err != nil { if errors.Is(err, pgx.ErrNoRows) { return AdminGetGame404JSONResponse{ - Message: "Game not found", + NotFoundJSONResponse: NotFoundJSONResponse{ + Message: "Game not found", + }, }, nil } else { return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error()) @@ -113,7 +115,9 @@ func (h *ApiHandler) AdminPutGame(ctx context.Context, request AdminPutGameReque if err != nil { if err == pgx.ErrNoRows { return AdminPutGame404JSONResponse{ - Message: "Game not found", + NotFoundJSONResponse: NotFoundJSONResponse{ + Message: "Game not found", + }, }, nil } else { return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error()) @@ -175,7 +179,9 @@ func (h *ApiHandler) AdminPutGame(ctx context.Context, request AdminPutGameReque }) if err != nil { return AdminPutGame400JSONResponse{ - Message: err.Error(), + BadRequestJSONResponse: BadRequestJSONResponse{ + Message: err.Error(), + }, }, nil } @@ -208,14 +214,18 @@ func (h *ApiHandler) PostLogin(ctx context.Context, request PostLoginRequestObje userID, err := auth.Login(ctx, h.q, username, password) if err != nil { return PostLogin401JSONResponse{ - Message: "Invalid username or password", + UnauthorizedJSONResponse: UnauthorizedJSONResponse{ + Message: "Invalid username or password", + }, }, nil } user, err := h.q.GetUserById(ctx, int32(userID)) if err != nil { return PostLogin401JSONResponse{ - Message: "Invalid username or password", + UnauthorizedJSONResponse: UnauthorizedJSONResponse{ + Message: "Invalid username or password", + }, }, nil } @@ -283,7 +293,9 @@ func (h *ApiHandler) GetGame(ctx context.Context, request GetGameRequestObject, if err != nil { if errors.Is(err, pgx.ErrNoRows) { return GetGame404JSONResponse{ - Message: "Game not found", + NotFoundJSONResponse: NotFoundJSONResponse{ + Message: "Game not found", + }, }, nil } else { return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error()) diff --git a/backend/gen/api_handler_wrapper_gen.go b/backend/gen/api_handler_wrapper_gen.go index 01d05bf..7fd34b2 100644 --- a/backend/gen/api_handler_wrapper_gen.go +++ b/backend/gen/api_handler_wrapper_gen.go @@ -145,13 +145,17 @@ func parseJWTClaimsFromAuthorizationHeader(authorization string) (*auth.JWTClaim user, err := parseJWTClaimsFromAuthorizationHeader(request.Params.Authorization) if err != nil { return {{ .Name }}401JSONResponse{ - Message: "Unauthorized", + UnauthorizedJSONResponse: UnauthorizedJSONResponse{ + Message: "Unauthorized", + }, }, nil } {{ if .RequiresAdminRole -}} if !user.IsAdmin { return {{ .Name }}403JSONResponse{ - Message: "Forbidden", + ForbiddenJSONResponse: ForbiddenJSONResponse{ + Message: "Forbidden", + }, }, nil } {{ end -}} diff --git a/frontend/app/.server/api/schema.d.ts b/frontend/app/.server/api/schema.d.ts index 37e9b8c..6198064 100644 --- a/frontend/app/.server/api/schema.d.ts +++ b/frontend/app/.server/api/schema.d.ts @@ -128,6 +128,10 @@ export interface paths { export type webhooks = Record; export interface components { schemas: { + Error: { + /** @example Invalid request */ + message: string; + }; User: { /** @example 123 */ user_id: number; @@ -258,7 +262,44 @@ export interface components { stderr: string; }; }; - responses: never; + responses: { + /** @description Bad request */ + BadRequest: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": components["schemas"]["Error"]; + }; + }; + /** @description Unauthorized */ + Unauthorized: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": components["schemas"]["Error"]; + }; + }; + /** @description Forbidden */ + Forbidden: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": components["schemas"]["Error"]; + }; + }; + /** @description Not found */ + NotFound: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": components["schemas"]["Error"]; + }; + }; + }; parameters: { header_authorization: string; path_game_id: number; @@ -299,18 +340,7 @@ export interface operations { }; }; }; - /** @description Invalid username or password */ - 401: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Invalid credentials */ - message: string; - }; - }; - }; + 401: components["responses"]["Unauthorized"]; }; }; getToken: { @@ -336,18 +366,7 @@ export interface operations { }; }; }; - /** @description Unauthorized */ - 401: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Unauthorized */ - message: string; - }; - }; - }; + 401: components["responses"]["Unauthorized"]; }; }; getGames: { @@ -372,30 +391,8 @@ export interface operations { }; }; }; - /** @description Unauthorized */ - 401: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Unauthorized */ - message: string; - }; - }; - }; - /** @description Forbidden */ - 403: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Forbidden operation */ - message: string; - }; - }; - }; + 401: components["responses"]["Unauthorized"]; + 403: components["responses"]["Forbidden"]; }; }; getGame: { @@ -422,42 +419,9 @@ export interface operations { }; }; }; - /** @description Unauthorized */ - 401: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Unauthorized */ - message: string; - }; - }; - }; - /** @description Forbidden */ - 403: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Forbidden operation */ - message: string; - }; - }; - }; - /** @description Not found */ - 404: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Not found */ - message: string; - }; - }; - }; + 401: components["responses"]["Unauthorized"]; + 403: components["responses"]["Forbidden"]; + 404: components["responses"]["NotFound"]; }; }; adminGetUsers: { @@ -482,30 +446,8 @@ export interface operations { }; }; }; - /** @description Unauthorized */ - 401: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Unauthorized */ - message: string; - }; - }; - }; - /** @description Forbidden */ - 403: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Forbidden operation */ - message: string; - }; - }; - }; + 401: components["responses"]["Unauthorized"]; + 403: components["responses"]["Forbidden"]; }; }; adminGetGames: { @@ -530,30 +472,8 @@ export interface operations { }; }; }; - /** @description Unauthorized */ - 401: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Unauthorized */ - message: string; - }; - }; - }; - /** @description Forbidden */ - 403: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Forbidden operation */ - message: string; - }; - }; - }; + 401: components["responses"]["Unauthorized"]; + 403: components["responses"]["Forbidden"]; }; }; adminGetGame: { @@ -580,42 +500,9 @@ export interface operations { }; }; }; - /** @description Unauthorized */ - 401: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Unauthorized */ - message: string; - }; - }; - }; - /** @description Forbidden */ - 403: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Forbidden operation */ - message: string; - }; - }; - }; - /** @description Not found */ - 404: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Not found */ - message: string; - }; - }; - }; + 401: components["responses"]["Unauthorized"]; + 403: components["responses"]["Forbidden"]; + 404: components["responses"]["NotFound"]; }; }; adminPutGame: { @@ -656,54 +543,10 @@ export interface operations { }; content?: never; }; - /** @description Invalid request */ - 400: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Invalid request */ - message: string; - }; - }; - }; - /** @description Unauthorized */ - 401: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Unauthorized */ - message: string; - }; - }; - }; - /** @description Forbidden */ - 403: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Forbidden operation */ - message: string; - }; - }; - }; - /** @description Not found */ - 404: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - /** @example Not found */ - message: string; - }; - }; - }; + 400: components["responses"]["BadRequest"]; + 401: components["responses"]["Unauthorized"]; + 403: components["responses"]["Forbidden"]; + 404: components["responses"]["NotFound"]; }; }; } diff --git a/openapi.yaml b/openapi.yaml index 1dd4614..683fadf 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -37,17 +37,7 @@ paths: required: - token '401': - description: Invalid username or password - content: - application/json: - schema: - type: object - properties: - message: - type: string - example: "Invalid credentials" - required: - - message + $ref: '#/components/responses/Unauthorized' /token: get: operationId: getToken @@ -68,17 +58,7 @@ paths: required: - token '401': - description: Unauthorized - content: - application/json: - schema: - type: object - properties: - message: - type: string - example: "Unauthorized" - required: - - message + $ref: '#/components/responses/Unauthorized' /games: get: operationId: getGames @@ -100,29 +80,9 @@ paths: required: - games '401': - description: Unauthorized - content: - application/json: - schema: - type: object - properties: - message: - type: string - example: "Unauthorized" - required: - - message + $ref: '#/components/responses/Unauthorized' '403': - description: Forbidden - content: - application/json: - schema: - type: object - properties: - message: - type: string - example: "Forbidden operation" - required: - - message + $ref: '#/components/responses/Forbidden' /games/{game_id}: get: operationId: getGame @@ -143,41 +103,11 @@ paths: required: - game '401': - description: Unauthorized - content: - application/json: - schema: - type: object - properties: - message: - type: string - example: "Unauthorized" - required: - - message + $ref: '#/components/responses/Unauthorized' '403': - description: Forbidden - content: - application/json: - schema: - type: object - properties: - message: - type: string - example: "Forbidden operation" - required: - - message + $ref: '#/components/responses/Forbidden' '404': - description: Not found - content: - application/json: - schema: - type: object - properties: - message: - type: string - example: "Not found" - required: - - message + $ref: '#/components/responses/NotFound' /admin/users: get: operationId: adminGetUsers @@ -199,29 +129,9 @@ paths: required: - users '401': - description: Unauthorized - content: - application/json: - schema: - type: object - properties: - message: - type: string - example: "Unauthorized" - required: - - message + $ref: '#/components/responses/Unauthorized' '403': - description: Forbidden - content: - application/json: - schema: - type: object - properties: - message: - type: string - example: "Forbidden operation" - required: - - message + $ref: '#/components/responses/Forbidden' /admin/games: get: operationId: adminGetGames @@ -243,29 +153,9 @@ paths: required: - games '401': - description: Unauthorized - content: - application/json: - schema: - type: object - properties: - message: - type: string - example: "Unauthorized" - required: - - message + $ref: '#/components/responses/Unauthorized' '403': - description: Forbidden - content: - application/json: - schema: - type: object - properties: - message: - type: string - example: "Forbidden operation" - required: - - message + $ref: '#/components/responses/Forbidden' /admin/games/{game_id}: get: operationId: adminGetGame @@ -286,41 +176,11 @@ paths: required: - game '401': - description: Unauthorized - content: - application/json: - schema: - type: object - properties: - message: - type: string - example: "Unauthorized" - required: - - message + $ref: '#/components/responses/Unauthorized' '403': - description: Forbidden - content: - application/json: - schema: - type: object - properties: - message: - type: string - example: "Forbidden operation" - required: - - message + $ref: '#/components/responses/Forbidden' '404': - description: Not found - content: - application/json: - schema: - type: object - properties: - message: - type: string - example: "Not found" - required: - - message + $ref: '#/components/responses/NotFound' put: operationId: adminPutGame summary: Update a game @@ -363,53 +223,13 @@ paths: '204': description: Successfully updated '400': - description: Invalid request - content: - application/json: - schema: - type: object - properties: - message: - type: string - example: "Invalid request" - required: - - message + $ref: '#/components/responses/BadRequest' '401': - description: Unauthorized - content: - application/json: - schema: - type: object - properties: - message: - type: string - example: "Unauthorized" - required: - - message + $ref: '#/components/responses/Unauthorized' '403': - description: Forbidden - content: - application/json: - schema: - type: object - properties: - message: - type: string - example: "Forbidden operation" - required: - - message + $ref: '#/components/responses/Forbidden' '404': - description: Not found - content: - application/json: - schema: - type: object - properties: - message: - type: string - example: "Not found" - required: - - message + $ref: '#/components/responses/NotFound' components: parameters: header_authorization: @@ -424,7 +244,40 @@ components: schema: type: integer required: true + responses: + BadRequest: + description: Bad request + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + Unauthorized: + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + Forbidden: + description: Forbidden + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + NotFound: + description: Not found + content: + application/json: + schema: + $ref: '#/components/schemas/Error' schemas: + Error: + type: object + properties: + message: + type: string + example: "Invalid request" + required: + - message User: type: object properties: -- cgit v1.2.3-70-g09d2