Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #14523
Closed
Open
Issue created Jan 25, 2023 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG] [python-nextgen] Deserialization with singular allOf and readOnly fails due to missing import

Created by: TimoGuenther

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-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):

  • title

Unaffected (imports correctly (e.g., Child)):

  • items

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.

Assignee
Assign to
Time tracking