Skip to content

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

@ShemTovYosef

Description

@ShemTovYosef
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:
#6305
#8213

Suggest a fix/enhancement

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions