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

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

Open
cunningr opened this issue Oct 12, 2018 · 0 comments
Open

Comments

@cunningr
Copy link

cunningr commented Oct 12, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants