swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.09k stars 6.03k forks source link

[PYTHON] Two patches in python-client/swagger_client/api_client.py #12345

Open mike-res opened 9 months ago

mike-res commented 9 months ago
Description

The code in python-client/swagger_client/api_client.py contains code for the ApiClient class.

I have found that two methods in the generated ApiClient class need to be patched in order ot ensure reliable operation:

         kwargs = {}
        if klass.swagger_types is not None:
           # ***** ADDED THE FOLLOWING LINE *****
            kwargs["_configuration"] = self.configuration
            for attr, attr_type in six.iteritems(klass.swagger_types):
                if (data is not None and
                        klass.attribute_map[attr] in data and
                        isinstance(data, (list, dict))):
                    value = data[klass.attribute_map[attr]]
                    kwargs[attr] = self.__deserialize(value, attr_type)
Swagger-codegen version

Unclear which version ie being used. I was using https://editor.swagger.io/) and https://editor-next.swagger.io/. Both of the online editors have the same issue.

Swagger declaration file content or url

No swagger: '2.0' code provided .. this issue is present in any code that the online python client generator produces.

Command line used for generation

used online editors (https://editor.swagger.io/) and https://editor-next.swagger.io/)

Steps to reproduce

Thiese issues are present in any python client produced by either https://editor.swagger.io/) and https://editor-next.swagger.io/.

Related issues/PRs
Suggest a fix/enhancement

Examples of preferred resulting code in the ApiClient::__deserialize_primitive(self, data, klass) and ApiClient::__deserialize_model(self, data, klass) methods appear above.

mike-res commented 9 months ago

I switched to using swagger-codegen-cli-2.4.39.jar so that I could generate client code automatically as part of our CI/CD flow, and the issues cited above are present in swagger-codegen-cli-2.4.39.jar .. hopefully that fills in some of the blanks for which versions of the code generator have this issue..