[API] Add Foundation

This commit is contained in:
Milovann Yanatchkov 2025-01-11 20:27:58 +01:00
parent 316bb86508
commit 55d7f54e95
7 changed files with 126 additions and 13 deletions

View file

@ -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_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape}}/api/v1"|"basePath": "/api/v1"|g
SWAGGER_EXCLUDE := code.gitea.io/sdk SWAGGER_EXCLUDE := code.gitea.io/sdk
SWAGGER_NEWLINE_COMMAND := -e '$$a\' 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"| 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 TEST_MYSQL_HOST ?= mysql:3306

View file

@ -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"`
}

View file

@ -89,6 +89,7 @@ import (
"code.gitea.io/gitea/routers/api/shared" "code.gitea.io/gitea/routers/api/shared"
"code.gitea.io/gitea/routers/api/v1/activitypub" "code.gitea.io/gitea/routers/api/v1/activitypub"
"code.gitea.io/gitea/routers/api/v1/admin" "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/misc"
"code.gitea.io/gitea/routers/api/v1/notify" "code.gitea.io/gitea/routers/api/v1/notify"
"code.gitea.io/gitea/routers/api/v1/org" "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 { if setting.Federation.Enabled {
m.Get("/nodeinfo", misc.NodeInfo) m.Get("/nodeinfo", misc.NodeInfo)
m.Group("/activitypub", func() { m.Group("/activitypub", func() {

View file

@ -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)
}

View file

@ -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"`
}

View file

@ -278,6 +278,7 @@ func Routes() *web.Route {
if setting.API.EnableSwagger { if setting.API.EnableSwagger {
// Note: The route is here but no in API routes because it renders a web page // 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/swagger", append(mid, misc.Swagger)...) // Render V1 by default
routes.Get("/api/forgejo/swagger", append(mid, misc.SwaggerForgejo)...) routes.Get("/api/forgejo/swagger", append(mid, misc.SwaggerForgejo)...)
} }

View file

@ -13,8 +13,8 @@
], ],
"swagger": "2.0", "swagger": "2.0",
"info": { "info": {
"description": "This documentation describes the Forgejo API.", "description": "This documentation describes the GitAec API.",
"title": "Forgejo API", "title": "GitAec API",
"license": { "license": {
"name": "This file is distributed under the MIT license for the purpose of interoperability", "name": "This file is distributed under the MIT license for the purpose of interoperability",
"url": "http://opensource.org/licenses/MIT" "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": { "/gitignore/templates": {
"get": { "get": {
"produces": [ "produces": [
@ -18851,16 +18877,7 @@
], ],
"responses": { "responses": {
"200": { "200": {
"$ref": "#/responses/OrganizationList" "$ref": "#/responses/Foundation"
},
"401": {
"$ref": "#/responses/unauthorized"
},
"403": {
"$ref": "#/responses/forbidden"
},
"404": {
"$ref": "#/responses/notFound"
} }
} }
} }
@ -23799,6 +23816,31 @@
"type": "object", "type": "object",
"x-go-package": "code.gitea.io/gitea/modules/forgefed" "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": { "GPGKey": {
"description": "GPGKey a user GPG key to sign commit and tag in repository", "description": "GPGKey a user GPG key to sign commit and tag in repository",
"type": "object", "type": "object",
@ -28156,6 +28198,12 @@
"$ref": "#/definitions/FilesResponse" "$ref": "#/definitions/FilesResponse"
} }
}, },
"Foundation": {
"description": "Foundation",
"schema": {
"$ref": "#/definitions/Foundation"
}
},
"GPGKey": { "GPGKey": {
"description": "GPGKey", "description": "GPGKey",
"schema": { "schema": {