Skip to content

[BUG] [PYTHON] Circular imports on AllOf generation with REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=True #18271

Closed
@zishunwei

Description

@zishunwei

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

When enabling REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=True for a AllOf generation, the circular imports error occurs if two schemas refer to each other (like #/components/schemas/Info and #/components/schemas/InfoProperty in spec)

openapi-generator version

Latest master code until 02 April 2024

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: ""
  version: ""
paths:
  /user/getInfo:
    get:
      operationId: getUserInfo
      parameters:
        - description: user time
          explode: false
          in: path
          name: id
          required: true
          schema:
            type: string
          style: simple
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Info'
          description: |
            OK
      security:
        - Session: []
      x-accepts: application/json
components:
  schemas:
    Info:
      allOf:
        - $ref: '#/components/schemas/Base'
      properties:
        nameA:
          type: string
        nameB:
          type: string
        property:
          items:
            $ref: '#/components/schemas/InfoProperty'
          type: array
      type: object
    Base:
      example:
        _typeName: _typeName
      properties:
        _typeName:
          type: string
      required:
        - _typeName
      type: object
    InfoProperty:
      allOf:
        - $ref: '#/components/schemas/Base'
      properties:
        Info:
          items:
            $ref: '#/components/schemas/Info'
          type: array
      type: object
Generation Details

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i demo.yaml -g python -o /demo --openapi-normalizer REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true

Steps to reproduce

Import the generated open_client will throw the circular imports error

Related issues/PRs
Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions