swagger-api / swagger-api/swagger-codegen-generators
[Python] Success constructor overwrites data
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
i have generated a python client via the swagger-codegen-cli (v3) docker image in my GitLab ci pipline for a Shopware 6 shop.
The problem is that the client overwrites the data befor returning it and it seems to be a problem in the generated constructor.
def __init__(self, data=None, links=None, *args, **kwargs): # noqa: E501
"""InlineResponse200156 - a model defined in Swagger""" # noqa: E501
self._data = None
self._links = None
self.discriminator = None
if data is not None:
self.data = data
if links is not None:
self.links = links
Success.__init__(self, *args, **kwargs)
I think the calll to the init() function of the parent class Success is either at the wrong place or the init() function of Success is wrong. In both init() functions the self._data gets initialized to None and even if the first init() (from the code above) sets the data to the data from my shop when the parent function is called it gets overwritten with None.
for referenc here is the init() function from the Success class:
def __init__(self, meta=None, links=None, data=None, included=None): # noqa: E501
"""Success - a model defined in Swagger""" # noqa: E501
self._meta = None
self._links = None
self._data = None
self._included = None
self.discriminator = None
if meta is not None:
self.meta = meta
if links is not None:
self.links = links
self.data = data
if included is not None:
self.included = included
This problem is in all classes in my model that inherent Success and one solution would be to change it that the init() call to the parent would be called befor the data is set.
Like so:
def __init__(self, data=None, links=None, *args, **kwargs): # noqa: E501
"""InlineResponse200156 - a model defined in Swagger""" # noqa: E501
Success.__init__(self, *args, **kwargs)
self._data = None
self._links = None
self.discriminator = None
if data is not None:
self.data = data
if links is not None:
self.links = links
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 with the generated InlineResponse200156 and Success constructors shown in the issue, then trace back to the generator template that produces inherited Python model constructors. Reproduce the overwrite with a Shopware 6 response and confirm that generated subclasses preserve their data after parent initialization.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100