Open zachdaniel opened 4 years ago
Steps:
step 1
will be adding an optional configuration to this schema
https://github.com/ash-project/ash_json_api/blob/master/lib/ash_json_api/api/api.ex
called member_name_transformer
step 2
then you need to make a behaviour module called AshJsonApi.MemberNameTransformer
that behaviour should have two callbacks. I think the first one should be called transform_in(string
) and the other should be transform_out(string)
This would be an example of a transformer we'd probably provide by default
defmodule AshJsonApi.MemberNameTransformer.CamelCase do
@behaviour AshJsonAPi.MemberNameTransformer
def transform_out(snake_case) do
convert_snake_case_to_camelcase(snake_case)
end
def transform_in(camel_case) do
convert_camel_case_to_snake_case(camel_case)
end
end
I mean, also maybe member_name_transformer
is a bad name, it could just be like...key_transformer
or something, feel free to propose less confusing names
@zachdaniel I added our discussion here, so maybe other people can benefit.
I will try to do this
Good call putting the chat here 👍 The final step of this will be to use the member name transformer throughout the application. Specifically, in AshJsonApi.Request
, where we parse the input, AshJsonApi.Serializer
where we form our responses, and AshJsonApi.JsonSchema
which is used as validation and documentation.
I should be able to tackle this by in the next 3 weeks. If somebody can jump in soon just ping me!
Currently, everything is
snake_case
but we want to let users configure a name transformer at the API level, to turn everything into kebab case or camelcase.