Bad links with engine mounted as root
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
Research direction
Start in lib/jsonapi/link_builder.rb at resource_url, then inspect how engine_mount_point is computed for an engine mounted at '/'. Reproduce the reported root-mounted case and verify that the generated self link has one leading slash rather than '//v1/users/...'; the existing link-building behavior should remain correct for non-root mounts.
Written by the indexing model from the issue text.
Description
This issue is a (choose one):
- Problem/bug report.
- Feature request.
- Request for support. Note: Please try to avoid submitting issues for support requests. Use Gitter instead.
Checklist before submitting:
- I've searched for an existing issue.
- I've asked my question on Gitter and have not received a satisfactory answer.
- I've included a complete bug report template. This step helps us and allows us to see the bug without trying to reproduce the problem from your description. It helps you because you will frequently detect if it's a problem specific to your project.
- The feature I'm asking for is compliant with the JSON:API spec.
Description
As described on lib/jsonapi/link_builder.rb#L139,
def resource_url(source)
"#{ base_url }#{ engine_mount_point }#{ resource_path(source) }"
end
But in this case:
constraints subdomain: 'api' do
mount MyEngine::Engine, at: '/' if defined?(MyEngine::Engine)
end
This creates a double / due to root value of engine_mount_point.
I guess a little update of:
@engine_mount_point = @engine ? @engine.routes.find_script_name({}) : ""
should be enough.
Current result:
{
"data": {
"id": "ed526d56-cc7e-41f4-8e99-fccf73fb7500",
"type": "users",
"links": {
"self": "//v1/users/ed526d56-cc7e-41f4-8e99-fccf73fb7500"
},
"attributes": {
"first_name": null,
"last_name": null,
"email": "[email protected]"
}
}
}
//v1/users/ed526d56-cc7e-41f4-8e99-fccf73fb7500 should be /v1/users/ed526d56-cc7e-41f4-8e99-fccf73fb7500
- Dominant language
- Ruby
- Stars
- 2.3k
- Forks
- 546
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from JSONAPI-Resources/jsonapi-resources
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
Difficulty 3/5 1-2 days Newbie friendliness 50/100
JSONAPI-Resources/jsonapi-resources#1488 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
JSONAPI-Resources/jsonapi-resources#1479 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
JSONAPI-Resources/jsonapi-resources#1477 · 3 comments · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
All issues in JSONAPI-Resources/jsonapi-resources
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
TheOdinProject/curriculum#31423 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
oxidize-rb/rb-sys#807 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
ai-generated
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100