From 9e7859c36c227651a329b4d3eb6e8911435c88ce Mon Sep 17 00:00:00 2001 From: Jannis Mattheis Date: Sat, 24 Nov 2018 10:52:43 +0100 Subject: [PATCH] Add missing bad request / not found definitions --- api/application.go | 28 +++++++ api/client.go | 12 +++ api/message.go | 36 +++++++++ api/stream/stream.go | 8 ++ api/user.go | 32 ++++++++ docs/spec.json | 174 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 290 insertions(+) diff --git a/api/application.go b/api/application.go index 3d7f9f0..c26b84d 100644 --- a/api/application.go +++ b/api/application.go @@ -54,6 +54,10 @@ type ApplicationAPI struct { // description: Ok // schema: // $ref: "#/definitions/Application" +// 400: +// description: Bad Request +// schema: +// $ref: "#/definitions/Error" // 401: // description: Unauthorized // schema: @@ -129,6 +133,10 @@ func (a *ApplicationAPI) GetApplications(ctx *gin.Context) { // responses: // 200: // description: Ok +// 400: +// description: Bad Request +// schema: +// $ref: "#/definitions/Error" // 401: // description: Unauthorized // schema: @@ -137,6 +145,10 @@ func (a *ApplicationAPI) GetApplications(ctx *gin.Context) { // description: Forbidden // schema: // $ref: "#/definitions/Error" +// 404: +// description: Not Found +// schema: +// $ref: "#/definitions/Error" func (a *ApplicationAPI) DeleteApplication(ctx *gin.Context) { withID(ctx, "id", func(id uint) { if app := a.DB.GetApplicationByID(id); app != nil && app.UserID == auth.GetUserID(ctx) { @@ -191,6 +203,10 @@ func (a *ApplicationAPI) DeleteApplication(ctx *gin.Context) { // description: Forbidden // schema: // $ref: "#/definitions/Error" +// 404: +// description: Not Found +// schema: +// $ref: "#/definitions/Error" func (a *ApplicationAPI) UpdateApplication(ctx *gin.Context) { withID(ctx, "id", func(id uint) { if app := a.DB.GetApplicationByID(id); app != nil && app.UserID == auth.GetUserID(ctx) { @@ -238,6 +254,10 @@ func (a *ApplicationAPI) UpdateApplication(ctx *gin.Context) { // description: Ok // schema: // $ref: "#/definitions/Application" +// 400: +// description: Bad Request +// schema: +// $ref: "#/definitions/Error" // 401: // description: Unauthorized // schema: @@ -246,6 +266,14 @@ func (a *ApplicationAPI) UpdateApplication(ctx *gin.Context) { // description: Forbidden // schema: // $ref: "#/definitions/Error" +// 404: +// description: Not Found +// schema: +// $ref: "#/definitions/Error" +// 500: +// description: Server Error +// schema: +// $ref: "#/definitions/Error" func (a *ApplicationAPI) UploadApplicationImage(ctx *gin.Context) { withID(ctx, "id", func(id uint) { if app := a.DB.GetApplicationByID(id); app != nil && app.UserID == auth.GetUserID(ctx) { diff --git a/api/client.go b/api/client.go index aca2856..22a265f 100644 --- a/api/client.go +++ b/api/client.go @@ -48,6 +48,10 @@ type ClientAPI struct { // description: Ok // schema: // $ref: "#/definitions/Client" +// 400: +// description: Bad Request +// schema: +// $ref: "#/definitions/Error" // 401: // description: Unauthorized // schema: @@ -120,6 +124,10 @@ func (a *ClientAPI) GetClients(ctx *gin.Context) { // responses: // 200: // description: Ok +// 400: +// description: Bad Request +// schema: +// $ref: "#/definitions/Error" // 401: // description: Unauthorized // schema: @@ -128,6 +136,10 @@ func (a *ClientAPI) GetClients(ctx *gin.Context) { // description: Forbidden // schema: // $ref: "#/definitions/Error" +// 404: +// description: Not Found +// schema: +// $ref: "#/definitions/Error" func (a *ClientAPI) DeleteClient(ctx *gin.Context) { withID(ctx, "id", func(id uint) { if client := a.DB.GetClientByID(id); client != nil && client.UserID == auth.GetUserID(ctx) { diff --git a/api/message.go b/api/message.go index 0166182..65e50e9 100644 --- a/api/message.go +++ b/api/message.go @@ -76,6 +76,10 @@ type pagingParams struct { // description: Ok // schema: // $ref: "#/definitions/PagedMessages" +// 400: +// description: Bad Request +// schema: +// $ref: "#/definitions/Error" // 401: // description: Unauthorized // schema: @@ -157,6 +161,10 @@ func withPaging(ctx *gin.Context, f func(pagingParams *pagingParams)) { // description: Ok // schema: // $ref: "#/definitions/PagedMessages" +// 400: +// description: Bad Request +// schema: +// $ref: "#/definitions/Error" // 401: // description: Unauthorized // schema: @@ -165,6 +173,10 @@ func withPaging(ctx *gin.Context, f func(pagingParams *pagingParams)) { // description: Forbidden // schema: // $ref: "#/definitions/Error" +// 404: +// description: Not Found +// schema: +// $ref: "#/definitions/Error" func (a *MessageAPI) GetMessagesWithApplication(ctx *gin.Context) { withID(ctx, "id", func(id uint) { withPaging(ctx, func(params *pagingParams) { @@ -226,6 +238,10 @@ func (a *MessageAPI) DeleteMessages(ctx *gin.Context) { // responses: // 200: // description: Ok +// 400: +// description: Bad Request +// schema: +// $ref: "#/definitions/Error" // 401: // description: Unauthorized // schema: @@ -234,6 +250,10 @@ func (a *MessageAPI) DeleteMessages(ctx *gin.Context) { // description: Forbidden // schema: // $ref: "#/definitions/Error" +// 404: +// description: Not Found +// schema: +// $ref: "#/definitions/Error" func (a *MessageAPI) DeleteMessageWithApplication(ctx *gin.Context) { withID(ctx, "id", func(id uint) { if application := a.DB.GetApplicationByID(id); application != nil && application.UserID == auth.GetUserID(ctx) { @@ -264,6 +284,10 @@ func (a *MessageAPI) DeleteMessageWithApplication(ctx *gin.Context) { // responses: // 200: // description: Ok +// 400: +// description: Bad Request +// schema: +// $ref: "#/definitions/Error" // 401: // description: Unauthorized // schema: @@ -272,6 +296,10 @@ func (a *MessageAPI) DeleteMessageWithApplication(ctx *gin.Context) { // description: Forbidden // schema: // $ref: "#/definitions/Error" +// 404: +// description: Not Found +// schema: +// $ref: "#/definitions/Error" func (a *MessageAPI) DeleteMessage(ctx *gin.Context) { withID(ctx, "id", func(id uint) { if msg := a.DB.GetMessageByID(id); msg != nil && a.DB.GetApplicationByID(msg.ApplicationID).UserID == auth.GetUserID(ctx) { @@ -304,10 +332,18 @@ func (a *MessageAPI) DeleteMessage(ctx *gin.Context) { // description: Ok // schema: // $ref: "#/definitions/Message" +// 400: +// description: Bad Request +// schema: +// $ref: "#/definitions/Error" // 401: // description: Unauthorized // schema: // $ref: "#/definitions/Error" +// 403: +// description: Forbidden +// schema: +// $ref: "#/definitions/Error" func (a *MessageAPI) CreateMessage(ctx *gin.Context) { message := model.Message{} if err := ctx.Bind(&message); err == nil { diff --git a/api/stream/stream.go b/api/stream/stream.go index 97f65a8..66358f4 100644 --- a/api/stream/stream.go +++ b/api/stream/stream.go @@ -133,6 +133,10 @@ func (a *API) register(client *client) { // description: Ok // schema: // $ref: "#/definitions/Message" +// 400: +// description: Bad Request +// schema: +// $ref: "#/definitions/Error" // 401: // description: Unauthorized // schema: @@ -141,6 +145,10 @@ func (a *API) register(client *client) { // description: Forbidden // schema: // $ref: "#/definitions/Error" +// 500: +// description: Server Error +// schema: +// $ref: "#/definitions/Error" func (a *API) Handle(ctx *gin.Context) { conn, err := upgrader.Upgrade(ctx.Writer, ctx.Request, nil) if err != nil { diff --git a/api/user.go b/api/user.go index 3941b87..2f934ed 100644 --- a/api/user.go +++ b/api/user.go @@ -116,6 +116,10 @@ func (a *UserAPI) GetCurrentUser(ctx *gin.Context) { // description: Ok // schema: // $ref: "#/definitions/User" +// 400: +// description: Bad Request +// schema: +// $ref: "#/definitions/Error" // 401: // description: Unauthorized // schema: @@ -160,6 +164,10 @@ func (a *UserAPI) CreateUser(ctx *gin.Context) { // description: Ok // schema: // $ref: "#/definitions/User" +// 400: +// description: Bad Request +// schema: +// $ref: "#/definitions/Error" // 401: // description: Unauthorized // schema: @@ -168,6 +176,10 @@ func (a *UserAPI) CreateUser(ctx *gin.Context) { // description: Forbidden // schema: // $ref: "#/definitions/Error" +// 404: +// description: Not Found +// schema: +// $ref: "#/definitions/Error" func (a *UserAPI) GetUserByID(ctx *gin.Context) { withID(ctx, "id", func(id uint) { if user := a.DB.GetUserByID(uint(id)); user != nil { @@ -198,6 +210,10 @@ func (a *UserAPI) GetUserByID(ctx *gin.Context) { // responses: // 200: // description: Ok +// 400: +// description: Bad Request +// schema: +// $ref: "#/definitions/Error" // 401: // description: Unauthorized // schema: @@ -206,6 +222,10 @@ func (a *UserAPI) GetUserByID(ctx *gin.Context) { // description: Forbidden // schema: // $ref: "#/definitions/Error" +// 404: +// description: Not Found +// schema: +// $ref: "#/definitions/Error" func (a *UserAPI) DeleteUserByID(ctx *gin.Context) { withID(ctx, "id", func(id uint) { if user := a.DB.GetUserByID(id); user != nil { @@ -239,6 +259,10 @@ func (a *UserAPI) DeleteUserByID(ctx *gin.Context) { // responses: // 200: // description: Ok +// 400: +// description: Bad Request +// schema: +// $ref: "#/definitions/Error" // 401: // description: Unauthorized // schema: @@ -285,6 +309,10 @@ func (a *UserAPI) ChangePassword(ctx *gin.Context) { // description: Ok // schema: // $ref: "#/definitions/User" +// 400: +// description: Bad Request +// schema: +// $ref: "#/definitions/Error" // 401: // description: Unauthorized // schema: @@ -293,6 +321,10 @@ func (a *UserAPI) ChangePassword(ctx *gin.Context) { // description: Forbidden // schema: // $ref: "#/definitions/Error" +// 404: +// description: Not Found +// schema: +// $ref: "#/definitions/Error" func (a *UserAPI) UpdateUserByID(ctx *gin.Context) { withID(ctx, "id", func(id uint) { var user *model.UserExternalWithPass diff --git a/docs/spec.json b/docs/spec.json index dc310ed..504b4b7 100644 --- a/docs/spec.json +++ b/docs/spec.json @@ -110,6 +110,12 @@ "$ref": "#/definitions/Application" } }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, "401": { "description": "Unauthorized", "schema": { @@ -191,6 +197,12 @@ "schema": { "$ref": "#/definitions/Error" } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } } } }, @@ -230,6 +242,12 @@ "200": { "description": "Ok" }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, "401": { "description": "Unauthorized", "schema": { @@ -241,6 +259,12 @@ "schema": { "$ref": "#/definitions/Error" } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } } } } @@ -292,6 +316,12 @@ "$ref": "#/definitions/Application" } }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, "401": { "description": "Unauthorized", "schema": { @@ -303,6 +333,18 @@ "schema": { "$ref": "#/definitions/Error" } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Server Error", + "schema": { + "$ref": "#/definitions/Error" + } } } } @@ -360,6 +402,12 @@ "$ref": "#/definitions/PagedMessages" } }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, "401": { "description": "Unauthorized", "schema": { @@ -371,6 +419,12 @@ "schema": { "$ref": "#/definitions/Error" } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } } } }, @@ -407,6 +461,12 @@ "200": { "description": "Ok" }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, "401": { "description": "Unauthorized", "schema": { @@ -418,6 +478,12 @@ "schema": { "$ref": "#/definitions/Error" } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } } } } @@ -511,6 +577,12 @@ "$ref": "#/definitions/Client" } }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, "401": { "description": "Unauthorized", "schema": { @@ -563,6 +635,12 @@ "200": { "description": "Ok" }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, "401": { "description": "Unauthorized", "schema": { @@ -574,6 +652,12 @@ "schema": { "$ref": "#/definitions/Error" } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } } } } @@ -660,6 +744,12 @@ "200": { "description": "Ok" }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, "401": { "description": "Unauthorized", "schema": { @@ -721,6 +811,12 @@ "$ref": "#/definitions/PagedMessages" } }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, "401": { "description": "Unauthorized", "schema": { @@ -774,11 +870,23 @@ "$ref": "#/definitions/Message" } }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/Error" } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } } } }, @@ -855,6 +963,12 @@ "200": { "description": "Ok" }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, "401": { "description": "Unauthorized", "schema": { @@ -866,6 +980,12 @@ "schema": { "$ref": "#/definitions/Error" } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } } } } @@ -898,6 +1018,12 @@ "$ref": "#/definitions/Message" } }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, "401": { "description": "Unauthorized", "schema": { @@ -909,6 +1035,12 @@ "schema": { "$ref": "#/definitions/Error" } + }, + "500": { + "description": "Server Error", + "schema": { + "$ref": "#/definitions/Error" + } } } } @@ -999,6 +1131,12 @@ "$ref": "#/definitions/User" } }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, "401": { "description": "Unauthorized", "schema": { @@ -1054,6 +1192,12 @@ "$ref": "#/definitions/User" } }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, "401": { "description": "Unauthorized", "schema": { @@ -1065,6 +1209,12 @@ "schema": { "$ref": "#/definitions/Error" } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } } } }, @@ -1116,6 +1266,12 @@ "$ref": "#/definitions/User" } }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, "401": { "description": "Unauthorized", "schema": { @@ -1127,6 +1283,12 @@ "schema": { "$ref": "#/definitions/Error" } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } } } }, @@ -1163,6 +1325,12 @@ "200": { "description": "Ok" }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, "401": { "description": "Unauthorized", "schema": { @@ -1174,6 +1342,12 @@ "schema": { "$ref": "#/definitions/Error" } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } } } }