-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add config property "enumPropertyNaming" to TypeScript codegens.
It allows overriding how enum member names are capitalised or snake_cased in generated code. It works very similarly to the Kotlin generator property of the same name.
- Loading branch information
Showing
17 changed files
with
154 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
modules/swagger-codegen/src/main/java/io/swagger/codegen/utils/EnumPropertyNamingUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.swagger.codegen.utils; | ||
|
||
import io.swagger.codegen.CodegenConstants.ENUM_PROPERTY_NAMING_TYPE; | ||
import io.swagger.codegen.DefaultCodegen; | ||
|
||
public final class EnumPropertyNamingUtils { | ||
|
||
/** Apply the given {@link ENUM_PROPERTY_NAMING_TYPE} to get the correct capitalisation and underscore-usage for an enum name. */ | ||
public static String applyEnumPropertyCapitalisation(String value, final ENUM_PROPERTY_NAMING_TYPE enumPropertyNaming) { | ||
switch (enumPropertyNaming) { | ||
case original: | ||
return value; | ||
case camelCase: | ||
// NOTE: Removes hyphens and underscores | ||
return DefaultCodegen.camelize(value, true); | ||
case PascalCase: | ||
// NOTE: Removes hyphens and underscores | ||
return DefaultCodegen.titleCase(DefaultCodegen.camelize(value)); | ||
case snake_case: | ||
// NOTE: Removes hyphens | ||
return DefaultCodegen.underscore(value); | ||
case UPPERCASE: | ||
return value.toUpperCase(); | ||
default: | ||
return value; | ||
} | ||
} | ||
|
||
public static ENUM_PROPERTY_NAMING_TYPE parseEnumPropertyNaming(final String enumPropertyNamingType) { | ||
try { | ||
return ENUM_PROPERTY_NAMING_TYPE.valueOf(enumPropertyNamingType); | ||
} catch (IllegalArgumentException ex) { | ||
StringBuilder sb = new StringBuilder(enumPropertyNamingType + " is an invalid enum property naming option. Please choose from:"); | ||
for (ENUM_PROPERTY_NAMING_TYPE t : ENUM_PROPERTY_NAMING_TYPE.values()) { | ||
sb.append("\n ").append(t.name()); | ||
} | ||
throw new RuntimeException(sb.toString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.