Skip to content

[BUG] [PYTHON] Inaccurate typing on API return values, query/path params, headers, etc. #16401

Open
@crossk3

Description

@crossk3

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

The python client generated by the openapi-generator for python using the asyncio library (probably it's library agnostic) generates a valid client with poor and/or incorrect typing. For example, in the given openapi-spec.json below, I have a schema called 'Contact' and two endpoints, one GET /v1/contacts/{id} that takes in a required string and returns Contact, and one GET /v1/contacts that returns a List[Contact].

The GET /v1/contacts/{id} typing incorrectly says id should be an object, but validly type annotates the return as Contact, while the GET /v1/contacts says the int query params should be object and annotates the type return as object instead of List[Contact] as expected.
image

Additionally, I have one Header param String-Header which is typed as a required string in the spec, but the generated client and documentation say it's an object not a string.
image

Other OpenAPI generators such as Redocly, Swagger all correctly type annotate the parameters and the return values, and I see in the generator code that it should be annotating List[Contact], but it doesn't seem to want to and instead defaults back to object.

openapi-generator version

docker v7.0.0-beta

OpenAPI declaration file content or url

openapi-spec.json

Generation Details

openapi-config.json

{
  "library": "asyncio",
  "packageName": "MyAPI",
  "projectName": "MyAPI",
  "packageVersion": "v0.1.0"
}
docker run --rm --user $UID:$GID -v $PWD:/local openapitools/openapi-generator-cli:v7.0.0-beta generate -i /local/openapi-spec.json -g python -o /local/python-client -c /local/openapi-config.json
Steps to reproduce
mkdir test-client
cd test-client
touch openapi-spec.json # write provided openapi-spec.json
touch openapi-config.json # write provided openapi-config.json
docker run --rm --user $UID:$GID -v $PWD:/local openapitools/openapi-generator-cli:v7.0.0-beta generate -i /local/openapi-spec.json -g python -o /local/python-client -c /local/openapi-config.json

And observe the generated client and generated documentation.

Related issues/PRs

I couldn't find anything immediately obvious in terms of related issues/PRs. Some more buggy-bugs where the code wasn't functional, but this is more of an improvement.

Suggest a fix

I couldn't seem to figure out exactly which file generates the API specification, but I suspect either the Schema object making it's way into DefaultCodegen is wrong, or it fails to match isArraySchema, or...? Happy to fix if someone can help me understand where the codegen actually happens 🙂

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions