Description
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.
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
.
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
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 🙂