clj-commons/camel-snake-kebab

Handle namespaced keywords

Closed this issue · 3 comments

This bit us when using friend and its namespaced keywords:

cemerick.friend=> (->kebab-case ::identity)
;=> :identity
cemerick.friend=> ::identity
;=> :cemerick.friend/identity
cemerick.friend=> (= ::identity :identity)
;=> false

Of course we wouldn't do this directly, but there was a middleware kebab-casing all the request map keys, so we lost the keyword namespace information, making for some tricky debugging.

It would be nice if (->kebab-case :cemerick.friend/identity) was just :cemerick.friend/identity. Related:

cemerick.friend=> (->kebab-case "cemerick.friend/identity")
"cemerick-.friend-/identity"

I'm not sure if . and / should be treated specially or not, but I'm guessing this would affect any potential fix.

I'm considering avoiding this issue by making the library reject namespaced keywords/symbols with an exception. Would you find that acceptable? It would force you to shift the kebab-casing middleware to before cemerick/friend in the stack.

btw: I'm sorry for causing the tricky debugging session.

Yeah, an exception would have been preferable for my specific use case here. I think I'd worry that other users would find it surprising to have an exception thrown unless this was a well-documented part of the library's contract anytime it encountered special things (the behavior translating "ohai.core" to "ohai-.core" was also quite surprising to me, but doesn't really feel exception-worthy).

No worries on the debug time - we sorted it out and found a good solution.

OK, then I'll probably solve it that way and make sure to document it.

the behavior translating "ohai.core" to "ohai-.core" was also quite surprising to me, but doesn't really feel exception-worthy

The expected input domain is that of a single identifier; the behavior with multiple identifiers (separated by '.' or '/') is undefined…

I'd vote on adding exception-raising input validation if the functions weren't expected to handle strings coming from the outside world. I'll settle with documenting this behavior for now.