Bug Report Checklist
Description
The python-nextgen generator fails to generate an import for a schema property with a single entry in allOf and some further attributes (such as readOnly or nullable) on the property as opposed to the reference.
Affected:
- both references and inline objects; anything that results in a new module to import.
- true
readOnly and/or true nullable
Unaffected (generates a wrapper class (e.g., ParentChild) that gets imported):
anyOf, oneOf
- multiple entries in
allOf
- false/missing
readOnly and false/missing nullable
additionalProperties, description, properties, type, writeOnly; only existence of the attribute matters, not its value (e.g., even if it is the same or different in the reference).
Unaffected (imports an alias):
Unaffected (imports correctly (e.g., Child)):
Impact:
- That is how DRF Spectacular generates read-only/nullable references, for example.
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:
child:
allOf:
- $ref: '#/components/schemas/Child'
readOnly: true
Child:
type: object
properties:
property_of_child: {}
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
>>> from openapi_client import Parent
>>> Parent.from_dict(dict(child=dict(property_of_child=42)))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "openapi_client/models/parent.py", line 71, in from_dict
"child": Child.from_dict(obj.get("child")) if obj.get("child") is not None else None
NameError: name 'Child' is not defined
Related issues/PRs
Suggest a fix
Manually adding the import to parent.py:
from openapi_client.models.child import Child
Fixes deserialization:
>>> from openapi_client import Parent
>>> Parent.from_dict(dict(child=dict(property_of_child=42)))
Parent(child=Child(property_of_child=42))
This must be automated.
Bug Report Checklist
Description
The
python-nextgengenerator fails to generate an import for a schema property with a single entry inallOfand some further attributes (such asreadOnlyornullable) on the property as opposed to the reference.Affected:
readOnlyand/or truenullableUnaffected (generates a wrapper class (e.g.,
ParentChild) that gets imported):anyOf,oneOfallOfreadOnlyand false/missingnullableadditionalProperties,description,properties,type,writeOnly; only existence of the attribute matters, not its value (e.g., even if it is the same or different in the reference).Unaffected (imports an alias):
titleUnaffected (imports correctly (e.g.,
Child)):itemsImpact:
openapi-generator version
6.3.0-20230125.125049-89
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix
Manually adding the import to
parent.py:Fixes deserialization:
This must be automated.