Phoenix is renaming/mangling my variables

I am confused about the rules that are used. And a little bit about why they are used.

Case in point (1.30.-rc1):

$ mix phx.gen.json Odoo CustDB custdbs uuid:string ip:string size:integer

(At first I used Backend (the name of my app) instead of Odoo. But this resulted in all types of errors because an alias Backend.Backend was generated, which caused a mess.)

But anyway. This commandline (I need to specifiy single and plural, which is a good thing compared to Laravel with creates its own plurals like people for person) resulted in the following names being generated in my code:

defmodule Backend.Web. CustDBController

  def index(conn, _params) do
    custdbs = Odoo.list_custdbs()
    render(conn, "index.json", custdbs: custdbs)

Note the variable name custdbs. Ok, next function:

  def create(conn, %{"cust_db" => cust_db_params}) do
    with {:ok, %CustDB{} = cust_db} <- Odoo.create_cust_db(cust_db_params) do
      |> put_status(:created)
      |> put_resp_header("location", cust_db_path(conn, :show, cust_db))
      |> render("show.json", cust_db: cust_db)

Now suddenly underscores are used.
There is a file generated for the schema, with the name cust_db.ex
Unfortunately the convention with APIs is to use plurals (where in SQL databases it’s to use singulars for table names), so the process recommends adding /custdbs

So I have a few questions:

  • where does the underscore come from, and what are the heuristics to add it?
  • can I auto-generate singulars for my REST API because I just hate the plurals?


I belive the generator use this function to create the names.

I’m not sure how to tell the generator not to do this.