forked from loafle/openapi-generator-original
Extract enum type fix to abstract client codegen
This commit is contained in:
parent
6f1d1c0084
commit
4f788e7ae7
@ -964,6 +964,40 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
return objs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update datatypeWithEnum for array container
|
||||
*
|
||||
* @param property Codegen property
|
||||
*/
|
||||
protected void updateDataTypeWithEnumForArray(CodegenProperty property) {
|
||||
CodegenProperty baseItem = property.items;
|
||||
while (baseItem != null && (Boolean.TRUE.equals(baseItem.isMap)
|
||||
|| Boolean.TRUE.equals(baseItem.isArray))) {
|
||||
baseItem = baseItem.items;
|
||||
}
|
||||
if (baseItem != null) {
|
||||
/*
|
||||
* Note: There are cases where we have datatypeWithEnum == Array<{ [key: string]: string}
|
||||
* In these cases, we then have Array <{ [key: EnumName]: EnumName}> - which is invalid typescript
|
||||
* To protect agains this we first replace [key: string] with a special/reserved placeholder (i.e. *[key]* )
|
||||
*/
|
||||
property.datatypeWithEnum = property.datatypeWithEnum.replace("[key: string]", "*PLACEHOLDER*")
|
||||
.replace(baseItem.baseType, toEnumName(baseItem))
|
||||
.replace("*PLACEHOLDER*", "[key: string]");
|
||||
|
||||
// naming the enum with respect to the language enum naming convention
|
||||
// e.g. remove [], {} from array/map of enum
|
||||
property.enumName = toEnumName(property);
|
||||
|
||||
// set default value for variable with inner enum
|
||||
if (property.defaultValue != null) {
|
||||
property.defaultValue = property.defaultValue.replace(baseItem.baseType, toEnumName(baseItem));
|
||||
}
|
||||
|
||||
updateCodegenPropertyEnum(property);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {
|
||||
Map<String, ModelsMap> result = super.postProcessAllModels(objs);
|
||||
|
@ -293,40 +293,6 @@ public class TypeScriptClientCodegen extends AbstractTypeScriptClientCodegen imp
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update datatypeWithEnum for array container
|
||||
*
|
||||
* @param property Codegen property
|
||||
*/
|
||||
protected void updateDataTypeWithEnumForArray(CodegenProperty property) {
|
||||
CodegenProperty baseItem = property.items;
|
||||
while (baseItem != null && (Boolean.TRUE.equals(baseItem.isMap)
|
||||
|| Boolean.TRUE.equals(baseItem.isArray))) {
|
||||
baseItem = baseItem.items;
|
||||
}
|
||||
if (baseItem != null) {
|
||||
/*
|
||||
* Note: There are cases where we have datatypeWithEnum == Array<{ [key: string]: string}
|
||||
* In these cases, we then have Array <{ [key: EnumName]: EnumName}> - which is invalid typescript
|
||||
* To protect agains this we first replace [key: string] with a special/reserved placeholder (i.e. *[key]* )
|
||||
*/
|
||||
property.datatypeWithEnum = property.datatypeWithEnum.replace("[key: string]", "*key*")
|
||||
.replace(baseItem.baseType, toEnumName(baseItem))
|
||||
.replace("*key*", "[key: string]");
|
||||
|
||||
// naming the enum with respect to the language enum naming convention
|
||||
// e.g. remove [], {} from array/map of enum
|
||||
property.enumName = toEnumName(property);
|
||||
|
||||
// set default value for variable with inner enum
|
||||
if (property.defaultValue != null) {
|
||||
property.defaultValue = property.defaultValue.replace(baseItem.baseType, toEnumName(baseItem));
|
||||
}
|
||||
|
||||
updateCodegenPropertyEnum(property);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelsMap postProcessModels(ModelsMap objs) {
|
||||
// process enum in models
|
||||
|
Loading…
x
Reference in New Issue
Block a user