Bug Report Checklist
Description
Python specs that include an enum whose values are floats result in generating invalid enum member names since they cannot contain dots.
Example bad output:
class Type(int, Enum):
"""
Type
"""
"""
allowed enum values
"""
NUMBER_2.0 = 2.0
NUMBER_1.0 = 1.0
NUMBER_0.5 = 0.5
NUMBER_0.25 = 0.25
openapi-generator version
7.14.0
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: Sample API
description: API description in Markdown.
version: 1.0.0
paths:
/pony-sizes:
get:
summary: Returns all pony sizes.
description: Optional extended description in Markdown.
responses:
200:
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/PonySizes'
components:
schemas:
PonySizes:
type: object
properties:
type:
$ref: '#/components/schemas/Type'
Type:
type: float
enum:
- 2.0
- 1.0
- 0.5
- 0.25
Steps to reproduce
Run this command (YAML referenced is the same as what's in the previous section):
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate \
-i https://raw.githubusercontent.com/pcaisse/openapi-generator/refs/heads/master/modules/openapi-generator/src/test/resources/3_0/enum_float.yaml \
-g python \
-o /local/out/python
Then compile and note the syntax error:
python -m py_compile out/python/openapi_client/models/type.py
File "out/python/openapi_client/models/type.py", line 29
NUMBER_2.0 = 2.0
^^
SyntaxError: invalid syntax
Suggest a fix
I believe replacing all periods with the string "DOT" (eg. name = name.replace(".", "DOT");) here would fix the issue.
Bug Report Checklist
Description
Python specs that include an enum whose values are floats result in generating invalid enum member names since they cannot contain dots.
Example bad output:
openapi-generator version
7.14.0
OpenAPI declaration file content or url
Steps to reproduce
Run this command (YAML referenced is the same as what's in the previous section):
Then compile and note the syntax error:
Suggest a fix
I believe replacing all periods with the string "DOT" (eg.
name = name.replace(".", "DOT");) here would fix the issue.