[API] Add Foundation
This commit is contained in:
parent
316bb86508
commit
9243fdf808
9 changed files with 129 additions and 20 deletions
2
Makefile
2
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
|
||||
|
|
|
|||
12
modules/structs/foundation.go
Normal file
12
modules/structs/foundation.go
Normal 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"`
|
||||
}
|
||||
|
|
@ -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() {
|
||||
|
|
@ -1668,6 +1673,7 @@ func Routes() *web.Route {
|
|||
m.Group("/topics", func() {
|
||||
m.Get("/search", repo.TopicSearch)
|
||||
}, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryRepository))
|
||||
|
||||
}, sudo())
|
||||
|
||||
return m
|
||||
|
|
|
|||
32
routers/api/v1/foundation/foundation.go
Normal file
32
routers/api/v1/foundation/foundation.go
Normal 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)
|
||||
}
|
||||
|
|
@ -68,13 +68,7 @@ func ListMyOrgs(ctx *context.APIContext) {
|
|||
// type: integer
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/OrganizationList"
|
||||
// "401":
|
||||
// "$ref": "#/responses/unauthorized"
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
// "$ref": "#/responses/Foundation"
|
||||
|
||||
listUserOrgs(ctx, ctx.Doer)
|
||||
}
|
||||
|
|
|
|||
15
routers/api/v1/swagger/foundation.go
Normal file
15
routers/api/v1/swagger/foundation.go
Normal 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"`
|
||||
}
|
||||
|
|
@ -178,6 +178,7 @@ func NormalRoutes() *web.Route {
|
|||
r.Use(common.ProtocolMiddlewares()...)
|
||||
|
||||
r.Mount("/", web_routers.Routes())
|
||||
//r.Mount("/foundation", apiv1.Routes())
|
||||
r.Mount("/api/v1", apiv1.Routes())
|
||||
r.Mount("/api/forgejo/v1", forgejo.Routes())
|
||||
r.Mount("/api/internal", private.Routes())
|
||||
|
|
|
|||
|
|
@ -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)...)
|
||||
}
|
||||
|
|
|
|||
72
templates/swagger/v1_json.tmpl
generated
72
templates/swagger/v1_json.tmpl
generated
|
|
@ -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": {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue