6

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 I encounter is that every endpoint returns empty data. The strange part is that when I debug the client, I can see the data via the inspector. Then in one step before the data is returned, it tries to deserialize the data and it returns a dictionary without any data inside.

return_data = response_data
if _preload_content:
    # deserialize response data
    if response_type:
        return_data = self.deserialize(response_data, response_type)

This is from the __call_api() function. When I inspect response_data, I can see it contains the data I need but deserialize() returns this: {'data': None, 'included': None, 'links': None, 'meta': None}

I know I could set the parameter _preload_content to false, but then I get the raw request response as a byte string and that kind of defeats the purpose of using a swagger client.

  • Is it a problem of the specs from my shop?
  • Is the codegen not working correctly?
  • Or is the python generator from swagger the problem?

EDIT:

I narrowed the problem down to the __init__() function of all the Response classes which all inherit from the Success class:

    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)

In the last step it calls the __init__() function of Success:

    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

Since data is not passed to the constructor of Success and there self.data gets overwritten with 'None'.

It seems the Python generator for swagger generates these constructors wrong. When I deleted the overwritten constructor in InlineResponse200156 it seemed to work, but since this issue is in all the generated classes that inherit success, I think the issue is in the generator itself.

Patrick Yoder
  • 1,065
  • 4
  • 14
  • 19
  • 2
    You may want to give [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator) a try as many top contributors of Swagger Codegen have switched to OpenAPI Generator instead. If I'm not mistaken, the `python` client generator has been refactored in the 5.x releases. Hope this helps. – NickSim Apr 12 '21 at 06:41
  • Did you find a solution? – Alex Jun 01 '21 at 18:00

0 Answers0