Skip to content

[python] required fields  #6291

Open
Open
@InoMurko

Description

@InoMurko

Python generated client model does not appear to be working for required parameters and reports that None is being passed for required parameters name and catalog_id:

`ERROR: test_backoffice_api_merchant_ad_controller_show (test.test_ad_api.TestAdApi)

Traceback (most recent call last):
File "/opt/priv/backoffice/swagger/test/test_ad_api.py", line 99, in test_backoffice_api_merchant_ad_controller_show
api_response = api_instance.backoffice_api_merchant_ad_controller_show(merchant_id=5, authorization=auth, ad_id=id)
File "/opt/priv/backoffice/swagger/swagger_client/apis/ad_api.py", line 298, in backoffice_api_merchant_ad_controller_show
(data) = self.backoffice_api_merchant_ad_controller_show_with_http_info(merchant_id, ad_id, authorization, **kwargs)
File "/opt/priv/backoffice/swagger/swagger_client/apis/ad_api.py", line 383, in backoffice_api_merchant_ad_controller_show_with_http_info
collection_formats=collection_formats)
File "/opt/priv/backoffice/swagger/swagger_client/api_client.py", line 327, in call_api
_return_http_data_only, collection_formats, _preload_content, _request_timeout)
File "/opt/priv/backoffice/swagger/swagger_client/api_client.py", line 158, in __call_api
return_data = self.deserialize(response_data, response_type)
File "/opt/priv/backoffice/swagger/swagger_client/api_client.py", line 240, in deserialize
return self.__deserialize(data, response_type)
File "/opt/priv/backoffice/swagger/swagger_client/api_client.py", line 280, in __deserialize
return self.__deserialize_model(data, klass)
File "/opt/priv/backoffice/swagger/swagger_client/api_client.py", line 621, in __deserialize_model
instance = klass()
File "/opt/priv/backoffice/swagger/swagger_client/models/ad_show_response.py", line 93, in init
self.name = name
File "/opt/priv/backoffice/swagger/swagger_client/models/ad_show_response.py", line 275, in name
raise ValueError("Invalid value for name, must not be None")
ValueError: Invalid value for name, must not be None
`

Swagger-codegen version

v2.2.3

https://gist.github.com/InoMurko/ce6aa8b938eca3124fc46f3cdddaf8f1

Command line used for generation

python -m unittest discover -s "priv/backoffice/swagger"

The generated model in Python:
`
def init(self, type=None, thumb=None, strength=None, status=None, start_date=None, product_id=None, name=None, id=None, expires=None, description=None, category_id=None, auto_renew=None):
"""
AdShowResponse - a model defined in Swagger
"""

    self._type = None
    self._thumb = None
    self._strength = None
    self._status = None
    self._start_date = None
    self._product_id = None
    self._name = None
    self._id = None
    self._expires = None
    self._description = None
    self._category_id = None
    self._auto_renew = None

    if type is not None:
      self.type = type
    if thumb is not None:
      self.thumb = thumb
    if strength is not None:
      self.strength = strength
    if status is not None:
      self.status = status
    if start_date is not None:
      self.start_date = start_date
    if product_id is not None:
      self.product_id = product_id
    self.name = name
    if id is not None:
      self.id = id
    if expires is not None:
      self.expires = expires
    if description is not None:
      self.description = description
    self.category_id = category_id
    if auto_renew is not None:
      self.auto_renew = auto_renew

`
The generated model in PHP:

/** * Constructor * @param mixed[] $data Associated array of property values initializing the model */ public function __construct(array $data = null) { $this->container['type'] = isset($data['type']) ? $data['type'] : null; $this->container['thumb'] = isset($data['thumb']) ? $data['thumb'] : null; $this->container['strength'] = isset($data['strength']) ? $data['strength'] : null; $this->container['status'] = isset($data['status']) ? $data['status'] : null; $this->container['start_date'] = isset($data['start_date']) ? $data['start_date'] : null; $this->container['product_id'] = isset($data['product_id']) ? $data['product_id'] : null; $this->container['name'] = isset($data['name']) ? $data['name'] : null; $this->container['id'] = isset($data['id']) ? $data['id'] : null; $this->container['expires'] = isset($data['expires']) ? $data['expires'] : null; $this->container['description'] = isset($data['description']) ? $data['description'] : null; $this->container['category_id'] = isset($data['category_id']) ? $data['category_id'] : null; $this->container['auto_renew'] = isset($data['auto_renew']) ? $data['auto_renew'] : null; }

it looks like theres a discrepancy on how required parameters are handled which is causing weird behaviour. I have indeed checked whether the server responds with the correct data (and it does).

{'category_id': 1, 'description': 'none', 'id': 623, 'name': 'my ad for fucks sake', 'product_id': 1, 'type': 'Image watermark'}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions