diff --git a/Makefile b/Makefile index 4af42ceb6f..a8a4c874d6 100644 --- a/Makefile +++ b/Makefile @@ -196,7 +196,7 @@ SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl \| JSEs SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape}}/api/v1"|"basePath": "/api/v1"|g SWAGGER_EXCLUDE := code.gitea.io/sdk SWAGGER_NEWLINE_COMMAND := -e '$$a\' -SWAGGER_SPEC_BRANDING := s|Gitea API|Forgejo API|g +SWAGGER_SPEC_BRANDING := s|Gitea API|GitAec API|g SWAGGER_SPEC_LICENSE := s|"name": "MIT"|"name": "This file is distributed under the MIT license for the purpose of interoperability"| TEST_MYSQL_HOST ?= mysql:3306 diff --git a/modules/structs/foundation.go b/modules/structs/foundation.go new file mode 100644 index 0000000000..2feffec37e --- /dev/null +++ b/modules/structs/foundation.go @@ -0,0 +1,12 @@ +// Copyright 2025 Milovann Yanatchkov +// SPDX-License-Identifier: GPL-3.0-or-later + +package structs + +// Foundatoion Versions +type Foundation struct { + ID int64 `json:"api_id"` + Version int64 `json:"version_id"` + DetailedVersion string `json:"detailed_version"` + BaseURL string `json:"api_base_url"` +} diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 4928c9ff58..8fd5fdad84 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -89,6 +89,7 @@ import ( "code.gitea.io/gitea/routers/api/shared" "code.gitea.io/gitea/routers/api/v1/activitypub" "code.gitea.io/gitea/routers/api/v1/admin" + "code.gitea.io/gitea/routers/api/v1/foundation" "code.gitea.io/gitea/routers/api/v1/misc" "code.gitea.io/gitea/routers/api/v1/notify" "code.gitea.io/gitea/routers/api/v1/org" @@ -834,6 +835,10 @@ func Routes() *web.Route { }) } + m.Group("/foundation", func() { + m.Get("/versions", foundation.GetVersions) + }, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryRepository)) + if setting.Federation.Enabled { m.Get("/nodeinfo", misc.NodeInfo) m.Group("/activitypub", func() { diff --git a/routers/api/v1/foundation/foundation.go b/routers/api/v1/foundation/foundation.go new file mode 100644 index 0000000000..fa45c2478c --- /dev/null +++ b/routers/api/v1/foundation/foundation.go @@ -0,0 +1,32 @@ +// Copyright 2025 Milovann Yanatchkov +// SPDX-License-Identifier: GPL-3.0-or-later + +package foundation + +import ( + "net/http" + + api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/services/context" +) + +// Get Foundation ID +func GetVersions(ctx *context.APIContext) { + // swagger:operation GET /foundation/versions foundation foundationVersions + // --- + // summary: Get foundation versions + // produces: + // - application/json + // responses: + // "200": + // "$ref": "#/responses/Foundation" + // "401": + // "$ref": "#/responses/unauthorized" + // "403": + // "$ref": "#/responses/forbidden" + // "404": + // "$ref": "#/responses/notFound" + + f := api.Foundation{1, 1, "http", "http"} + ctx.JSON(http.StatusOK, f) +} diff --git a/routers/api/v1/swagger/foundation.go b/routers/api/v1/swagger/foundation.go new file mode 100644 index 0000000000..69e66ddd75 --- /dev/null +++ b/routers/api/v1/swagger/foundation.go @@ -0,0 +1,15 @@ +// Copyright 2025 Milovann Yanatchkov +// SPDX-License-Identifier: GPL-3.0-or-later + +package swagger + +import ( + api "code.gitea.io/gitea/modules/structs" +) + +// Foundation +// swagger:response Foundation +type swaggerResponseFoundation struct { + // in:body + Body api.Foundation `json:"body"` +} diff --git a/routers/web/web.go b/routers/web/web.go index 4d8d280c89..e975bccdf5 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -278,6 +278,7 @@ func Routes() *web.Route { if setting.API.EnableSwagger { // Note: The route is here but no in API routes because it renders a web page + routes.Get("/foundation", append(mid, misc.Swagger)...) // Render V1 by default routes.Get("/api/swagger", append(mid, misc.Swagger)...) // Render V1 by default routes.Get("/api/forgejo/swagger", append(mid, misc.SwaggerForgejo)...) } diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index f726176883..e762bf5b89 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -13,8 +13,8 @@ ], "swagger": "2.0", "info": { - "description": "This documentation describes the Forgejo API.", - "title": "Forgejo API", + "description": "This documentation describes the GitAec API.", + "title": "GitAec API", "license": { "name": "This file is distributed under the MIT license for the purpose of interoperability", "url": "http://opensource.org/licenses/MIT" @@ -1605,6 +1605,32 @@ } } }, + "/foundation/versions": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "foundation" + ], + "summary": "Get foundation versions", + "operationId": "foundationVersions", + "responses": { + "200": { + "$ref": "#/responses/Foundation" + }, + "401": { + "$ref": "#/responses/unauthorized" + }, + "403": { + "$ref": "#/responses/forbidden" + }, + "404": { + "$ref": "#/responses/notFound" + } + } + } + }, "/gitignore/templates": { "get": { "produces": [ @@ -18851,16 +18877,7 @@ ], "responses": { "200": { - "$ref": "#/responses/OrganizationList" - }, - "401": { - "$ref": "#/responses/unauthorized" - }, - "403": { - "$ref": "#/responses/forbidden" - }, - "404": { - "$ref": "#/responses/notFound" + "$ref": "#/responses/Foundation" } } } @@ -23799,6 +23816,31 @@ "type": "object", "x-go-package": "code.gitea.io/gitea/modules/forgefed" }, + "Foundation": { + "description": "Foundatoion Versions", + "type": "object", + "properties": { + "api_base_url": { + "type": "string", + "x-go-name": "BaseURL" + }, + "api_id": { + "type": "integer", + "format": "int64", + "x-go-name": "ID" + }, + "detailed_version": { + "type": "string", + "x-go-name": "DetailedVersion" + }, + "version_id": { + "type": "integer", + "format": "int64", + "x-go-name": "Version" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, "GPGKey": { "description": "GPGKey a user GPG key to sign commit and tag in repository", "type": "object", @@ -28156,6 +28198,12 @@ "$ref": "#/definitions/FilesResponse" } }, + "Foundation": { + "description": "Foundation", + "schema": { + "$ref": "#/definitions/Foundation" + } + }, "GPGKey": { "description": "GPGKey", "schema": {