From 48c7c880b8fcf8e5d8495e66392e787bd7209b8c Mon Sep 17 00:00:00 2001 From: zeripath Date: Sun, 1 Aug 2021 21:44:15 +0100 Subject: [PATCH] Swagger AccessToken fixes (#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: https://github.com/zeripath/java-gitea-api/issues/4 Signed-off-by: Andrew Thornton Co-authored-by: techknowlogick --- routers/api/v1/swagger/app.go | 7 ++++++ routers/api/v1/swagger/options.go | 3 +++ routers/api/v1/user/app.go | 9 ++----- templates/swagger/v1_json.tmpl | 39 ++++++++++++------------------- 4 files changed, 27 insertions(+), 31 deletions(-) diff --git a/routers/api/v1/swagger/app.go b/routers/api/v1/swagger/app.go index 8be2c85574..9783abe1a0 100644 --- a/routers/api/v1/swagger/app.go +++ b/routers/api/v1/swagger/app.go @@ -14,3 +14,10 @@ type swaggerResponseOAuth2Application struct { // in:body Body api.OAuth2Application `json:"body"` } + +// AccessToken represents an API access token. +// swagger:response AccessToken +type swaggerResponseAccessToken struct { + // in:body + Body api.AccessToken `json:"body"` +} diff --git a/routers/api/v1/swagger/options.go b/routers/api/v1/swagger/options.go index 0ae96a9203..3f0c6e2d52 100644 --- a/routers/api/v1/swagger/options.go +++ b/routers/api/v1/swagger/options.go @@ -164,6 +164,9 @@ type swaggerParameterBodies struct { // in:body CreateTagOption api.CreateTagOption + // in:body + CreateAccessTokenOption api.CreateAccessTokenOption + // in:body UserSettingsOptions api.UserSettingsOptions } diff --git a/routers/api/v1/user/app.go b/routers/api/v1/user/app.go index 9f355a8289..afd209f2f0 100644 --- a/routers/api/v1/user/app.go +++ b/routers/api/v1/user/app.go @@ -76,15 +76,10 @@ func CreateAccessToken(ctx *context.APIContext) { // description: username of user // type: string // required: true - // - name: accessToken + // - name: userCreateToken // in: body // schema: - // type: object - // required: - // - name - // properties: - // name: - // type: string + // "$ref": "#/definitions/CreateAccessTokenOption" // responses: // "201": // "$ref": "#/responses/AccessToken" diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index d97ec5ff2d..a1d92abec7 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -11917,18 +11917,10 @@ "required": true }, { - "name": "accessToken", + "name": "userCreateToken", "in": "body", "schema": { - "type": "object", - "required": [ - "name" - ], - "properties": { - "name": { - "type": "string" - } - } + "$ref": "#/definitions/CreateAccessTokenOption" } } ], @@ -12654,6 +12646,17 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, + "CreateAccessTokenOption": { + "description": "CreateAccessTokenOption options when create access token", + "type": "object", + "properties": { + "name": { + "type": "string", + "x-go-name": "Name" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, "CreateBranchProtectionOption": { "description": "CreateBranchProtectionOption options for creating a branch protection", "type": "object", @@ -17045,20 +17048,8 @@ "responses": { "AccessToken": { "description": "AccessToken represents an API access token.", - "headers": { - "id": { - "type": "integer", - "format": "int64" - }, - "name": { - "type": "string" - }, - "sha1": { - "type": "string" - }, - "token_last_eight": { - "type": "string" - } + "schema": { + "$ref": "#/definitions/AccessToken" } }, "AccessTokenList": {