fix(api): declare archive endpoint as octet-stream in swagger (#40571)

`repoGetArchive` declared `application/json` in the Swagger 2 spec while
actually serving an archive, which made generated API clients fail on
content-type validation. Declare it as `application/octet-stream` with a
file schema, as already done for `repoGetRawFile`, so the body also
appears in the OpenAPI 3 spec.

The shared `error` response described its `message` and `url` fields as
headers, so clients could not decode error bodies. Declare it as a JSON
body using the `APIError` struct.

Fixes: https://github.com/go-gitea/gitea/issues/21997

Assisted-by: OpenCode:hy4-flash-free
Assisted-by: Claude Code:claude-opus-5-5

---------

Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
Vu Nguyen Anh Tuanandsilverwind authored and GitHub committed 2026-11-28 04:25:08 +00:00
1 parent f9a13b6ce2
commit 5be2141de0
5 files changed
+65 -21

No files matched your search

+3 -1
View File
@@ -233,7 +233,7 @@ func GetArchive(ctx *context.APIContext) {
// ---
// summary: Get an archive of a repository
// produces:
// - application/json
// - application/octet-stream
// parameters:
// - name: owner
// in: path
@@ -260,6 +260,8 @@ func GetArchive(ctx *context.APIContext) {
// responses:
// 200:
// description: success
// schema:
// type: file
// default:
// "$ref": "#/responses/error"
serveRepoArchive(ctx, ctx.PathParam("*"), ctx.FormStrings("path"))
+7
View File
@@ -55,3 +55,10 @@ type swaggerResponseLabelTemplateInfo struct {
// in:body
Body []api.LabelTemplate `json:"body"`
}
// APIError is error format response
// swagger:response error
type swaggerResponseError struct {
// in:body
Body api.APIError `json:"body"`
}
-1
View File
@@ -60,7 +60,6 @@ func init() {
// * url: the swagger document URL
// APIError is error format response
// swagger:response error
type APIError struct {
Message string `json:"message"`
URL string `json:"url"`
+31 -10
View File
@@ -1689,19 +1689,14 @@
"description": "APIEmpty is an empty response"
},
"error": {
"description": "APIError is error format response",
"headers": {
"message": {
"content": {
"application/json": {
"schema": {
"type": "string"
}
},
"url": {
"schema": {
"type": "string"
"$ref": "#/components/schemas/APIError"
}
}
}
},
"description": "APIError is error format response"
},
"string": {
"content": {
@@ -1715,6 +1710,24 @@
}
},
"schemas": {
"APIError": {
"description": "APIError is an api error with a message",
"properties": {
"message": {
"description": "Message contains the error description",
"type": "string",
"x-go-name": "Message"
},
"url": {
"description": "URL contains the documentation URL for this error",
"format": "uri",
"type": "string",
"x-go-name": "URL"
}
},
"type": "object",
"x-go-package": "gitea.dev/modules/structs"
},
"AccessLevelName": {
"enum": [
"none",
@@ -20029,6 +20042,14 @@
],
"responses": {
"200": {
"content": {
"application/octet-stream": {
"schema": {
"format": "binary",
"type": "string"
}
}
},
"description": "success"
},
"default": {
+24 -9
View File
@@ -7679,7 +7679,7 @@
"/repos/{owner}/{repo}/archive/{archive}": {
"get": {
"produces": [
"application/json"
"application/octet-stream"
],
"tags": [
"repository"
@@ -7721,7 +7721,10 @@
],
"responses": {
"200": {
"description": "success"
"description": "success",
"schema": {
"type": "file"
}
},
"default": {
"$ref": "#/responses/error"
@@ -24594,6 +24597,23 @@
}
},
"definitions": {
"APIError": {
"description": "APIError is an api error with a message",
"type": "object",
"properties": {
"message": {
"description": "Message contains the error description",
"type": "string",
"x-go-name": "Message"
},
"url": {
"description": "URL contains the documentation URL for this error",
"type": "string",
"x-go-name": "URL"
}
},
"x-go-package": "gitea.dev/modules/structs"
},
"AccessToken": {
"type": "object",
"title": "AccessToken represents an API access token.",
@@ -35662,13 +35682,8 @@
},
"error": {
"description": "APIError is error format response",
"headers": {
"message": {
"type": "string"
},
"url": {
"type": "string"
}
"schema": {
"$ref": "#/definitions/APIError"
}
},
"string": {