jsonapi-client icon indicating copy to clipboard operation
jsonapi-client copied to clipboard

Switching underscore for dashes

Open gklinich opened this issue 7 years ago • 1 comments

I don't understand the the reason for the 'jsonify_attribute_name' and 'dejsonify_attribute_name' function.

For example in our API we have meta data like this:

'meta': {'sp_version': '8.3', 'api': 'SP', 'api_version': '3', 'sp_build_id': 'HHHH'}

when trying to retrieve the the 'sp_version' with 'resp.meta.sp_version', None is return because the 'sp_version' attributed is jsonify to 'sp-version'.

AFAIK our meta data is valid per the jsonapi spec

gklinich avatar Aug 22 '17 22:08 gklinich

It is common convention to use dashes and not underscores in JSON API schemas. Specification itself does not take a stand on it, but this conversion takes place because of this convention, to ease python access to data that follows this convention.

In general you can access entities that have underscore in their name with index operator (res['some_underscore']) but Meta seems to lack this operator. That is easy to implement so I did this in 8324c68dba370c3908b184a64dc1483106364b7a.

Another option would be to make option to disable transformation alltogether to Session as an argument.

tuomas2 avatar Aug 23 '17 11:08 tuomas2