clearlydefined / clearlydefined/service

ClearlyDefined could not support Go component with more than 5 '/' in the module path

Open
#909 12 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
51
Forks
46
PR merge metrics
No merged PRs in 30d

Description

The route here, [router.get('/definitions/:type/:provider/:namespace/:name/:revision/:extra1?/:extra2?/:extra3?')](https://github.com/clearlydefined/service/blob/0d00f25fa21587693ef6a703db5b4e542eadfaf6/routes/definitions.js#L23), is added for Go component support. For example, the Go component, named `github.com/quasilyte/regex/syntax@v0.0.0-20200407221936-30656e2c4a95`, will translate to `Get /defintions/go/golang/github.com/quasilyte/regex/syntax/v0.0.0-20200407221936-30656e2c4a95`. And all the params are parsed like: `type=go, provider=golang, namespace=github.com,name=quasilyte, revision=syntax, extra1=v0.0.0-20200407221936-30656e2c4a95`. Then ClearlyDefined is trying to create a go coordinate based on this [logic](https://github.com/clearlydefined/service/blob/0d00f25fa21587693ef6a703db5b4e542eadfaf6/lib/utils.js#L65).

However, the`extra1, extra2, extra3` is not extensible because it will not work for the Go component with a module path that has more than 4 slashes, like `github.com/azure/go-autorest/autorest/azure/cli@v0.4.2`.

After some discussion with the community, there are two options.
Option1, use express regex route to replace `/definitions/:type/:provider/:namespace/:name/:revision/:extra1?/:extra2?/:extra3?` with `/:type/:provider/:namespace/:name/:revision/*`and we could get all extras from `req.params[0]`.
Pro:
1. Don't change the existing API.
2. Simple to fix.

Con:
1. It's still a hacky way.

Option2, add another route `/definitions?type=type&provider=provider&namespace=namespace&name=name&revision=revision`. All the parameters are moved from path params to query params because param params could support any characters by url encoding.
Pro:
1. Long-term solution and more extensible. In the future, it could support scenarios when the name or provider also contains slashes.

Con:
1. An extra API to get a definition may confuse the community.
2. Probably needs to do some API versioning which we may need to do some extra work.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.