Skip to content

Commit a1b8091

Browse files
committed
Swagger AccessToken fixes
There is a subtle problem with the Swagger definition for AccessTokens which causes autogeneration of APIs for these endpoints to fail. This PR corrects these errors. Ref: zeripath/java-gitea-api#4 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 3705168 commit a1b8091

File tree

4 files changed

+27
-31
lines changed

4 files changed

+27
-31
lines changed

routers/api/v1/swagger/app.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ type swaggerResponseOAuth2Application struct {
1414
// in:body
1515
Body api.OAuth2Application `json:"body"`
1616
}
17+
18+
// AccessToken represents an API access token.
19+
// swagger:response AccessToken
20+
type swaggerResponseAccessToken struct {
21+
// in:body
22+
Body api.AccessToken `json:"body"`
23+
}

routers/api/v1/swagger/options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ type swaggerParameterBodies struct {
164164
// in:body
165165
CreateTagOption api.CreateTagOption
166166

167+
// in:body
168+
CreateAccessTokenOption api.CreateAccessTokenOption
169+
167170
// in:body
168171
UserSettingsOptions api.UserSettingsOptions
169172
}

routers/api/v1/user/app.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,10 @@ func CreateAccessToken(ctx *context.APIContext) {
7676
// description: username of user
7777
// type: string
7878
// required: true
79-
// - name: accessToken
79+
// - name: userCreateToken
8080
// in: body
8181
// schema:
82-
// type: object
83-
// required:
84-
// - name
85-
// properties:
86-
// name:
87-
// type: string
82+
// "$ref": "#/definitions/CreateAccessTokenOption"
8883
// responses:
8984
// "201":
9085
// "$ref": "#/responses/AccessToken"

templates/swagger/v1_json.tmpl

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11917,18 +11917,10 @@
1191711917
"required": true
1191811918
},
1191911919
{
11920-
"name": "accessToken",
11920+
"name": "userCreateToken",
1192111921
"in": "body",
1192211922
"schema": {
11923-
"type": "object",
11924-
"required": [
11925-
"name"
11926-
],
11927-
"properties": {
11928-
"name": {
11929-
"type": "string"
11930-
}
11931-
}
11923+
"$ref": "#/definitions/CreateAccessTokenOption"
1193211924
}
1193311925
}
1193411926
],
@@ -12654,6 +12646,17 @@
1265412646
},
1265512647
"x-go-package": "code.gitea.io/gitea/modules/structs"
1265612648
},
12649+
"CreateAccessTokenOption": {
12650+
"description": "CreateAccessTokenOption options when create access token",
12651+
"type": "object",
12652+
"properties": {
12653+
"name": {
12654+
"type": "string",
12655+
"x-go-name": "Name"
12656+
}
12657+
},
12658+
"x-go-package": "code.gitea.io/gitea/modules/structs"
12659+
},
1265712660
"CreateBranchProtectionOption": {
1265812661
"description": "CreateBranchProtectionOption options for creating a branch protection",
1265912662
"type": "object",
@@ -17045,20 +17048,8 @@
1704517048
"responses": {
1704617049
"AccessToken": {
1704717050
"description": "AccessToken represents an API access token.",
17048-
"headers": {
17049-
"id": {
17050-
"type": "integer",
17051-
"format": "int64"
17052-
},
17053-
"name": {
17054-
"type": "string"
17055-
},
17056-
"sha1": {
17057-
"type": "string"
17058-
},
17059-
"token_last_eight": {
17060-
"type": "string"
17061-
}
17051+
"schema": {
17052+
"$ref": "#/definitions/AccessToken"
1706217053
}
1706317054
},
1706417055
"AccessTokenList": {

0 commit comments

Comments
 (0)