-
Notifications
You must be signed in to change notification settings - Fork 186
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
fix: Multi-word custom endpoint not respecting route format #400
fix: Multi-word custom endpoint not respecting route format #400
Conversation
Hey @gaorlov 👋 giving this one a bump for you to take a look 🙏 |
What's the current blocker for merging this one? 🙏 |
Hello! Thanks for taking the time to contribute! I'll take a closer look tomorrow. I'm the meantime, can you please add an entry to the changelog? Thanks! Greg |
@gaorlov updated the changelog! 🙏 |
@gaorlov small bump! 🙂 |
@sebasjimenez10 sorry about the delay. For reasons i don't yet understand the automated testing has stopped working. I'm working with the owners of the I appreciate your patience! Greg |
@gaorlov thank you so much for looking into it. No worries on the wait, I'm glad to contribute 🙏🏻 |
Hey @gaorlov, just dropping by and giving this one a bump! 🙏 |
Hey @gaorlov, hope you're doing good! Just wanted to bump this one! |
🙏 |
@@ -348,6 +350,17 @@ def _build_connection(rebuild = false) | |||
yield(conn) if block_given? | |||
end | |||
end | |||
|
|||
def _name_for_route_format(name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be a method on name
? like name.to_route(route_format)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gaorlov name here is a Symbol, that would require a big refactor in other places as well and I believe that to be out of scope for this PR. But happy to discuss further to continue contributing 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you do like
module Routable
def to_route(format: :dasherized_route)
case format
when :dasherized_route
to_s.dasherize
when :camelized_route
to_s.camelize(:lower)
else
self
end
end
end
class Symbol
include Routable
end
and then you can have name.to_route(route_format)
and not have to do anything else to the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! thanks for contributing!
Please merge in main to get tests running in the PR
Thanks!
f0171fb
to
8e07765
Compare
8e07765
to
9cf3d0f
Compare
@gaorlov done! Just rebased on top of |
@gaorlov small bump! |
@gaorlov tiny bump on this one! 🙏 |
thank you for you contributions and patience! |
This PR fixes an issue I experienced when working with multi-word custom endpoints. If you have a multi-word custom endpoint and you also have the
self.route_format = :dasherized_route
config in your base class, upon calling thatcustom_endpoint
JsonApiClient doesn't respect the configuration selected and will use the underscored version of the endpoint name.For instance:
Given,
When calling
Pet.vip_pets
orpet = Pet.new(...); pet.related_pets
the resulting endpoint being called will be either:http://example.com/pets/vip_pets
orhttp://example.com/pets/:id/related_pets
instead of
http://example.com/pets/vip-pets
orhttp://example.com/pets/:id/related-pets
Same issue applies for
camelized_routes
.This PR fixes this by checking the
route_format
configuration attribute and making sure it is converted to the appropriate endpoint name, usingActiveSupport
helper methods.The methods defined in the instance of the class will still be underscored, so that we can still do
Pet.vip_vets
.Happy to address any concerns or comments, thanks!