OpenAPITools / OpenAPITools/openapi-generator

[BUG][Elixir] --name-mappings is not applied to property names

Open
#18,661 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

The Elixir generator does not apply --name-mappings which are e.g. necessary to work around a field called _.

openapi-generator version

0e05cf26d94

OpenAPI declaration file content or url
openapi: '3.0.0'
info:
  version: 1.0.0
  title: test
paths:
  /test:
    get:
      summary: sample
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  _:
                    type: string
Generation Details
java -jar /home/val/.m2/repository/org/openapitools/openapi-generator-cli/7.6.0-SNAPSHOT/openapi-generator-cli-7.6.0-SNAPSHOT.jar generate -i spec.yaml -o undersc/ -g elixir --name-mappings _=underscore
Steps to reproduce

generate, see this:

  @derive Jason.Encoder
  defstruct [
    :_
  ]

  @type t :: %__MODULE__{
    :_ => String.t | nil
  }
==> test
Compiling 5 files (.ex)
    error: invalid use of _. _ can only be used inside patterns to ignore values and cannot be used in expressions. Make sure you are inside a pattern or change it accordingly
    │
 10 │   defstruct [
    │   ^^^^^^^^^^^
    │
    └─ lib/test/model/_test_get_200_response.ex:10: Jason.Encoder.Test.Model.TestGet200Response.encode/2
Related issues/PRs

#18398 for a default _ mapping in Python

Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the command in the issue with the provided OpenAPI declaration and inspect the generated lib/test/model/_test_get_200_response.ex output. Trace how --name-mappings is handled by the Elixir generator for model property names. Done means the generated Elixir model uses underscore for the mapped property and compiles successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir, openapi
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.