swagger-api / swagger-api/swagger-codegen

[Python] Code generator doesn't preserve original case for variables

Open
#12,505 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

We are using swagger codegen several years for Java and Node.JS projects and now implemented Python project.
We found codegen for Python doesn't preserve original names for models and variables, and converts them to underscored by default: petId => pet_id and in addition, supports or camel o pascal

But we want to preserve the case as it's working in Java/Javascript/Scala/C# based on CodegenConstants.MODEL_PROPERTY_NAMING_TYPE

Swagger-codegen version

2.4.41

Swagger declaration file content or url
  Repository:
    type: object
    description: A local repo configuration
    properties:
      repoName:
        type: string
        description: The local repo name
      location:
        type: string
        description: The local repo  location
      description:
        type: string
        description: The local repo description

  RepoResults:
    type: object
    description: List of local repositories configuration
    properties:
      RepoConfig:
        type: array
        items:
          $ref: '#/definitions/Repository'
Command line used for generation

Using maven with swagger-codegen-maven-plugin

<plugin>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>2.4.41</version>
                <executions>
                    <execution>
                        <id>python-swagger-client</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${basedir}/target/resources/services.yaml</inputSpec>
                            <output>${basedir}/target/generated_sources</output>
                            <templateDirectory>${basedir}/templates</templateDirectory>
                            <generateApiTests>false</generateApiTests>
                            <generateModelTests>false</generateModelTests>
                            <language>python</language>
                            <additionalProperties>
                                <property>case=camel</property>
                            </additionalProperties>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Steps to reproduce
  1. Create a model that can contain variables with different cases
  2. Generate python code
  3. Expects that python can parse JSON payload with original cases
Related issues/PRs

like these PR:
https://github.com/swagger-api/swagger-codegen/pull/6305
https://github.com/swagger-api/swagger-codegen/pull/8213

Suggest a fix/enhancement

Add support for "original" type for "case" property like done for camel/snake

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 with the Python generator entry point invoked by the swagger-codegen-maven-plugin and trace how the additionalProperties case value is handled. Compare the referenced pull requests for existing naming behavior. Done means a case=original option preserves model and variable names such as repoName in generated Python code.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.