OpenAPITools / OpenAPITools/openapi-generator
[BUG][PYTHON] AttributeError: module 'open_api_client' has no attribute 'Optional[str]'
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- [ x] Have you validated the input using an OpenAPI validator (example)?
- [x ] Have you tested with the latest master to confirm the issue still exists?
- [x ] 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)
This seems to be a pretty simple bug,
From generation it looks like its generating Optional[str] when the schema is items as str.
when deserializing the object it fails to find it under a base python type mapping
Suggest a fix
not sure the best method but what i did locally for now.
if klass.startswith('Optional['):
m = re.match(r'Optional\[(.*)]', klass)
assert m is not None, "Malformed Optional type definition"
klass = m.group(1)
\api_client.py", line 317, in response_deserialize
return_data = self.deserialize(response_text, response_type, content_type)
api_client.py", line 415, in deserialize
return self.__deserialize(data, response_type)
api_client.py", line 433, in __deserialize
return [self.__deserialize(sub_data, sub_kls)
\api_client.py", line 433, in <listcomp>
return [self.__deserialize(sub_data, sub_kls)
\api_client.py", line 447, in __deserialize
klass = getattr(openapi.models, klass)
AttributeError: module 'openapi.models' has no attribute 'Optional[str]'
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated api_client.py traceback, especially response_deserialize, deserialize, and __deserialize, then locate the OpenAPI Generator template or source that produces this logic. Reproduce the list deserialization case with an Optional[str] item type and add regression coverage showing that deserialization completes without the AttributeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100