-
Notifications
You must be signed in to change notification settings - Fork 78
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
Add option to exclude keys from underscore/dash treatment? #132
Comments
@wasnotrice does |
@doomspork if the api used underscored keys, then yes, it would. The problem is that the api's response keys are dashed, but one of my values Does that make more sense? |
@wasnotrice I don't think I'm following sorry 😞 The If your API is already giving you dashes and you're returning dashes without the help of ` |
@doomspork sorry I don't think I'm doing a very good job of explaining :) The api is generated with this library, so the reason that the keys are dashed in the first place is that I have But given that my api serves responses with dashed keys, when some of my fields are arbitrary JSON, I don't want the library to descend into that arbitrary JSON and dash the keys there, too. I want to say something like "transform keys to dashes in this map, but skip the value of |
Ah ha! I follow now. I'm not 💯on how best to accomplish this though 🤔 Maybe we could support 4 options for Something like: underscore_to_dash:
except: [:__finalized__] Maybe |
Thanks for sticking with me :) Sure, I think The other potential confusion is whether the I'll tinker with it. It'll be easier to talk about with an implementation and test. |
Sounds good to me @wasnotrice, a PR would be a great place to start 👍 |
@wasnotrice I think
Lmk what you think! |
Hello! I just came across this issue, and it's a problem that applies to me also. I'm maintaining an API where I'd like the field keys to be dasherized, but some attribute values are arbitrary JSON objects whose keys I'd like to not be dasherized. The spec says in section 7.2.2.1 "Attributes":
To me, this seems to make a separation between the format of the JSON:API document and the values of attributes, whose format is arbitrary. I think it would make sense for a config option that transforms field keys, but doesn't change attribute values. This would let library users benefit from the field transformation config, but still have control over the format of the attribute values. Any thoughts on this approach? I'm happy to work on an implementation if it makes sense. |
@protestContest I am at least initially liking your idea. To me, it's nice if the options for "dash conversion" are fairly high level (i.e. operate on everything or operate on everything except attributes) because we do all have the option to turn the feature off and do our own transformation outside of this library. In other words, I think trying to support increasingly niche controls reaches diminishing returns from the perspective of maintaining this library. I'd be interested in reviewing a PR from you that allowed for excluding everything nested within attributes from transformation. |
I'll call this issue closed by #310 but if anyone wants to have it re-opened (or possibly even better open a new targeted ticket) because your needs aren't covered by what's available so far, please do. |
I'm working with an API where I have a field
data_schema
that is an arbitrary JSON object. The API uses the dashed key format, so it shows up in requests/responses asdata-schema
. This is all fine until someone includes an underscore in one of their JSON object keys, such as__finalized__
. So my incoming datagets transformed into
(this is surprising to the people who used the leading underscores to indicate "don't mess with this") Ideally, the value of
data-schema
would not be touched at all. I'm not sure how we could accomplish that simply. But I wonder if it makes sense to add an underscore option that specifies field prefixes or patterns that would not be underscored/dashed? Any thoughts?The text was updated successfully, but these errors were encountered: