Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [PYTHON] Invalid code generated for polymorphism when name has double underscores #20272

Open
5 of 6 tasks
YousefHaggy opened this issue Dec 8, 2024 · 0 comments · May be fixed by #20273
Open
5 of 6 tasks

[BUG] [PYTHON] Invalid code generated for polymorphism when name has double underscores #20272

YousefHaggy opened this issue Dec 8, 2024 · 0 comments · May be fixed by #20273

Comments

@YousefHaggy
Copy link

YousefHaggy commented Dec 8, 2024

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 template code for python imports using classVarName in a few spots, which can differ from classFilename, resulting in invalid imports for a component containing double underscores. I think both these spots should use classFilename instead

from {{packageName}}.models.{{model.classVarName}} import {{modelName}}

return import_module("{{packageName}}.models.{{model.classVarName}}").{{modelName}}.from_dict(obj)

openapi-generator version
OpenAPI declaration file content or url
Generation Details
Steps to reproduce

Just run python generator with repro spec and look at the Dog__cool import from_dict imports in animal.py
openapi-generator generate -i spec.yaml -g python -o python_client

Repro spec:

openapi: 3.1.0
info:
  title: Animal API
  version: 1.0.0
paths:
  /animals:
    get:
      summary: Get a list of animals
      operationId: getAnimals
      responses:
        '200':
          description: A list of animals
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Animal'
            
components:
  schemas:
    Animal:
      type: object
      discriminator:
        propertyName: type
      required:
        - type
      properties:
        type:
          type: string
          description: The type of the animal
          enum:
            - Cat
            - Dog
        name:
          type: string
          description: The name of the animal
        age:
          type: integer
          description: The age of the animal
          
    Cat:
      type: object
      allOf:
        - $ref: '#/components/schemas/Animal'
        - properties:
            breed:
              type: string
              description: The breed of the cat
            color:
              type: string
              description: The color of the cat
            isIndoor:
              type: boolean
              description: Whether the cat is indoor or outdoor

    Dog__Cool:
      type: object
      allOf:
        - $ref: '#/components/schemas/Animal'
        - properties:
            breed:
              type: string
              description: The breed of the dog
            size:
              type: string
              description: The size of the dog (e.g., small, medium, large)
            isTrained:
              type: boolean
              description: Whether the dog is trained
Related issues/PRs
Suggest a fix

#20273

@YousefHaggy YousefHaggy changed the title [BUG] [PYTHON] Invalid code generated for polymorphism when name has underscores [BUG] [PYTHON] Invalid code generated for polymorphism when name has double underscores Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant