swagger-api / swagger-api/swagger-codegen
[PYTHON] duplicated function arguments when model properties have dollar symbols
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When model properties have dollar symbols $, then the swagger-codegen strips out these characters.
This can lead to duplicated function arguments (and also duplicated class members) in the Python code.
E.g. when a model has the properties bar and $bar:
definitions:
Foo:
properties:
bar:
type: integer
$bar:
type: string
This creates a class with an __init__ method with duplicated parameters:
class Foo(object):
...
def __init__(self, bar=None, bar=None): # noqa: E501
self._bar = bar
self._bar = bar
Swagger-codegen version
2.4.17
and
3.0.23
Swagger declaration file content or url
Full swagger file: https://gist.github.com/jakobkogler/d54d50e8188adf70a668b70d087f8a7e
Command line used for generation
./run-in-docker.sh generate -i foo.yaml -l python -o /gen/foo
Steps to reproduce
- Download the swagger-file from the gist linked above.
- Run
./run-in-docker.sh generate -i foo.yaml -l python -o /gen/foo pip install -e foo- In a Python repl:
import swagger_clientfails because of duplicated function arguments
Related issues/PRs
https://github.com/swagger-api/swagger-codegen/issues/10276
https://github.com/swagger-api/swagger-codegen/issues/10447
Suggest a fix/enhancement
Looks like the dollar sign gets removed at https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java#L397
Not sure what a good solution is, maybe replace $ with _dollar_, if the stripped out variable name clashes with another one.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java around line 397 and reproduce with the linked gist, foo.yaml, and the run-in-docker.sh command. Check the generated Python model for collisions between bar and $bar; done means generation no longer creates duplicated arguments or class members and pip installation followed by import succeeds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, python
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100