diff options
author | Antoine GIRARD <sapk@users.noreply.github.com> | 2017-05-02 15:35:59 +0200 |
---|---|---|
committer | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2017-05-02 15:35:59 +0200 |
commit | 3edb0c58943c003ed3f209b2197d1f43484a3432 (patch) | |
tree | e5849cead5053ab505a2c5dc1342111c6bcf0816 /routers/api/v1/user | |
parent | bb5f694fc57c3ade9c13e841b9a237f4e192da22 (diff) | |
download | gitea-3edb0c58943c003ed3f209b2197d1f43484a3432.tar.gz gitea-3edb0c58943c003ed3f209b2197d1f43484a3432.zip |
Generate swagger json (#1402)
- Generate swagger.json into public/
- Add swagger-ui auto-installation
- Add footer link to local swagger-ui
- Add /swagger url for using app url.
- Fix Swagger-UI version via git tag
Diffstat (limited to 'routers/api/v1/user')
-rw-r--r-- | routers/api/v1/user/app.go | 23 | ||||
-rw-r--r-- | routers/api/v1/user/follower.go | 66 | ||||
-rw-r--r-- | routers/api/v1/user/gpg_key.go | 51 | ||||
-rw-r--r-- | routers/api/v1/user/key.go | 56 | ||||
-rw-r--r-- | routers/api/v1/user/repo.go | 19 | ||||
-rw-r--r-- | routers/api/v1/user/star.go | 36 | ||||
-rw-r--r-- | routers/api/v1/user/user.go | 27 | ||||
-rw-r--r-- | routers/api/v1/user/watch.go | 36 |
8 files changed, 300 insertions, 14 deletions
diff --git a/routers/api/v1/user/app.go b/routers/api/v1/user/app.go index 6d5a271f79..88837a71a2 100644 --- a/routers/api/v1/user/app.go +++ b/routers/api/v1/user/app.go @@ -12,8 +12,16 @@ import ( ) // ListAccessTokens list all the access tokens -// see https://github.com/gogits/go-gogs-client/wiki/Users#list-access-tokens-for-a-user func ListAccessTokens(ctx *context.APIContext) { + // swagger:route GET /users/{username}/tokens userGetTokens + // + // Produces: + // - application/json + // + // Responses: + // 200: AccessTokenList + // 500: error + tokens, err := models.ListAccessTokens(ctx.User.ID) if err != nil { ctx.Error(500, "ListAccessTokens", err) @@ -31,8 +39,19 @@ func ListAccessTokens(ctx *context.APIContext) { } // CreateAccessToken create access tokens -// see https://github.com/gogits/go-gogs-client/wiki/Users#create-a-access-token func CreateAccessToken(ctx *context.APIContext, form api.CreateAccessTokenOption) { + // swagger:route POST /users/{username} /tokens userCreateToken + // + // Consumes: + // - application/json + // + // Produces: + // - application/json + // + // Responses: + // 200: AccessToken + // 500: error + t := &models.AccessToken{ UID: ctx.User.ID, Name: form.Name, diff --git a/routers/api/v1/user/follower.go b/routers/api/v1/user/follower.go index ff043c9de9..84240c7957 100644 --- a/routers/api/v1/user/follower.go +++ b/routers/api/v1/user/follower.go @@ -30,12 +30,29 @@ func listUserFollowers(ctx *context.APIContext, u *models.User) { // ListMyFollowers list all my followers func ListMyFollowers(ctx *context.APIContext) { + // swagger:route GET /user/followers userCurrentListFollowers + // + // Produces: + // - application/json + // + // Responses: + // 200: UserList + // 500: error + listUserFollowers(ctx, ctx.User) } // ListFollowers list user's followers -// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#list-followers-of-a-user func ListFollowers(ctx *context.APIContext) { + // swagger:route GET /users/:username/followers userListFollowers + // + // Produces: + // - application/json + // + // Responses: + // 200: UserList + // 500: error + u := GetUserByParams(ctx) if ctx.Written() { return @@ -54,12 +71,29 @@ func listUserFollowing(ctx *context.APIContext, u *models.User) { // ListMyFollowing list all my followings func ListMyFollowing(ctx *context.APIContext) { + // swagger:route GET /user/following userCurrentListFollowing + // + // Produces: + // - application/json + // + // Responses: + // 200: UserList + // 500: error + listUserFollowing(ctx, ctx.User) } // ListFollowing list user's followings -// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#list-users-followed-by-another-user func ListFollowing(ctx *context.APIContext) { + // swagger:route GET /users/{username}/following userListFollowing + // + // Produces: + // - application/json + // + // Responses: + // 200: UserList + // 500: error + u := GetUserByParams(ctx) if ctx.Written() { return @@ -76,8 +110,13 @@ func checkUserFollowing(ctx *context.APIContext, u *models.User, followID int64) } // CheckMyFollowing check if the repo is followed by me -// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#check-if-you-are-following-a-user func CheckMyFollowing(ctx *context.APIContext) { + // swagger:route GET /user/following/{username} userCurrentCheckFollowing + // + // Responses: + // 204: empty + // 404: notFound + target := GetUserByParams(ctx) if ctx.Written() { return @@ -86,8 +125,13 @@ func CheckMyFollowing(ctx *context.APIContext) { } // CheckFollowing check if the repo is followed by user -// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#check-if-one-user-follows-another func CheckFollowing(ctx *context.APIContext) { + // swagger:route GET /users/{username}/following/:target userCheckFollowing + // + // Responses: + // 204: empty + // 404: notFound + u := GetUserByParams(ctx) if ctx.Written() { return @@ -100,8 +144,13 @@ func CheckFollowing(ctx *context.APIContext) { } // Follow follow one repository -// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#follow-a-user func Follow(ctx *context.APIContext) { + // swagger:route PUT /user/following/{username} userCurrentPutFollow + // + // Responses: + // 204: empty + // 500: error + target := GetUserByParams(ctx) if ctx.Written() { return @@ -114,8 +163,13 @@ func Follow(ctx *context.APIContext) { } // Unfollow unfollow one repository -// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#unfollow-a-user func Unfollow(ctx *context.APIContext) { + // swagger:route DELETE /user/following/{username} userCurrentDeleteFollow + // + // Responses: + // 204: empty + // 500: error + target := GetUserByParams(ctx) if ctx.Written() { return diff --git a/routers/api/v1/user/gpg_key.go b/routers/api/v1/user/gpg_key.go index bb4ae42431..678816ccda 100644 --- a/routers/api/v1/user/gpg_key.go +++ b/routers/api/v1/user/gpg_key.go @@ -34,6 +34,15 @@ func listGPGKeys(ctx *context.APIContext, uid int64) { //ListGPGKeys get the GPG key list of a user func ListGPGKeys(ctx *context.APIContext) { + // swagger:route GET /users/{username}/gpg_keys userListGPGKeys + // + // Produces: + // - application/json + // + // Responses: + // 200: GPGKeyList + // 500: error + user := GetUserByParams(ctx) if ctx.Written() { return @@ -43,11 +52,30 @@ func ListGPGKeys(ctx *context.APIContext) { //ListMyGPGKeys get the GPG key list of the logged user func ListMyGPGKeys(ctx *context.APIContext) { + // swagger:route GET /user/gpg_keys userCurrentListGPGKeys + // + // Produces: + // - application/json + // + // Responses: + // 200: GPGKeyList + // 500: error + listGPGKeys(ctx, ctx.User.ID) } //GetGPGKey get the GPG key based on a id func GetGPGKey(ctx *context.APIContext) { + // swagger:route GET /user/gpg_keys/{id} userCurrentGetGPGKey + // + // Produces: + // - application/json + // + // Responses: + // 200: GPGKey + // 404: notFound + // 500: error + key, err := models.GetGPGKeyByID(ctx.ParamsInt64(":id")) if err != nil { if models.IsErrGPGKeyNotExist(err) { @@ -72,11 +100,34 @@ func CreateUserGPGKey(ctx *context.APIContext, form api.CreateGPGKeyOption, uid //CreateGPGKey associate a GPG key to the current user func CreateGPGKey(ctx *context.APIContext, form api.CreateGPGKeyOption) { + // swagger:route POST /user/gpg_keys userCurrentPostGPGKey + // + // Consumes: + // - application/json + // + // Produces: + // - application/json + // + // Responses: + // 201: GPGKey + // 422: validationError + // 500: error + CreateUserGPGKey(ctx, form, ctx.User.ID) } //DeleteGPGKey remove a GPG key associated to the current user func DeleteGPGKey(ctx *context.APIContext) { + // swagger:route DELETE /user/gpg_keys/{id} userCurrentDeleteGPGKey + // + // Produces: + // - application/json + // + // Responses: + // 204: empty + // 403: forbidden + // 500: error + if err := models.DeleteGPGKey(ctx.User, ctx.ParamsInt64(":id")); err != nil { if models.IsErrGPGKeyAccessDenied(err) { ctx.Error(403, "", "You do not have access to this key") diff --git a/routers/api/v1/user/key.go b/routers/api/v1/user/key.go index 39a045df32..a53ed2f8c9 100644 --- a/routers/api/v1/user/key.go +++ b/routers/api/v1/user/key.go @@ -54,14 +54,30 @@ func listPublicKeys(ctx *context.APIContext, uid int64) { } // ListMyPublicKeys list all my public keys -// see https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#list-your-public-keys func ListMyPublicKeys(ctx *context.APIContext) { + // swagger:route GET /user/keys userCurrentListKeys + // + // Produces: + // - application/json + // + // Responses: + // 200: PublicKeyList + // 500: error + listPublicKeys(ctx, ctx.User.ID) } // ListPublicKeys list all user's public keys -// see https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#list-public-keys-for-a-user func ListPublicKeys(ctx *context.APIContext) { + // swagger:route GET /users/{username}/keys userListKeys + // + // Produces: + // - application/json + // + // Responses: + // 200: PublicKeyList + // 500: error + user := GetUserByParams(ctx) if ctx.Written() { return @@ -70,8 +86,17 @@ func ListPublicKeys(ctx *context.APIContext) { } // GetPublicKey get one public key -// see https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#get-a-single-public-key func GetPublicKey(ctx *context.APIContext) { + // swagger:route GET /user/keys/{id} userCurrentGetKey + // + // Produces: + // - application/json + // + // Responses: + // 200: PublicKey + // 404: notFound + // 500: error + key, err := models.GetPublicKeyByID(ctx.ParamsInt64(":id")) if err != nil { if models.IsErrKeyNotExist(err) { @@ -104,14 +129,35 @@ func CreateUserPublicKey(ctx *context.APIContext, form api.CreateKeyOption, uid } // CreatePublicKey create one public key for me -// see https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#create-a-public-key func CreatePublicKey(ctx *context.APIContext, form api.CreateKeyOption) { + // swagger:route POST /user/keys userCurrentPostKey + // + // Consumes: + // - application/json + // + // Produces: + // - application/json + // + // Responses: + // 201: PublicKey + // 422: validationError + // 500: error + CreateUserPublicKey(ctx, form, ctx.User.ID) } // DeletePublicKey delete one public key of mine -// see https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#delete-a-public-key func DeletePublicKey(ctx *context.APIContext) { + // swagger:route DELETE /user/keys/{id} userCurrentDeleteKey + // + // Produces: + // - application/json + // + // Responses: + // 204: empty + // 403: forbidden + // 500: error + if err := models.DeletePublicKey(ctx.User, ctx.ParamsInt64(":id")); err != nil { if models.IsErrKeyAccessDenied(err) { ctx.Error(403, "", "You do not have access to this key") diff --git a/routers/api/v1/user/repo.go b/routers/api/v1/user/repo.go index cc08094fc5..ddb932bce9 100644 --- a/routers/api/v1/user/repo.go +++ b/routers/api/v1/user/repo.go @@ -36,6 +36,15 @@ func listUserRepos(ctx *context.APIContext, u *models.User) { // ListUserRepos - list the repos owned and accessible by the given user. func ListUserRepos(ctx *context.APIContext) { + // swagger:route GET /users/{username}/repos userListRepos + // + // Produces: + // - application/json + // + // Responses: + // 200: RepositoryList + // 500: error + user := GetUserByParams(ctx) if ctx.Written() { return @@ -44,8 +53,16 @@ func ListUserRepos(ctx *context.APIContext) { } // ListMyRepos - list the repositories owned by you. -// see https://github.com/gogits/go-gogs-client/wiki/Repositories#list-your-repositories func ListMyRepos(ctx *context.APIContext) { + // swagger:route GET /user/repos userCurrentListRepos + // + // Produces: + // - application/json + // + // Responses: + // 200: RepositoryList + // 500: error + listUserRepos(ctx, ctx.User) } diff --git a/routers/api/v1/user/star.go b/routers/api/v1/user/star.go index 47d3ed5079..49d704cb2e 100644 --- a/routers/api/v1/user/star.go +++ b/routers/api/v1/user/star.go @@ -33,6 +33,15 @@ func getStarredRepos(userID int64, private bool) ([]*api.Repository, error) { // GetStarredRepos returns the repos that the user specified by the APIContext // has starred func GetStarredRepos(ctx *context.APIContext) { + // swagger:route GET /users/{username}/starred userListStarred + // + // Produces: + // - application/json + // + // Responses: + // 200: RepositoryList + // 500: error + user := GetUserByParams(ctx) private := user.ID == ctx.User.ID repos, err := getStarredRepos(user.ID, private) @@ -44,6 +53,15 @@ func GetStarredRepos(ctx *context.APIContext) { // GetMyStarredRepos returns the repos that the authenticated user has starred func GetMyStarredRepos(ctx *context.APIContext) { + // swagger:route GET /user/starred userCurrentListStarred + // + // Produces: + // - application/json + // + // Responses: + // 200: RepositoryList + // 500: error + repos, err := getStarredRepos(ctx.User.ID, true) if err != nil { ctx.Error(500, "getStarredRepos", err) @@ -53,6 +71,12 @@ func GetMyStarredRepos(ctx *context.APIContext) { // IsStarring returns whether the authenticated is starring the repo func IsStarring(ctx *context.APIContext) { + // swagger:route GET /user/starred/{username}/{reponame} userCurrentCheckStarring + // + // Responses: + // 204: empty + // 404: notFound + if models.IsStaring(ctx.User.ID, ctx.Repo.Repository.ID) { ctx.Status(204) } else { @@ -62,6 +86,12 @@ func IsStarring(ctx *context.APIContext) { // Star the repo specified in the APIContext, as the authenticated user func Star(ctx *context.APIContext) { + // swagger:route PUT /user/starred/{username}/{reponame} userCurrentPutStar + // + // Responses: + // 204: empty + // 500: error + err := models.StarRepo(ctx.User.ID, ctx.Repo.Repository.ID, true) if err != nil { ctx.Error(500, "StarRepo", err) @@ -72,6 +102,12 @@ func Star(ctx *context.APIContext) { // Unstar the repo specified in the APIContext, as the authenticated user func Unstar(ctx *context.APIContext) { + // swagger:route DELETE /user/starred/{username}/{reponame} userCurrentDeleteStar + // + // Responses: + // 204: empty + // 500: error + err := models.StarRepo(ctx.User.ID, ctx.Repo.Repository.ID, false) if err != nil { ctx.Error(500, "StarRepo", err) diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go index de99fade46..cdb55c0d81 100644 --- a/routers/api/v1/user/user.go +++ b/routers/api/v1/user/user.go @@ -17,6 +17,15 @@ import ( // Search search users func Search(ctx *context.APIContext) { + // swagger:route GET /users/search userSearch + // + // Produces: + // - application/json + // + // Responses: + // 200: UserList + // 500: error + opts := &models.SearchUserOptions{ Keyword: strings.Trim(ctx.Query("q"), " "), Type: models.UserTypeIndividual, @@ -56,6 +65,16 @@ func Search(ctx *context.APIContext) { // GetInfo get user's information func GetInfo(ctx *context.APIContext) { + // swagger:route GET /users/{username} userGet + // + // Produces: + // - application/json + // + // Responses: + // 200: User + // 404: notFound + // 500: error + u, err := models.GetUserByName(ctx.Params(":username")) if err != nil { if models.IsErrUserNotExist(err) { @@ -75,5 +94,13 @@ func GetInfo(ctx *context.APIContext) { // GetAuthenticatedUser get curent user's information func GetAuthenticatedUser(ctx *context.APIContext) { + // swagger:route GET /user userGetCurrent + // + // Produces: + // - application/json + // + // Responses: + // 200: User + ctx.JSON(200, ctx.User.APIFormat()) } diff --git a/routers/api/v1/user/watch.go b/routers/api/v1/user/watch.go index 8bf4eeb505..230c819202 100644 --- a/routers/api/v1/user/watch.go +++ b/routers/api/v1/user/watch.go @@ -33,6 +33,15 @@ func getWatchedRepos(userID int64, private bool) ([]*api.Repository, error) { // GetWatchedRepos returns the repos that the user specified in ctx is watching func GetWatchedRepos(ctx *context.APIContext) { + // swagger:route GET /users/{username}/subscriptions userListSubscriptions + // + // Produces: + // - application/json + // + // Responses: + // 200: RepositoryList + // 500: error + user := GetUserByParams(ctx) private := user.ID == ctx.User.ID repos, err := getWatchedRepos(user.ID, private) @@ -44,6 +53,15 @@ func GetWatchedRepos(ctx *context.APIContext) { // GetMyWatchedRepos returns the repos that the authenticated user is watching func GetMyWatchedRepos(ctx *context.APIContext) { + // swagger:route GET /user/subscriptions userCurrentListSubscriptions + // + // Produces: + // - application/json + // + // Responses: + // 200: RepositoryList + // 500: error + repos, err := getWatchedRepos(ctx.User.ID, true) if err != nil { ctx.Error(500, "getWatchedRepos", err) @@ -54,6 +72,12 @@ func GetMyWatchedRepos(ctx *context.APIContext) { // IsWatching returns whether the authenticated user is watching the repo // specified in ctx func IsWatching(ctx *context.APIContext) { + // swagger:route GET /repos/{username}/{reponame}/subscription userCurrentCheckSubscription + // + // Responses: + // 200: WatchInfo + // 404: notFound + if models.IsWatching(ctx.User.ID, ctx.Repo.Repository.ID) { ctx.JSON(200, api.WatchInfo{ Subscribed: true, @@ -70,6 +94,12 @@ func IsWatching(ctx *context.APIContext) { // Watch the repo specified in ctx, as the authenticated user func Watch(ctx *context.APIContext) { + // swagger:route PUT /repos/{username}/{reponame}/subscription userCurrentPutSubscription + // + // Responses: + // 200: WatchInfo + // 500: error + err := models.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, true) if err != nil { ctx.Error(500, "WatchRepo", err) @@ -88,6 +118,12 @@ func Watch(ctx *context.APIContext) { // Unwatch the repo specified in ctx, as the authenticated user func Unwatch(ctx *context.APIContext) { + // swagger:route DELETE /repos/{username}/{reponame}/subscription userCurrentDeleteSubscription + // + // Responses: + // 204: empty + // 500: error + err := models.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, false) if err != nil { ctx.Error(500, "UnwatchRepo", err) |