Bug Report Checklist
Description
The python-nextgen generator assumes the existence of (from|to)_(dict|json) methods on generated enums, which causes enum (de)serialization to fail with an exception.
Affected:
- singular
allOf: The parent expects (from|to)_dict from the enum.
anyOf, oneOf, plural allOf: The composite model expects (from|to)_(dict|json) from the wrapped enum(s).
Impact:
openapi-generator version
6.3.0-20230125.125049-89
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: ""
version: ""
paths: {}
components:
schemas:
Parent:
type: object
properties:
number:
allOf:
- $ref: '#/components/schemas/Number'
Number:
enum:
- one
- two
- three
type: string
Generation Details
java -jar openapi-generator-cli-6.3.0-20230125.125049-89.jar generate -i openapi-schema.yaml -g python-nextgen
Steps to reproduce
Assuming the import problem described in #14523 is fixed:
>>> from openapi_client import Parent, Number
>>> Parent.from_dict(dict(number="one"))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "openapi_client/models/parent.py", line 73, in from_dict
"number": Number.from_dict(obj.get("number")) if obj.get("number") is not None else None
AttributeError: type object 'Number' has no attribute 'from_dict'
>>> Parent(number=Number.ONE).to_dict()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "openapi_client/models/parent.py", line 60, in to_dict
_dict['number'] = self.number.to_dict()
AttributeError: 'Number' object has no attribute 'to_dict'
Related issues/PRs
Suggest a fix
Manually replacing the from_dict call with an enum value lookup (by calling the enum class directly) and removing the block that calls to_dict on the enum from parent.py fixes (de)serialization for singular allOf:
>>> from openapi_client import Parent, Number
>>> Parent.from_dict(dict(number="one"))
Parent(number=<Number.ONE: 'one'>)
>>> Parent(number=Number.ONE).to_dict()
{'number': <Number.ONE: 'one'>}
This must be automated.
The fix for composite models seems more involved (e.g., checking for existence of the required methods on the wrapped value).
Alternatively, the enums could feature trivial implementations of the required methods.
Bug Report Checklist
Description
The
python-nextgengenerator assumes the existence of(from|to)_(dict|json)methods on generated enums, which causes enum (de)serialization to fail with an exception.Affected:
allOf: The parent expects(from|to)_dictfrom the enum.anyOf,oneOf, pluralallOf: The composite model expects(from|to)_(dict|json)from the wrapped enum(s).Impact:
openapi-generator version
6.3.0-20230125.125049-89
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Assuming the import problem described in #14523 is fixed:
Related issues/PRs
Suggest a fix
Manually replacing the
from_dictcall with an enum value lookup (by calling the enum class directly) and removing the block that callsto_dicton the enum fromparent.pyfixes (de)serialization for singularallOf:This must be automated.
The fix for composite models seems more involved (e.g., checking for existence of the required methods on the wrapped value).
Alternatively, the enums could feature trivial implementations of the required methods.