swagger-api / swagger-api/swagger-codegen

[Python]Generated code has naming conflict

Open
#10,368 0 comments 1 reaction 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

The generated Python code renamed the camelCase property to under_score format and conflict with another property.

Swagger-codegen version

swagger-codegen-cli-2.4.14

Swagger declaration file content or url
definitions:
  RestrictedBanInfo:
    type: object
    required:
      - ban_type
    properties:
      ban_type:
        type: string
      banType:
        type: string
        description: the same value as ban_type
        readOnly: true
Command line used for generation

java -jar swagger-codegen-cli-2.4.14.jar generate -i swagger.json -g python --library asyncio -o ./

Steps to reproduce
  1. define an object with 2 properties. Using the camelCase and under_score case to name those 2 properties. e.g. xY and x_y
  2. generate python client code
  3. check generated model code
class RestrictedBanInfo(object):
    openapi_types = {
        'ban_type': 'str',
        'ban_type': 'str',
     }

    attribute_map = {
        'ban_type': 'ban_type',
        'ban_type': 'banType',
    }

    def __init__(self, ban_type=None, ban_type=None):
        ...

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

Reproduce the issue with the RestrictedBanInfo YAML definition and the swagger-codegen-cli-2.4.14 Python asyncio generation command. Inspect the generated model's openapi_types, attribute_map, and init; done means both ban_type and banType remain distinct properties without duplicate dictionary keys or constructor arguments.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.