Skip to content

Commit

Permalink
Fix the post processing of enums in the Python generator, such that i…
Browse files Browse the repository at this point in the history
…t uses the proper variable namesfrom x-enum-varnames

Remove build artefacts
  • Loading branch information
0xMattijs committed May 6, 2024
1 parent 73f2d82 commit 84a7330
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,10 @@ private ModelsMap postProcessModelsMap(ModelsMap objs) {
enumVars.put("name", toEnumVariableName((String) enumVars.get("value"), "str"));
} else {
model.vendorExtensions.putIfAbsent("x-py-enum-type", "int");
enumVars.put("name", toEnumVariableName((String) enumVars.get("value"), "int"));
// Do not overwrite the variable name if already set through x-enum-varnames
if (model.vendorExtensions.get("x-enum-varnames") == null) {
enumVars.put("name", toEnumVariableName((String) enumVars.get("value"), "int"));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2060,6 +2060,35 @@ components:
enum:
- 1.1
- -1.2
enum_number_vendor_ext:
type: integer
format: int32
enum:
- 42
- 18
- 56
x-enum-descriptions:
- 'Description for 42'
- 'Description for 18'
- 'Description for 56'
x-enum-varnames:
- FortyTwo
- Eigtheen
- FiftySix
enum_string_vendor_ext:
type: string
enum:
- FOO
- Bar
- baz
x-enum-descriptions:
- 'Description for FOO'
- 'Description for Bar'
- 'Description for baz'
x-enum-varnames:
- FOOVar
- BarVar
- bazVar
outerEnum:
$ref: '#/components/schemas/OuterEnum'
outerEnumInteger:
Expand Down
23 changes: 23 additions & 0 deletions samples/yaml/weather.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
openapi: 3.0.0
info:
version: 1.0.0
title: Weather API
paths: {}

components:
schemas:
WeatherType:
type: integer
format: int32
enum:
- 42
- 18
- 56
x-enum-descriptions:
- 'Blue sky'
- 'Slightly overcast'
- 'Take an umbrella with you'
x-enum-varnames:
- Sunny
- Cloudy
- Rainy

0 comments on commit 84a7330

Please sign in to comment.