Skip to content

Commit d2f87fd

Browse files
sapkappleboy
authored andcommitted
Add swagger descriptions and needed structs (gogs#53)
* Add swagger descriptions and needed structs * Remove missed TODO comment
1 parent 0c3a0b0 commit d2f87fd

File tree

8 files changed

+110
-10
lines changed

8 files changed

+110
-10
lines changed

gitea/miscellaneous.go

+35-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,47 @@
44

55
package gitea
66

7+
// SearchResults results of search
8+
// swagger:response SearchResults
9+
type SearchResults struct {
10+
OK bool `json:"ok"`
11+
Data []*Repository `json:"data"`
12+
}
13+
14+
// SearchError error of failing search
15+
// swagger:response SearchError
16+
type SearchError struct {
17+
OK bool `json:"ok"`
18+
Error string `json:"error"`
19+
}
20+
721
// MarkdownOption markdown options
22+
// swagger:parameters renderMarkdown
823
type MarkdownOption struct {
9-
Text string
10-
Mode string
24+
// Text markdown to render
25+
//
26+
// in: body
27+
Text string
28+
// Mode to render
29+
//
30+
// in: body
31+
Mode string
32+
// Context to render
33+
//
34+
// in: body
1135
Context string
12-
Wiki bool
36+
// Is it a wiki page ?
37+
//
38+
// in: body
39+
Wiki bool
1340
}
1441

42+
// MarkdownRender is a rendered markdown document
43+
// swagger:response MarkdownRender
44+
type MarkdownRender string
45+
1546
// ServerVersion wraps the version of the server
47+
// swagger:response ServerVersion
1648
type ServerVersion struct {
1749
Version string
1850
}

gitea/repo.go

+34-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Permission struct {
1919
}
2020

2121
// Repository represents a API repository.
22+
// swagger:response Repository
2223
type Repository struct {
2324
ID int64 `json:"id"`
2425
Owner *User `json:"owner"`
@@ -42,6 +43,10 @@ type Repository struct {
4243
Permissions *Permission `json:"permissions,omitempty"`
4344
}
4445

46+
// RepositoryList represents a list of API repository.
47+
// swagger:response RepositoryList
48+
type RepositoryList []*Repository
49+
4550
// ListMyRepos lists all repositories for the authenticated user that has access to.
4651
func (c *Client) ListMyRepos() ([]*Repository, error) {
4752
repos := make([]*Repository, 0, 10)
@@ -61,14 +66,37 @@ func (c *Client) ListOrgRepos(org string) ([]*Repository, error) {
6166
}
6267

6368
// CreateRepoOption options when creating repository
69+
//swagger:parameters createOrgRepo
6470
type CreateRepoOption struct {
65-
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
71+
// Name of the repository to create
72+
//
73+
// in: body
74+
// unique: true
75+
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
76+
// Description of the repository to create
77+
//
78+
// in: body
6679
Description string `json:"description" binding:"MaxSize(255)"`
67-
Private bool `json:"private"`
68-
AutoInit bool `json:"auto_init"`
69-
Gitignores string `json:"gitignores"`
70-
License string `json:"license"`
71-
Readme string `json:"readme"`
80+
// Is the repository to create private ?
81+
//
82+
// in: body
83+
Private bool `json:"private"`
84+
// Init the repository to create ?
85+
//
86+
// in: body
87+
AutoInit bool `json:"auto_init"`
88+
// Gitignores to use
89+
//
90+
// in: body
91+
Gitignores string `json:"gitignores"`
92+
// License to use
93+
//
94+
// in: body
95+
License string `json:"license"`
96+
// Readme of the repository to create
97+
//
98+
// in: body
99+
Readme string `json:"readme"`
72100
}
73101

74102
// CreateRepo creates a repository for authenticated user.

gitea/repo_key.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,20 @@ func (c *Client) GetDeployKey(user, repo string, keyID int64) (*DeployKey, error
3434
}
3535

3636
// CreateKeyOption options when create deploy key
37+
// swagger:parameters userCurrentPostKey
3738
type CreateKeyOption struct {
39+
// Title of the key to add
40+
//
41+
// in: body
42+
// required: true
43+
// unique: true
3844
Title string `json:"title" binding:"Required"`
39-
Key string `json:"key" binding:"Required"`
45+
// An armored SSH key to add
46+
//
47+
// in: body
48+
// required: true
49+
// unique: true
50+
Key string `json:"key" binding:"Required"`
4051
}
4152

4253
// CreateDeployKey options when create one deploy key

gitea/repo_watch.go

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
)
1212

1313
// WatchInfo represents a API watch status of one repository
14+
// swagger:response WatchInfo
1415
type WatchInfo struct {
1516
Subscribed bool `json:"subscribed"`
1617
Ignored bool `json:"ignored"`

gitea/user.go

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
)
1111

1212
// User represents a API user.
13+
// swagger:response User
1314
type User struct {
1415
ID int64 `json:"id"`
1516
UserName string `json:"login"`
@@ -18,6 +19,10 @@ type User struct {
1819
AvatarURL string `json:"avatar_url"`
1920
}
2021

22+
// UserList represents a list of API user.
23+
// swagger:response UserList
24+
type UserList []*User
25+
2126
// MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility
2227
func (u User) MarshalJSON() ([]byte, error) {
2328
// Re-declaring User to avoid recursion

gitea/user_app.go

+6
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,16 @@ func BasicAuthEncode(user, pass string) string {
1818
}
1919

2020
// AccessToken represents a API access token.
21+
// swagger:response AccessToken
2122
type AccessToken struct {
2223
Name string `json:"name"`
2324
Sha1 string `json:"sha1"`
2425
}
2526

27+
// AccessTokenList represents a list of API access token.
28+
// swagger:response AccessTokenList
29+
type AccessTokenList []*AccessToken
30+
2631
// ListAccessTokens lista all the access tokens of user
2732
func (c *Client) ListAccessTokens(user, pass string) ([]*AccessToken, error) {
2833
tokens := make([]*AccessToken, 0, 10)
@@ -31,6 +36,7 @@ func (c *Client) ListAccessTokens(user, pass string) ([]*AccessToken, error) {
3136
}
3237

3338
// CreateAccessTokenOption options when create access token
39+
// swagger:parameters userCreateToken
3440
type CreateAccessTokenOption struct {
3541
Name string `json:"name" binding:"Required"`
3642
}

gitea/user_gpgkey.go

+12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import (
1111
"time"
1212
)
1313

14+
// GPGKeyList represents a list of GPGKey
15+
// swagger:response GPGKeyList
16+
type GPGKeyList []*GPGKey
17+
1418
// GPGKey a user GPG key to sign commit and tag in repository
19+
// swagger:response GPGKey
1520
type GPGKey struct {
1621
ID int64 `json:"id"`
1722
PrimaryKeyID string `json:"primary_key_id"`
@@ -28,13 +33,20 @@ type GPGKey struct {
2833
}
2934

3035
// GPGKeyEmail a email attache to a GPGKey
36+
// swagger:model GPGKeyEmail
3137
type GPGKeyEmail struct {
3238
Email string `json:"email"`
3339
Verified bool `json:"verified"`
3440
}
3541

3642
// CreateGPGKeyOption options create user GPG key
43+
// swagger:parameters userCurrentPostGPGKey
3744
type CreateGPGKeyOption struct {
45+
// An armored GPG key to add
46+
//
47+
// in: body
48+
// required: true
49+
// unique: true
3850
ArmoredKey string `json:"armored_public_key" binding:"Required"`
3951
}
4052

gitea/user_key.go

+5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import (
1111
"time"
1212
)
1313

14+
// PublicKeyList represents a list of PublicKey
15+
// swagger:response PublicKeyList
16+
type PublicKeyList []*PublicKey
17+
1418
// PublicKey publickey is a user key to push code to repository
19+
// swagger:response PublicKey
1520
type PublicKey struct {
1621
ID int64 `json:"id"`
1722
Key string `json:"key"`

0 commit comments

Comments
 (0)