Skip to content

Commit d88d588

Browse files
authored
Replace periods with '_DOT_' in Python enum member names (#21372)
This is relevant for enums whose values are floats since without this step the enum is syntactically invalid. See: #21322
1 parent b57c23b commit d88d588

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,8 @@ public void setMapNumberTo(String mapNumberTo) {
10611061
}
10621062

10631063
public String toEnumVariableName(String name, String datatype) {
1064+
name = name.replace(".", "_DOT_");
1065+
10641066
if ("int".equals(datatype)) {
10651067
return "NUMBER_" + name.replace("-", "MINUS_");
10661068
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Sample API
4+
description: API description in Markdown.
5+
version: 1.0.0
6+
paths:
7+
/pony-sizes:
8+
get:
9+
summary: Returns all pony sizes.
10+
description: Optional extended description in Markdown.
11+
responses:
12+
200:
13+
description: OK
14+
content:
15+
application/json:
16+
schema:
17+
type: array
18+
items:
19+
$ref: '#/components/schemas/PonySizes'
20+
components:
21+
schemas:
22+
PonySizes:
23+
type: object
24+
properties:
25+
type:
26+
$ref: '#/components/schemas/Type'
27+
Type:
28+
type: float
29+
enum:
30+
- 2.0
31+
- 1.0
32+
- 0.5
33+
- 0.25

0 commit comments

Comments
 (0)