Skip to content

Commit 5fe7c0e

Browse files
Swagger AccessToken fixes (#16574) (#16597)
Backport #16574 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 <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
1 parent 763e419 commit 5fe7c0e

File tree

4 files changed

+27
-31
lines changed

4 files changed

+27
-31
lines changed

routers/api/v1/swagger/app.go

+7
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

+3
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

+2-7
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

+15-24
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",
@@ -17044,20 +17047,8 @@
1704417047
"responses": {
1704517048
"AccessToken": {
1704617049
"description": "AccessToken represents an API access token.",
17047-
"headers": {
17048-
"id": {
17049-
"type": "integer",
17050-
"format": "int64"
17051-
},
17052-
"name": {
17053-
"type": "string"
17054-
},
17055-
"sha1": {
17056-
"type": "string"
17057-
},
17058-
"token_last_eight": {
17059-
"type": "string"
17060-
}
17050+
"schema": {
17051+
"$ref": "#/definitions/AccessToken"
1706117052
}
1706217053
},
1706317054
"AccessTokenList": {

0 commit comments

Comments
 (0)