You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[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
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
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
Bug Report Checklist
Description
The template code for python imports using
classVarName
in a few spots, which can differ fromclassFilename
, resulting in invalid imports for a component containing double underscores. I think both these spots should use classFilename insteadopenapi-generator/modules/openapi-generator/src/main/resources/python/model_generic.mustache
Line 21 in dc175c5
openapi-generator/modules/openapi-generator/src/main/resources/python/model_generic.mustache
Line 264 in dc175c5
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:
Related issues/PRs
Suggest a fix
#20273
The text was updated successfully, but these errors were encountered: