[Python/General] Underscore Conversion Method Does not Work with Acronyms

Open
#1,228 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java, python

Research direction

Start in DefaultCodegen.java and inspect the underscore method and its replacement patterns. Reproduce the issue with the provided SomeIDs/someIDs schema using standard Python client generation, then verify that acronym and initialism names receive underscores at the end of capital-letter sequences rather than between each capital.

Written by the indexing model from the issue text.

Description

Client: Python

This is copied over from swagger-codegen project as it exists in openapi-generator code also. This is the originally reported issue;

--------------------------copied over-------------------------------------

Description

In DefaultCodegen.java the underscore method does not work with acronyms, initialisms, or any multi capital letter phrases. This is because these lines of code:

// Replace capital letter with _ plus lowercase letter.
        word = word.replaceAll(firstPattern, replacementPattern);
        word = word.replaceAll(secondPattern, replacementPattern);

are designed to add an underscore before each capital letter (ignoring the first letter). For example, SomeIDs would be converted to some_i_ds instead of some_ids.

I discovered this bug while generating a Python client but presumably this issue exists in other languages.

Swagger-codegen version

2.4.0.SNAPSHOT up to date with PR 8748 (September 26th).

Swagger declaration file content or url

A model class similar to:

"SomeIDs": {
            "type": "object",
            "properties": {
                "someIDs": {
                    "type": "array",
                    "items": {
                        "type": "integer",
                        "format": "int32"
                    }
                }
            }
        }

in a Swagger schema will produce the bug.

Command line used for generation

The standard python client generation command will produce this bug.

Steps to reproduce

Generate Python Client from Swagger schema containing an acronym, initialisms, or any multi capital letter phrases
Look at corresponding name in Python client.
Related issues/PRs

Suggest a fix/enhancement

Changing the logic to place the underscores at the end of a series of capital letters instead of after each capital letter will solve this issue.

Dominant language
Java
Stars
26.8k
Forks
7.7k
Avg merge
1d 6h
Merged PRs (30d)
100

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.

More from OpenAPITools/openapi-generator

All issues in OpenAPITools/openapi-generator

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.