diff --git a/internal/api/api.go b/internal/api/api.go
index 4fc8658..3583dab 100644
--- a/internal/api/api.go
+++ b/internal/api/api.go
@@ -137,6 +137,14 @@
return err
}
+ if um.ModulePath != modulePath {
+ return &Error{
+ Code: http.StatusBadRequest,
+ Message: fmt.Sprintf("%s is a package, not a module", modulePath),
+ Fixes: []string{fmt.Sprintf("retry the call with the containing module: %q", um.ModulePath)},
+ }
+ }
+
// api:response Module
resp := Module{
Path: um.ModulePath,
diff --git a/internal/tests/api/api_test.go b/internal/tests/api/api_test.go
index 2b02e7e..627d1f2 100644
--- a/internal/tests/api/api_test.go
+++ b/internal/tests/api/api_test.go
@@ -540,7 +540,7 @@
u := unit("")
u.Readme = &internal.Readme{Filepath: "README.md", Contents: "Hello world"}
- ds.MustInsertModule(t, module(t, mi1, u))
+ ds.MustInsertModule(t, module(t, mi1, u, unit("pkg")))
mi2 := modinfo(modulePath, "v1.2.4")
mi2.HasGoMod = true
@@ -598,6 +598,15 @@
want: &api.Error{Code: 404, Message: "not found"},
},
{
+ name: "package path in module endpoint",
+ url: "/v1beta/module/example.com/pkg?version=v1.2.3",
+ wantStatus: http.StatusBadRequest,
+ want: &api.Error{
+ Code: http.StatusBadRequest,
+ Message: "example.com/pkg is a package, not a module",
+ },
+ },
+ {
name: "missing module path",
url: "/v1beta/module/",
wantStatus: http.StatusBadRequest,