Skip to content
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

Support member name transformers #17

Open
zachdaniel opened this issue Jun 7, 2020 · 4 comments
Open

Support member name transformers #17

zachdaniel opened this issue Jun 7, 2020 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@zachdaniel
Copy link
Contributor

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.

@zachdaniel zachdaniel added the enhancement New feature or request label Jun 7, 2020
@zachdaniel zachdaniel added the good first issue Good for newcomers label Sep 21, 2020
@mario-mazo
Copy link

mario-mazo commented Sep 26, 2020

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

@mario-mazo
Copy link

mario-mazo commented Sep 26, 2020

@zachdaniel I added our discussion here, so maybe other people can benefit.

I will try to do this

@mario-mazo mario-mazo self-assigned this Sep 26, 2020
@zachdaniel
Copy link
Contributor Author

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.

@mario-mazo
Copy link

I should be able to tackle this by in the next 3 weeks. If somebody can jump in soon just ping me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants