mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-06 10:35:25 +00:00
[TypeScript] fix single quote in enums not escaped (#2665)
* [TypeScript] fix single quote in enums not escaped * [TypeScript] remove useless override in some CodeGen TypeScript class generator
This commit is contained in:
parent
c08c45de05
commit
572494ce44
@ -39,7 +39,7 @@ import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractTypeScriptClientCodegen.class);
|
||||
|
||||
protected final SimpleDateFormat SNAPSHOT_SUFFIX_FORMAT = new SimpleDateFormat("yyyyMMddHHmm", Locale.ROOT);
|
||||
protected static final SimpleDateFormat SNAPSHOT_SUFFIX_FORMAT = new SimpleDateFormat("yyyyMMddHHmm", Locale.ROOT);
|
||||
|
||||
private static final String X_DISCRIMINATOR_TYPE = "x-discriminator-value";
|
||||
private static final String UNDEFINED_VALUE = "undefined";
|
||||
@ -88,7 +88,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
"object"
|
||||
));
|
||||
|
||||
languageGenericTypes = new HashSet<String>(Arrays.asList(
|
||||
languageGenericTypes = new HashSet<>(Arrays.asList(
|
||||
"Array"
|
||||
));
|
||||
|
||||
@ -328,14 +328,14 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
* @param dataType either "string" or "number"
|
||||
* @return a literal union for representing enum values as a type
|
||||
*/
|
||||
protected String enumValuesToEnumTypeUnion(List<String> values, String dataType) {
|
||||
private String enumValuesToEnumTypeUnion(List<String> values, String dataType) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
boolean isFirst = true;
|
||||
for (String value : values) {
|
||||
if (!isFirst) {
|
||||
b.append(" | ");
|
||||
}
|
||||
b.append(toEnumValue(value.toString(), dataType));
|
||||
b.append(toEnumValue(value, dataType));
|
||||
isFirst = false;
|
||||
}
|
||||
return b.toString();
|
||||
@ -348,7 +348,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
* @param values a list of numbers
|
||||
* @return a literal union for representing enum values as a type
|
||||
*/
|
||||
protected String numericEnumValuesToEnumTypeUnion(List<Number> values) {
|
||||
private String numericEnumValuesToEnumTypeUnion(List<Number> values) {
|
||||
List<String> stringValues = new ArrayList<>();
|
||||
for (Number value : values) {
|
||||
stringValues.add(value.toString());
|
||||
@ -364,12 +364,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
return UNDEFINED_VALUE;
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
return UNDEFINED_VALUE;
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
return UNDEFINED_VALUE;
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
} else if (ModelUtils.isNumberSchema(p) || ModelUtils.isIntegerSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
}
|
||||
@ -435,7 +430,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
return this.modelPropertyNaming;
|
||||
}
|
||||
|
||||
public String getNameUsingModelPropertyNaming(String name) {
|
||||
private String getNameUsingModelPropertyNaming(String name) {
|
||||
switch (CodegenConstants.MODEL_PROPERTY_NAMING_TYPE.valueOf(getModelPropertyNaming())) {
|
||||
case original:
|
||||
return name;
|
||||
@ -592,6 +587,17 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
public String escapeQuotationMark(String input) {
|
||||
// remove ', " to avoid code injection
|
||||
return input.replace("\"", "").replace("'", "");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeText(String input) {
|
||||
if (input == null) {
|
||||
return input;
|
||||
}
|
||||
|
||||
// replace ' with \'
|
||||
return super.escapeText(input).replace("\'", "\\\'");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -112,11 +112,6 @@ public class JavascriptFlowtypedClientCodegen extends AbstractTypeScriptClientCo
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
|
||||
codegenModel.additionalPropertiesType = getTypeDeclaration(ModelUtils.getAdditionalProperties(schema));
|
||||
@ -134,24 +129,6 @@ public class JavascriptFlowtypedClientCodegen extends AbstractTypeScriptClientCo
|
||||
addNpmPackageGeneration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
Schema inner;
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
inner = ((ArraySchema) p).getItems();
|
||||
return this.getSchemaType(p) + "<" + this.getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "{ [key: string]: " + this.getTypeDeclaration(inner) + "; }";
|
||||
} else if (ModelUtils.isFileSchema(p)) {
|
||||
return "any";
|
||||
} else if (ModelUtils.isBinarySchema(p)) {
|
||||
return "any";
|
||||
} else {
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
}
|
||||
|
||||
private void addNpmPackageGeneration() {
|
||||
if (additionalProperties.containsKey(NPM_NAME)) {
|
||||
this.setNpmName(additionalProperties.get(NPM_NAME).toString());
|
||||
@ -238,17 +215,6 @@ public class JavascriptFlowtypedClientCodegen extends AbstractTypeScriptClientCo
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// remove ', " to avoid code injection
|
||||
return input.replace("\"", "").replace("'", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "javascript-flowtyped";
|
||||
|
@ -153,24 +153,6 @@ public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodege
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
Schema inner;
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
inner = ((ArraySchema) p).getItems();
|
||||
return this.getSchemaType(p) + "<" + this.getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "{ [key: string]: " + this.getTypeDeclaration(inner) + "; }";
|
||||
} else if (ModelUtils.isFileSchema(p)) {
|
||||
return "any";
|
||||
} else if (ModelUtils.isBinarySchema(p)) {
|
||||
return "any";
|
||||
} else {
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
|
||||
objs = super.postProcessOperationsWithModels(objs, allModels);
|
||||
|
Loading…
Reference in New Issue
Block a user