-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better API documentation for packages #21637
Comments
|
There should be no need to call the endpoints in The documentation for the Gitea Package API can be found in the swagger section. |
IMO, maybe |
Yes, sorry, my mistake. Edited my comment.
|
@harryzcy Are your questions answered? Can this ticket be closed? |
It would be helpful to add these as comments where they are mounted and as comments on the functions e.g. PATCHdiff --git a/routers/api/packages/api.go b/routers/api/packages/api.go
index 6f53bc4ae..a600e1a5c 100644
--- a/routers/api/packages/api.go
+++ b/routers/api/packages/api.go
@@ -40,7 +40,9 @@ func reqPackageAccess(accessMode perm.AccessMode) func(ctx *context.Context) {
}
}
-func Routes(ctx gocontext.Context) *web.Route {
+// CommonRoutes provide endpoints for most package managers (excepting docker HUB - see below)
+// These are mounted on `/api/packages` (not `/api/v1/packages`)
+func CommonRoutes(ctx gocontext.Context) *web.Route {
r := web.NewRoute()
r.Use(context.PackageContexter(ctx))
@@ -301,7 +303,9 @@ func Routes(ctx gocontext.Context) *web.Route {
return r
}
-func ContainerRoutes(ctx gocontext.Context) *web.Route {
+// DockerContainerRoutes provides endpoints that match the Docker HUB API in order for facilitate downloading packages a docker packages
+// These have to be mounted on `/v2/...` due to compatibility with the Docker HUB API
+func DockerContainerRoutes(ctx gocontext.Context) *web.Route {
r := web.NewRoute()
r.Use(context.PackageContexter(ctx))
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index 0d11674aa..bd22fac18 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -1073,6 +1073,7 @@ func Routes(ctx gocontext.Context) *web.Route {
}, repoAssignment())
})
+ // NOTE: these are Gitea package management API - see packages.CommonRoutes and packages.DockerContainerRoutes for endpoints to see implementations of package manager APIs
m.Group("/packages/{username}", func() {
m.Group("/{type}/{name}/{version}", func() {
m.Get("", packages.GetPackage)
diff --git a/routers/init.go b/routers/init.go
index 53b33f468..cb5e3beb1 100644
--- a/routers/init.go
+++ b/routers/init.go
@@ -185,9 +185,15 @@ func NormalRoutes(ctx context.Context) *web.Route {
r.Mount("/", web_routers.Routes(ctx))
r.Mount("/api/v1", apiv1.Routes(ctx))
r.Mount("/api/internal", private.Routes())
+
if setting.Packages.Enabled {
- r.Mount("/api/packages", packages_router.Routes(ctx))
- r.Mount("/v2", packages_router.ContainerRoutes(ctx))
+ // Add endpoints to match common package manager APIs
+
+ // This implements package support for most package managers
+ r.Mount("/api/packages", packages_router.CommonRoutes(ctx))
+
+ // This implements Docker HUB API (Note this is not preceded by /api but is instead /v2)
+ r.Mount("/v2", packages_router.DockerContainerRoutes(ctx))
}
return r
}
|
In go-gitea#21637 it was mentioned that the purpose of the API routes for the packages is unclear. This PR adds some documentation. Fix go-gitea#21637 Signed-off-by: Andrew Thornton <art27@cantab.net>
Yes, my questions are cleared. |
Feature Description
Currently, the package registry APIs exists under several endpoints:
/api/v1/packages
,/api/packages
, and/v2
. It's not very clear how they are used and what's the difference between them.Screenshots
No response
The text was updated successfully, but these errors were encountered: