mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-06-29 12:10:54 +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 {
|
public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractTypeScriptClientCodegen.class);
|
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 X_DISCRIMINATOR_TYPE = "x-discriminator-value";
|
||||||
private static final String UNDEFINED_VALUE = "undefined";
|
private static final String UNDEFINED_VALUE = "undefined";
|
||||||
@ -88,7 +88,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
|||||||
"object"
|
"object"
|
||||||
));
|
));
|
||||||
|
|
||||||
languageGenericTypes = new HashSet<String>(Arrays.asList(
|
languageGenericTypes = new HashSet<>(Arrays.asList(
|
||||||
"Array"
|
"Array"
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -328,14 +328,14 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
|||||||
* @param dataType either "string" or "number"
|
* @param dataType either "string" or "number"
|
||||||
* @return a literal union for representing enum values as a type
|
* @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();
|
StringBuilder b = new StringBuilder();
|
||||||
boolean isFirst = true;
|
boolean isFirst = true;
|
||||||
for (String value : values) {
|
for (String value : values) {
|
||||||
if (!isFirst) {
|
if (!isFirst) {
|
||||||
b.append(" | ");
|
b.append(" | ");
|
||||||
}
|
}
|
||||||
b.append(toEnumValue(value.toString(), dataType));
|
b.append(toEnumValue(value, dataType));
|
||||||
isFirst = false;
|
isFirst = false;
|
||||||
}
|
}
|
||||||
return b.toString();
|
return b.toString();
|
||||||
@ -348,7 +348,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
|||||||
* @param values a list of numbers
|
* @param values a list of numbers
|
||||||
* @return a literal union for representing enum values as a type
|
* @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<>();
|
List<String> stringValues = new ArrayList<>();
|
||||||
for (Number value : values) {
|
for (Number value : values) {
|
||||||
stringValues.add(value.toString());
|
stringValues.add(value.toString());
|
||||||
@ -364,12 +364,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
|||||||
return UNDEFINED_VALUE;
|
return UNDEFINED_VALUE;
|
||||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||||
return UNDEFINED_VALUE;
|
return UNDEFINED_VALUE;
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (ModelUtils.isNumberSchema(p) || ModelUtils.isIntegerSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
|
||||||
return p.getDefault().toString();
|
|
||||||
}
|
|
||||||
return UNDEFINED_VALUE;
|
|
||||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
return p.getDefault().toString();
|
return p.getDefault().toString();
|
||||||
}
|
}
|
||||||
@ -435,7 +430,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
|||||||
return this.modelPropertyNaming;
|
return this.modelPropertyNaming;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNameUsingModelPropertyNaming(String name) {
|
private String getNameUsingModelPropertyNaming(String name) {
|
||||||
switch (CodegenConstants.MODEL_PROPERTY_NAMING_TYPE.valueOf(getModelPropertyNaming())) {
|
switch (CodegenConstants.MODEL_PROPERTY_NAMING_TYPE.valueOf(getModelPropertyNaming())) {
|
||||||
case original:
|
case original:
|
||||||
return name;
|
return name;
|
||||||
@ -592,6 +587,17 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
|||||||
public String escapeQuotationMark(String input) {
|
public String escapeQuotationMark(String input) {
|
||||||
// remove ', " to avoid code injection
|
// remove ', " to avoid code injection
|
||||||
return input.replace("\"", "").replace("'", "");
|
return input.replace("\"", "").replace("'", "");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String escapeText(String input) {
|
||||||
|
if (input == null) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
// replace ' with \'
|
||||||
|
return super.escapeText(input).replace("\'", "\\\'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -112,11 +112,6 @@ public class JavascriptFlowtypedClientCodegen extends AbstractTypeScriptClientCo
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public CodegenType getTag() {
|
|
||||||
return CodegenType.CLIENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
|
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
|
||||||
codegenModel.additionalPropertiesType = getTypeDeclaration(ModelUtils.getAdditionalProperties(schema));
|
codegenModel.additionalPropertiesType = getTypeDeclaration(ModelUtils.getAdditionalProperties(schema));
|
||||||
@ -134,24 +129,6 @@ public class JavascriptFlowtypedClientCodegen extends AbstractTypeScriptClientCo
|
|||||||
addNpmPackageGeneration();
|
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() {
|
private void addNpmPackageGeneration() {
|
||||||
if (additionalProperties.containsKey(NPM_NAME)) {
|
if (additionalProperties.containsKey(NPM_NAME)) {
|
||||||
this.setNpmName(additionalProperties.get(NPM_NAME).toString());
|
this.setNpmName(additionalProperties.get(NPM_NAME).toString());
|
||||||
@ -238,17 +215,6 @@ public class JavascriptFlowtypedClientCodegen extends AbstractTypeScriptClientCo
|
|||||||
return objs;
|
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
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "javascript-flowtyped";
|
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
|
@Override
|
||||||
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
|
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
|
||||||
objs = super.postProcessOperationsWithModels(objs, allModels);
|
objs = super.postProcessOperationsWithModels(objs, allModels);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user