Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 = m.unescapedDescription == null ? null : escapeUnsafeCharacters(m.unescapedDescription);
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 = property.unescapedDescription == null ? null : escapeUnsafeCharacters(property.unescapedDescription);
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 = property.unescapedDescription == null ? null : escapeUnsafeCharacters(property.unescapedDescription);
}
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 = codegenParameter.unescapedDescription == null ? null : escapeUnsafeCharacters(codegenParameter.unescapedDescription);
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 = codegenParameter.unescapedDescription == null ? null : escapeUnsafeCharacters(codegenParameter.unescapedDescription);
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 = codegenParameter.unescapedDescription == null ? null : escapeUnsafeCharacters(codegenParameter.unescapedDescription);
}
if (original.getMaxLength() != null) {
codegenParameter.setMaxLength(original.getMaxLength());
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 @@ -459,6 +459,7 @@ public CodegenArrayModel(CodegenModel cm, Schema schema) {
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 @@ -1509,6 +1509,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 @@ -39,7 +39,7 @@ export class {{classname}}RequestFactory extends BaseAPIRequestFactory {
* {{&summary}}
{{/summary}}
{{#allParams}}
* @param {{paramName}} {{description}}
* @param {{paramName}} {{{description}}}
{{/allParams}}
*/
public async {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}_options?: Configuration): Promise<RequestContext> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ import { {{classname}} } from '{{filename}}{{importFileExtension}}';
{{/tsImports}}
import { HttpFile } from '../http/http{{importFileExtension}}';

{{#description}}
{{#unescapedSafeDescription}}
/**
* {{{.}}}
*/
{{/description}}
{{/unescapedSafeDescription}}
{{^isEnum}}
{{#oneOf}}
{{#-first}}{{>model/modelOneOf}}{{/-first}}
{{/oneOf}}
{{^oneOf}}
export class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{
{{#vars}}
{{#description}}
{{#unescapedSafeDescription}}
/**
* {{{.}}}
*/
{{/description}}
{{/unescapedSafeDescription}}
'{{name}}'{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}} | null{{/isNullable}};
{{/vars}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,12 @@ public void arrayItemsCanBeNullable() throws Exception {
.get("foo");
Assert.assertEquals(codegen.getTypeDeclaration(schema), "Array<string | null>");
}

@Test
public void multilineCommentsAreEscaped() {
final DefaultCodegen codegen = new TypeScriptClientCodegen();
final String multilineComment = "/* This is a multiline comment */";
final String escapedComment = codegen.escapeUnsafeCharacters(multilineComment);
Assert.assertEquals(escapedComment, "/_* This is a multiline comment *_/");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export class Capitalization {
'capitalSnake'?: string;
'sCAETHFlowPoints'?: string;
/**
* Name of the pet
* Name of the pet

*/
'ATT_NAME'?: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import { HttpFile } from '../http/http';

/**
* Model for testing model with \"_class\" property
* Model for testing model with "_class" property
*/
export class ClassModel {
'_class'?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class FormatTest {
*/
'patternWithDigits'?: string;
/**
* A string starting with \'image_\' (case insensitive) and one to three digits following i.e. Image_01.
* A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01.
*/
'patternWithDigitsAndDelimiter'?: string;

Expand Down
Loading