Skip to content

Commit

Permalink
Resolve issue with enums with spaces (#47)
Browse files Browse the repository at this point in the history
Fixes #46
  • Loading branch information
rvowles authored Jun 15, 2021
1 parent 713a8f3 commit 440a465
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/it/k8s/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -549,4 +549,9 @@ components:
type: string
count:
type: number

NumericAndSpacedEnum:
type: string
enum:
- Ahoy There
- 18 Spaces Here
- 667
7 changes: 6 additions & 1 deletion src/it/k8s_null/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -549,4 +549,9 @@ components:
type: string
count:
type: number

NumericAndSpacedEnum:
type: string
enum:
- Ahoy There
- 18 Spaces Here
- 667
5 changes: 4 additions & 1 deletion src/main/java/cd/connect/openapi/DartV3ApiGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,10 @@ public String toVarName(String name) {
}

name = name.replaceAll("-", "_")
.replaceAll(" ", "_")
.replaceAll("\\$", "__")
.replaceAll("\\^", "__")
.replaceAll("\\=", "__");
.replaceAll("\\=", "__").trim();

if (name.matches("^[A-Z_]*$")) {
return name;
Expand Down Expand Up @@ -399,6 +400,8 @@ public Map<String, Object> updateAllModels(Map<String, Object> objs) {
return objs;
}



// TODO: check with multiple levels of hierarchy
private void updateModelsWithAllOfInheritance(Map<String, CodegenModel> models) {
for (CodegenModel cm : models.values()) {
Expand Down
7 changes: 3 additions & 4 deletions src/test/java/cd/connect/openapi/SampleRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ public void runGenerator() {
"--additional-properties", "pubName=sample_app",
// "--type-mappings", "int-or-string=IntOrString",
// "--import-mappings", "IntOrString=./int_or_string.dart",
"--global-property", "skipFormModel=false",
// "--additional-properties", "nullSafe=true",
// "--additional-properties", "nullSafe-array-default=true",
"--additional-properties", "listAnyOf=true",
// "--global-property", "skipFormModel=false",
"--additional-properties", "nullSafe=true",
"--additional-properties", "nullSafe-array-default=true",
"--output", "target/" + getClass().getSimpleName())
.toArray(new String[0]));
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/resources/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ components:
type: string
imageUrl:
type: string
NumericAndSpacedEnum:
type: string
enum:
- Ahoy There
- 18 Spaces Here
- 667
EventStatus:
type: string
enum:
Expand Down

0 comments on commit 440a465

Please sign in to comment.