Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[typescript] fix: escaped multiline comments; implementation option 2 #19553

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
public String classFilename; // store the class file name, mainly used for import
@Getter @Setter
public String unescapedDescription;
@Getter @Setter
public String unescapedSafeDescription;
/**
* -- GETTER --
* Returns the discriminator for this schema object, or null if no discriminator has been specified.
Expand Down Expand Up @@ -938,6 +940,7 @@ public boolean equals(Object o) {
Objects.equals(xmlName, that.xmlName) &&
Objects.equals(classFilename, that.classFilename) &&
Objects.equals(unescapedDescription, that.unescapedDescription) &&
Objects.equals(unescapedSafeDescription, that.unescapedSafeDescription) &&
Objects.equals(discriminator, that.discriminator) &&
Objects.equals(defaultValue, that.defaultValue) &&
Objects.equals(arrayModelType, that.arrayModelType) &&
Expand Down Expand Up @@ -1019,6 +1022,7 @@ public String toString() {
sb.append(", xmlName='").append(xmlName).append('\'');
sb.append(", classFilename='").append(classFilename).append('\'');
sb.append(", unescapedDescription='").append(unescapedDescription).append('\'');
sb.append(", unescapedSafeDescription='").append(unescapedSafeDescription).append('\'');
sb.append(", discriminator=").append(discriminator);
sb.append(", defaultValue='").append(defaultValue).append('\'');
sb.append(", arrayModelType='").append(arrayModelType).append('\'');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
isCookieParam, isBodyParam, isContainer,
isCollectionFormatMulti, isPrimitiveType, isModel, isExplode, isDeepObject, isMatrix, isAllowEmptyValue;
public String baseName, paramName, dataType, datatypeWithEnum, dataFormat, contentType,
collectionFormat, description, unescapedDescription, baseType, defaultValue, enumDefaultValue, enumName, style;
collectionFormat, description, unescapedDescription, unescapedSafeDescription, baseType, defaultValue, enumDefaultValue, enumName, style;

public String nameInLowerCase; // property name in lower case
public String nameInCamelCase; // property name in camel case (e.g. modifiedDate)
Expand Down Expand Up @@ -156,6 +156,7 @@ public CodegenParameter copy() {
output.isModel = this.isModel;
output.description = this.description;
output.unescapedDescription = this.unescapedDescription;
output.unescapedSafeDescription = this.unescapedSafeDescription;
output.baseType = this.baseType;
output.containerType = this.containerType;
output.containerTypeMapped = this.containerTypeMapped;
Expand Down Expand Up @@ -283,7 +284,7 @@ public int hashCode() {
return Objects.hash(isFormParam, isQueryParam, isPathParam, isHeaderParam, isCookieParam,
isBodyParam, isContainer, isCollectionFormatMulti, isPrimitiveType, isModel, isExplode, baseName,
paramName, dataType, datatypeWithEnum, dataFormat, collectionFormat, description,
unescapedDescription, baseType, containerType, containerTypeMapped, defaultValue,
unescapedDescription, unescapedSafeDescription, baseType, containerType, containerTypeMapped, defaultValue,
enumDefaultValue, enumName, style, isDeepObject, isMatrix, isAllowEmptyValue, example, examples,
jsonSchema, isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal,
isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isPassword,
Expand Down Expand Up @@ -370,6 +371,7 @@ public boolean equals(Object o) {
Objects.equals(collectionFormat, that.collectionFormat) &&
Objects.equals(description, that.description) &&
Objects.equals(unescapedDescription, that.unescapedDescription) &&
Objects.equals(unescapedSafeDescription, that.unescapedSafeDescription) &&
Objects.equals(baseType, that.baseType) &&
Objects.equals(containerType, that.containerType) &&
Objects.equals(containerTypeMapped, that.containerTypeMapped) &&
Expand Down Expand Up @@ -435,6 +437,7 @@ public String toString() {
sb.append(", collectionFormat='").append(collectionFormat).append('\'');
sb.append(", description='").append(description).append('\'');
sb.append(", unescapedDescription='").append(unescapedDescription).append('\'');
sb.append(", unescapedSafeDescription='").append(unescapedSafeDescription).append('\'');
sb.append(", baseType='").append(baseType).append('\'');
sb.append(", containerType='").append(containerType).append('\'');
sb.append(", containerTypeMapped='").append(containerTypeMapped).append('\'');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,18 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti

/**
* The 'description' string without escape characters needed by some programming languages/targets
* Read: property has escapeText() applied
*/
@Getter @Setter
public String unescapedDescription;

/**
* The 'description' string without escape characters but with safe escaping for use in comment blocks, etc.
* Read: property has escapeUnsafeCharacters() applied
*/
@Getter @Setter
public String unescapedSafeDescription;

/**
* maxLength validation for strings, see http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.2.1
*/
Expand Down Expand Up @@ -983,6 +991,7 @@ public String toString() {
sb.append(", containerTypeMapped='").append(containerTypeMapped).append('\'');
sb.append(", title='").append(title).append('\'');
sb.append(", unescapedDescription='").append(unescapedDescription).append('\'');
sb.append(", unescapedSafeDescription='").append(unescapedSafeDescription).append('\'');
sb.append(", maxLength=").append(maxLength);
sb.append(", minLength=").append(minLength);
sb.append(", pattern='").append(pattern).append('\'');
Expand Down Expand Up @@ -1172,6 +1181,7 @@ public boolean equals(Object o) {
Objects.equals(containerTypeMapped, that.containerTypeMapped) &&
Objects.equals(title, that.title) &&
Objects.equals(unescapedDescription, that.unescapedDescription) &&
Objects.equals(unescapedSafeDescription, that.unescapedSafeDescription) &&
Objects.equals(maxLength, that.maxLength) &&
Objects.equals(minLength, that.minLength) &&
Objects.equals(pattern, that.pattern) &&
Expand Down Expand Up @@ -1206,7 +1216,7 @@ public int hashCode() {
return Objects.hash(openApiType, baseName, complexType, getter, setter, description,
dataType, datatypeWithEnum, dataFormat, name, min, max, defaultValue,
defaultValueWithParam, baseType, containerType, containerTypeMapped, title, unescapedDescription,
maxLength, minLength, pattern, example, jsonSchema, minimum, maximum,
unescapedSafeDescription, maxLength, minLength, pattern, example, jsonSchema, minimum, maximum,
exclusiveMinimum, exclusiveMaximum, required, deprecated,
hasMoreNonReadOnly, isPrimitiveType, isModel, isContainer, isString, isNumeric,
isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBinary, isFile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3002,6 +3002,7 @@ public CodegenModel fromModel(String name, Schema schema) {
m.title = escapeText(schema.getTitle());
m.description = escapeText(schema.getDescription());
m.unescapedDescription = schema.getDescription();
m.unescapedSafeDescription = escapeUnsafeCharacters(schema.getDescription());
m.classname = toModelName(name);
m.classVarName = toVarName(name);
m.classFilename = toModelFilename(name);
Expand Down Expand Up @@ -3895,6 +3896,7 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo
property.nameInSnakeCase = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, property.nameInPascalCase);
property.description = escapeText(p.getDescription());
property.unescapedDescription = p.getDescription();
property.unescapedSafeDescription = escapeUnsafeCharacters(p.getDescription());
property.title = p.getTitle();
property.getter = toGetter(name);
property.setter = toSetter(name);
Expand Down Expand Up @@ -4101,6 +4103,7 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo
if (original.getDescription() != null) {
property.description = escapeText(p.getDescription());
property.unescapedDescription = p.getDescription();
property.unescapedSafeDescription = escapeUnsafeCharacters(p.getDescription());
}
if (original.getMaxLength() != null) {
property.setMaxLength(original.getMaxLength());
Expand Down Expand Up @@ -5099,6 +5102,7 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
codegenParameter.baseName = parameter.getName();
codegenParameter.description = escapeText(parameter.getDescription());
codegenParameter.unescapedDescription = parameter.getDescription();
codegenParameter.unescapedSafeDescription = escapeUnsafeCharacters(parameter.getDescription());
if (parameter.getRequired() != null) {
codegenParameter.required = parameter.getRequired();
}
Expand Down Expand Up @@ -7252,6 +7256,7 @@ public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set
codegenParameter.isFormParam = Boolean.TRUE;
codegenParameter.description = escapeText(codegenProperty.description);
codegenParameter.unescapedDescription = codegenProperty.getDescription();
codegenParameter.unescapedSafeDescription = escapeUnsafeCharacters(codegenProperty.getDescription());
codegenParameter.jsonSchema = Json.pretty(propertySchema);
codegenParameter.containerType = codegenProperty.containerType;
codegenParameter.containerTypeMapped = codegenProperty.containerTypeMapped;
Expand Down Expand Up @@ -7790,6 +7795,7 @@ public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, S
if (original.getDescription() != null) {
codegenParameter.description = escapeText(original.getDescription());
codegenParameter.unescapedDescription = original.getDescription();
codegenParameter.unescapedSafeDescription = escapeUnsafeCharacters(original.getDescription());
}
if (original.getMaxLength() != null) {
codegenParameter.setMaxLength(original.getMaxLength());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ public String escapeQuotationMark(String input) {

@Override
public String escapeUnsafeCharacters(String input) {
if (input == null) {
return input;
}
return input.replace("*/", "*_/").replace("/*", "/_*");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,9 @@ public String escapeQuotationMark(String input) {

@Override
public String escapeUnsafeCharacters(String input) {
if (input == null) {
return input;
}
return input.replace("*/", "*_/").replace("/*", "/_*");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,9 @@ public String escapeQuotationMark(String input) {

@Override
public String escapeUnsafeCharacters(String input) {
if (input == null) {
return input;
}
return input.replace("*/", "*_/").replace("/*", "/_*");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,9 @@ public String escapeQuotationMark(String input) {

@Override
public String escapeUnsafeCharacters(String input) {
if (input == null) {
return input;
}
return input.replace("*/", "*_/").replace("/*", "/_*").replace("--", "- -");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,9 @@ public String escapeQuotationMark(String input) {

@Override
public String escapeUnsafeCharacters(String input) {
if (input == null) {
return input;
}
return input.replace("*/", "*_/").replace("/*", "/_*");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ public String escapeQuotationMark(String input) {

@Override
public String escapeUnsafeCharacters(String input) {
if (input == null) {
return input;
}
return input.replace("]]", "] ]");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2137,6 +2137,9 @@ public String escapeQuotationMark(String input) {

@Override
public String escapeUnsafeCharacters(String input) {
if (input == null) {
return input;
}
return input.replace("*/", "*_/").replace("/*", "/_*");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ public String toDefaultValue(Schema schema) {

@Override
public String escapeUnsafeCharacters(String input) {
if (input == null) {
return input;
}
return input.replace("#=", "#_=").replace("=#", "=_#");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ public String escapeReservedWord(String name) {

@Override
public String escapeUnsafeCharacters(String input) {
if (input == null) {
return input;
}
return input.replace("*/", "*_/").replace("/*", "/_*");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,9 @@ public String escapeQuotationMark(String input) {

@Override
public String escapeUnsafeCharacters(String input) {
if (input == null) {
return input;
}
return input.replace("*/", "*_/").replace("/*", "/_*");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ public String escapeQuotationMark(String input) {

@Override
public String escapeUnsafeCharacters(String input) {
if (input == null) {
return input;
}
// remove multiline comment
return input.replace("'''", "'_'_'");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ public String escapeQuotationMark(String input) {

@Override
public String escapeUnsafeCharacters(String input) {
if (input == null) {
return input;
}
// remove multiline comment
return input.replace("'''", "'_'_'");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ public String escapeQuotationMark(String input) {

@Override
public String escapeUnsafeCharacters(String input) {
if (input == null) {
return input;
}
return input.replace("=end", "=_end").replace("=begin", "=_begin").replace("#{", "\\#{");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public String escapeQuotationMark(String input) {

@Override
public String escapeUnsafeCharacters(String input) {
if (input == null) {
return input;
}
return input.replace("*/", "*_/").replace("/*", "/_*");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,9 @@ public String escapeText(String input) {

@Override
public String escapeUnsafeCharacters(String input) {
if (input == null) {
return input;
}
return input.replace("*/", "*_/").replace("/*", "/_*");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,9 @@ public String escapeQuotationMark(String input) {

@Override
public String escapeUnsafeCharacters(String input) {
if (input == null) {
return input;
}
return input.replace("*/", "*_/").replace("/*", "/_*");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,9 @@ public String escapeQuotationMark(String input) {
*/
@Override
public String escapeUnsafeCharacters(String input) {

if (input == null) {
return input;
}
/**
* Replace backticks with normal single quotes.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,9 @@ public String escapeQuotationMark(String input) {

@Override
public String escapeUnsafeCharacters(String input) {
if (input == null) {
return input;
}
return input.replace("=end", "=_end").replace("=begin", "=_begin");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ public String escapeQuotationMark(String input) {

@Override
public String escapeUnsafeCharacters(String input) {
if (input == null) {
return input;
}
// ref: https://clojurebridge.github.io/community-docs/docs/clojure/comment/
return input.replace("(comment", "(_comment");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,9 @@ public String escapeQuotationMark(String input) {

@Override
public String escapeUnsafeCharacters(String input) {
if (input == null) {
return input;
}
return input.replace("=end", "=_end").replace("=begin", "=_begin").replace("#{", "\\#{");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ public ExtendedCodegenModel(CodegenModel cm) {
this.xmlName = cm.xmlName;
this.classFilename = cm.classFilename;
this.unescapedDescription = cm.unescapedDescription;
this.unescapedSafeDescription = cm.unescapedSafeDescription;
this.discriminator = cm.discriminator;
this.defaultValue = cm.defaultValue;
this.arrayModelType = cm.arrayModelType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ protected ImmutableMap.Builder<String, Lambda> addMustacheLambdas() {

@Override
public String escapeUnsafeCharacters(String input) {
if (input == null) {
return input;
}
return input.replace("*/", "*_/").replace("/*", "/_*");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ public String escapeQuotationMark(String input) {

@Override
public String escapeUnsafeCharacters(String input) {
if (input == null) {
return input;
}
return input.replace("*/", "*_/").replace("/*", "/_*");
}

Expand Down
Loading
Loading