Skip to content

[BUG][PYTHON] Deserialize on basic str fails since new version #18774

Description

@oricho123

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Hey. I've been using your openapi-generator for my app and It is great!

Since PR #18039 I've found a bug in the Python deserialization of a basic str.
The return value of each api_call that should return a basic str ('example') returns instead an str wrapped with quotes ('"example"'), as it misses the normally called json.loads.

I know where the problem is, please keep reading :)

openapi-generator version

v7.6.0

OpenAPI declaration file content or URL

Ran a basic generated GET function that called the api_clent. the response should be a str

This is the generated code

response_data = self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        response_data.read()
        return self.api_client.response_deserialize(
            response_data=response_data,
            response_types_map=_response_types_map,
        ).data
Generation Details

Generate a basic get in a service. For a Python library

Steps to reproduce

Generate a Python code from a service that returns a string,
Run a basic generated GET function that calls the api_clent. the response should be a str

Related issues/PRs

The specific line was introduced in PR #18039

More specifically- on file modules/openapi-generator/src/main/resources/python/api_client.mustache

Suggest a fix

Firstly, The function __deserialize_primitive(response_text, response_type)
on the file mentioned above, is getting a string representation of response_type, and not the type class as it must expect.
As of now, a TypeError is ALWAYS being thrown and caught when providing a string, and no deserialization happens.
So I guess it's needed to run before -

            # convert str to class
            if klass in self.NATIVE_TYPES_MAPPING:
                klass = self.NATIVE_TYPES_MAPPING[klass]
            else:
                klass = getattr(monday_code.models, klass)

In any case, I still don't think it will solve the problem, as the code will now run-

str('"example_value"')

And no json.loads will happen to remove the double quotes.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions