From 4dfb2ce4d9330f68f7e8ec62a70aea9b18ed8084 Mon Sep 17 00:00:00 2001 From: Joscha Feth Date: Wed, 4 Sep 2024 15:58:36 +0100 Subject: [PATCH 1/4] [typescript] fix: `Java`-escaped multiline comments --- .../openapitools/codegen/CodegenConfig.java | 2 ++ .../openapitools/codegen/CodegenModel.java | 4 ++++ .../codegen/CodegenParameter.java | 7 +++++-- .../openapitools/codegen/CodegenProperty.java | 12 +++++++++++- .../openapitools/codegen/DefaultCodegen.java | 19 +++++++++++++++++++ .../languages/ElixirClientCodegen.java | 1 + .../languages/ErlangProperCodegen.java | 1 + .../TypeScriptFetchClientCodegen.java | 1 + .../resources/typescript/api/api.mustache | 2 +- .../resources/typescript/model/model.mustache | 8 ++++---- .../codegen/DefaultCodegenTest.java | 8 ++++++++ .../TypeScriptClientCodegenTest.java | 8 ++++++++ .../explode-query/models/Capitalization.ts | 3 ++- .../builds/explode-query/models/ClassModel.ts | 2 +- .../builds/explode-query/models/FormatTest.ts | 2 +- 15 files changed, 69 insertions(+), 11 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java index 1c25a69f5dd3..6fedf637cc36 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java @@ -100,6 +100,8 @@ public interface CodegenConfig { String escapeUnsafeCharacters(String input); + String escapeUnsafeCharactersNullGuard(String input); + String escapeReservedWord(String name); String escapeQuotationMark(String input); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java index 41a3a176ab2a..e21b23f4109e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java @@ -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. @@ -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) && @@ -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('\''); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenParameter.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenParameter.java index 0497bf49c55b..c25a53f98459 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenParameter.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenParameter.java @@ -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) @@ -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; @@ -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, @@ -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) && @@ -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('\''); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java index dddec1c620c6..a5e6bb069d6a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java @@ -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 */ @@ -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('\''); @@ -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) && @@ -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, diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 6e252298d08a..708c17e27bd3 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -1167,6 +1167,19 @@ public String escapeUnsafeCharacters(String input) { return input; } + /** + * Same as escapeUnsafeCharacters, but with a null guard + * + * @see escapeUnsafeCharacters + */ + @Override + public String escapeUnsafeCharactersNullGuard(String input) { + if (input == null) { + return input; + } + return escapeUnsafeCharacters(input); + } + /** * Escape single and/or double quote to avoid code injection * @@ -3002,6 +3015,7 @@ public CodegenModel fromModel(String name, Schema schema) { m.title = escapeText(schema.getTitle()); m.description = escapeText(schema.getDescription()); m.unescapedDescription = schema.getDescription(); + m.unescapedSafeDescription = escapeUnsafeCharactersNullGuard(schema.getDescription()); m.classname = toModelName(name); m.classVarName = toVarName(name); m.classFilename = toModelFilename(name); @@ -3895,6 +3909,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 = escapeUnsafeCharactersNullGuard(p.getDescription()); property.title = p.getTitle(); property.getter = toGetter(name); property.setter = toSetter(name); @@ -4101,6 +4116,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 = escapeUnsafeCharactersNullGuard(p.getDescription()); } if (original.getMaxLength() != null) { property.setMaxLength(original.getMaxLength()); @@ -5099,6 +5115,7 @@ public CodegenParameter fromParameter(Parameter parameter, Set imports) codegenParameter.baseName = parameter.getName(); codegenParameter.description = escapeText(parameter.getDescription()); codegenParameter.unescapedDescription = parameter.getDescription(); + codegenParameter.unescapedSafeDescription = escapeUnsafeCharactersNullGuard(parameter.getDescription()); if (parameter.getRequired() != null) { codegenParameter.required = parameter.getRequired(); } @@ -7252,6 +7269,7 @@ public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set codegenParameter.isFormParam = Boolean.TRUE; codegenParameter.description = escapeText(codegenProperty.description); codegenParameter.unescapedDescription = codegenProperty.getDescription(); + codegenParameter.unescapedSafeDescription = escapeUnsafeCharactersNullGuard(codegenProperty.getDescription()); codegenParameter.jsonSchema = Json.pretty(propertySchema); codegenParameter.containerType = codegenProperty.containerType; codegenParameter.containerTypeMapped = codegenProperty.containerTypeMapped; @@ -7790,6 +7808,7 @@ public CodegenParameter fromRequestBody(RequestBody body, Set imports, S if (original.getDescription() != null) { codegenParameter.description = escapeText(original.getDescription()); codegenParameter.unescapedDescription = original.getDescription(); + codegenParameter.unescapedSafeDescription = escapeUnsafeCharactersNullGuard(original.getDescription()); } if (original.getMaxLength() != null) { codegenParameter.setMaxLength(original.getMaxLength()); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElixirClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElixirClientCodegen.java index 775afb9bd597..d4e8f7cd8db7 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElixirClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElixirClientCodegen.java @@ -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; diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangProperCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangProperCodegen.java index ab03c7c55d3e..0e70c15848ff 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangProperCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangProperCodegen.java @@ -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; diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java index e299264517af..0b3abbc3d0cf 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java @@ -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; diff --git a/modules/openapi-generator/src/main/resources/typescript/api/api.mustache b/modules/openapi-generator/src/main/resources/typescript/api/api.mustache index 0ad7fa1ca686..db7d7d781eb2 100644 --- a/modules/openapi-generator/src/main/resources/typescript/api/api.mustache +++ b/modules/openapi-generator/src/main/resources/typescript/api/api.mustache @@ -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 { diff --git a/modules/openapi-generator/src/main/resources/typescript/model/model.mustache b/modules/openapi-generator/src/main/resources/typescript/model/model.mustache index 4f30fea765b0..0ebd74543ea2 100644 --- a/modules/openapi-generator/src/main/resources/typescript/model/model.mustache +++ b/modules/openapi-generator/src/main/resources/typescript/model/model.mustache @@ -6,11 +6,11 @@ import { {{classname}} } from '{{filename}}{{importFileExtension}}'; {{/tsImports}} import { HttpFile } from '../http/http{{importFileExtension}}'; -{{#description}} +{{#unescapedSafeDescription}} /** * {{{.}}} */ -{{/description}} +{{/unescapedSafeDescription}} {{^isEnum}} {{#oneOf}} {{#-first}}{{>model/modelOneOf}}{{/-first}} @@ -18,11 +18,11 @@ import { HttpFile } from '../http/http{{importFileExtension}}'; {{^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}} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java index d5da26e5be8f..36ac06f05ac5 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java @@ -780,6 +780,14 @@ public void testEscapeTextWhileAllowingNewLines() { Assertions.assertEquals(codegen.escapeTextWhileAllowingNewLines("\\/"), "/"); } + @Test + public void testEscapeUnsafeCharactersNullGuard() { + final DefaultCodegen codegen = new DefaultCodegen(); + + // allow null + Assertions.assertEquals(codegen.escapeUnsafeCharactersNullGuard(null), null); + } + @Test public void updateCodegenPropertyEnum() { final DefaultCodegen codegen = new DefaultCodegen(); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/TypeScriptClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/TypeScriptClientCodegenTest.java index 0c1cd296d18b..3baf222a7f7e 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/TypeScriptClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/TypeScriptClientCodegenTest.java @@ -168,4 +168,12 @@ public void arrayItemsCanBeNullable() throws Exception { .get("foo"); Assert.assertEquals(codegen.getTypeDeclaration(schema), "Array"); } + + @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 *_/"); + } } diff --git a/samples/openapi3/client/petstore/typescript/builds/explode-query/models/Capitalization.ts b/samples/openapi3/client/petstore/typescript/builds/explode-query/models/Capitalization.ts index d468f2bbc67d..f3312874e028 100644 --- a/samples/openapi3/client/petstore/typescript/builds/explode-query/models/Capitalization.ts +++ b/samples/openapi3/client/petstore/typescript/builds/explode-query/models/Capitalization.ts @@ -19,7 +19,8 @@ export class Capitalization { 'capitalSnake'?: string; 'sCAETHFlowPoints'?: string; /** - * Name of the pet + * Name of the pet + */ 'ATT_NAME'?: string; diff --git a/samples/openapi3/client/petstore/typescript/builds/explode-query/models/ClassModel.ts b/samples/openapi3/client/petstore/typescript/builds/explode-query/models/ClassModel.ts index 05a609ba28e7..04c78f3ed86c 100644 --- a/samples/openapi3/client/petstore/typescript/builds/explode-query/models/ClassModel.ts +++ b/samples/openapi3/client/petstore/typescript/builds/explode-query/models/ClassModel.ts @@ -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; diff --git a/samples/openapi3/client/petstore/typescript/builds/explode-query/models/FormatTest.ts b/samples/openapi3/client/petstore/typescript/builds/explode-query/models/FormatTest.ts index 33bb6c633d65..201b69dc6b25 100644 --- a/samples/openapi3/client/petstore/typescript/builds/explode-query/models/FormatTest.ts +++ b/samples/openapi3/client/petstore/typescript/builds/explode-query/models/FormatTest.ts @@ -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; From 92f3c1c06246de07595d055f584454d23566dfd1 Mon Sep 17 00:00:00 2001 From: Joscha Feth Date: Wed, 4 Sep 2024 16:11:33 +0100 Subject: [PATCH 2/4] chore: update generated code samples --- .../java/org/openapitools/handler/PathHandlerInterface.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerInterface.java b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerInterface.java index bad7106ea5c8..1b91d89e043e 100644 --- a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerInterface.java +++ b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerInterface.java @@ -574,13 +574,13 @@ public interface PathHandlerInterface { *

* * - *

Response headers: [CodegenProperty{openApiType='string', baseName='Set-Cookie', complexType='null', getter='getSetCookie', setter='setSetCookie', description='Cookie authentication key for use with the `api_key` apiKey authentication.', dataType='String', datatypeWithEnum='String', dataFormat='null', name='setCookie', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.Set-Cookie;', baseType='String', containerType='null', containerTypeMapped='null', title='null', unescapedDescription='Cookie authentication key for use with the `api_key` apiKey authentication.', maxLength=null, minLength=null, pattern='null', example='AUTH_KEY=abcde12345; Path=/; HttpOnly', jsonSchema='{ + *

Response headers: [CodegenProperty{openApiType='string', baseName='Set-Cookie', complexType='null', getter='getSetCookie', setter='setSetCookie', description='Cookie authentication key for use with the `api_key` apiKey authentication.', dataType='String', datatypeWithEnum='String', dataFormat='null', name='setCookie', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.Set-Cookie;', baseType='String', containerType='null', containerTypeMapped='null', title='null', unescapedDescription='Cookie authentication key for use with the `api_key` apiKey authentication.', unescapedSafeDescription='null', maxLength=null, minLength=null, pattern='null', example='AUTH_KEY=abcde12345; Path=/; HttpOnly', jsonSchema='{ "example" : "AUTH_KEY=abcde12345; Path=/; HttpOnly", "type" : "string" -}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=true, isModel=false, isContainer=false, isString=true, isNumeric=false, isInteger=false, isShort=false, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=false, isUuid=false, isUri=false, isEmail=false, isPassword=false, isFreeFormObject=false, isArray=false, isMap=false, isOptional=false, isEnum=false, isInnerEnum=false, isEnumRef=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, isNew=false, isOverridden=null, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='setCookie', nameInPascalCase='SetCookie', nameInSnakeCase='SET_COOKIE', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, isVoid=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, hasSanitizedName=true, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=null, dependentRequired=null, contains=null}, CodegenProperty{openApiType='integer', baseName='X-Rate-Limit', complexType='null', getter='getxRateLimit', setter='setxRateLimit', description='calls per hour allowed by the user', dataType='Integer', datatypeWithEnum='Integer', dataFormat='int32', name='xRateLimit', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.X-Rate-Limit;', baseType='Integer', containerType='null', containerTypeMapped='null', title='null', unescapedDescription='calls per hour allowed by the user', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{ +}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=true, isModel=false, isContainer=false, isString=true, isNumeric=false, isInteger=false, isShort=false, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=false, isUuid=false, isUri=false, isEmail=false, isPassword=false, isFreeFormObject=false, isArray=false, isMap=false, isOptional=false, isEnum=false, isInnerEnum=false, isEnumRef=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, isNew=false, isOverridden=null, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='setCookie', nameInPascalCase='SetCookie', nameInSnakeCase='SET_COOKIE', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, isVoid=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, hasSanitizedName=true, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=null, dependentRequired=null, contains=null}, CodegenProperty{openApiType='integer', baseName='X-Rate-Limit', complexType='null', getter='getxRateLimit', setter='setxRateLimit', description='calls per hour allowed by the user', dataType='Integer', datatypeWithEnum='Integer', dataFormat='int32', name='xRateLimit', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.X-Rate-Limit;', baseType='Integer', containerType='null', containerTypeMapped='null', title='null', unescapedDescription='calls per hour allowed by the user', unescapedSafeDescription='null', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{ "format" : "int32", "type" : "integer" -}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=true, isModel=false, isContainer=false, isString=false, isNumeric=true, isInteger=true, isShort=true, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=false, isUuid=false, isUri=false, isEmail=false, isPassword=false, isFreeFormObject=false, isArray=false, isMap=false, isOptional=false, isEnum=false, isInnerEnum=false, isEnumRef=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, isNew=false, isOverridden=null, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='xRateLimit', nameInPascalCase='XRateLimit', nameInSnakeCase='X_RATE_LIMIT', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, isVoid=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, hasSanitizedName=true, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=int32, dependentRequired=null, contains=null}, CodegenProperty{openApiType='string', baseName='X-Expires-After', complexType='Date', getter='getxExpiresAfter', setter='setxExpiresAfter', description='date in UTC when token expires', dataType='Date', datatypeWithEnum='Date', dataFormat='date-time', name='xExpiresAfter', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.X-Expires-After;', baseType='Date', containerType='null', containerTypeMapped='null', title='null', unescapedDescription='date in UTC when token expires', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{ +}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=true, isModel=false, isContainer=false, isString=false, isNumeric=true, isInteger=true, isShort=true, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=false, isUuid=false, isUri=false, isEmail=false, isPassword=false, isFreeFormObject=false, isArray=false, isMap=false, isOptional=false, isEnum=false, isInnerEnum=false, isEnumRef=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, isNew=false, isOverridden=null, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='xRateLimit', nameInPascalCase='XRateLimit', nameInSnakeCase='X_RATE_LIMIT', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, isVoid=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, hasSanitizedName=true, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=int32, dependentRequired=null, contains=null}, CodegenProperty{openApiType='string', baseName='X-Expires-After', complexType='Date', getter='getxExpiresAfter', setter='setxExpiresAfter', description='date in UTC when token expires', dataType='Date', datatypeWithEnum='Date', dataFormat='date-time', name='xExpiresAfter', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.X-Expires-After;', baseType='Date', containerType='null', containerTypeMapped='null', title='null', unescapedDescription='date in UTC when token expires', unescapedSafeDescription='null', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{ "format" : "date-time", "type" : "string" }', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=false, isModel=false, isContainer=false, isString=false, isNumeric=false, isInteger=false, isShort=false, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=true, isUuid=false, isUri=false, isEmail=false, isPassword=false, isFreeFormObject=false, isArray=false, isMap=false, isOptional=false, isEnum=false, isInnerEnum=false, isEnumRef=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, isNew=false, isOverridden=null, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='xExpiresAfter', nameInPascalCase='XExpiresAfter', nameInSnakeCase='X_EXPIRES_AFTER', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, isVoid=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, hasSanitizedName=true, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=date-time, dependentRequired=null, contains=null}]

From 7216a37aaccbf4aaa1e6f8156d08639f558e9a78 Mon Sep 17 00:00:00 2001 From: Joscha Feth Date: Mon, 9 Sep 2024 10:48:34 +0100 Subject: [PATCH 3/4] fix: `null` guard for non-`null`-safe implementations of `escapeUnsafeCharacters` --- .../openapitools/codegen/CodegenConfig.java | 2 -- .../openapitools/codegen/DefaultCodegen.java | 25 +++++-------------- .../codegen/languages/AbstractCppCodegen.java | 3 +++ .../languages/AbstractDartCodegen.java | 3 +++ .../languages/AbstractEiffelCodegen.java | 3 +++ .../languages/AbstractFSharpCodegen.java | 3 +++ .../codegen/languages/AbstractGoCodegen.java | 3 +++ .../languages/AbstractGraphQLCodegen.java | 3 +++ .../languages/AbstractJavaCodegen.java | 3 +++ .../languages/AbstractJuliaCodegen.java | 3 +++ .../languages/AbstractKotlinCodegen.java | 3 +++ .../codegen/languages/AbstractPhpCodegen.java | 3 +++ .../languages/AbstractPythonCodegen.java | 3 +++ .../AbstractPythonPydanticV1Codegen.java | 3 +++ .../languages/AbstractRubyCodegen.java | 3 +++ .../languages/AbstractRustCodegen.java | 3 +++ .../AbstractTypeScriptClientCodegen.java | 3 +++ .../languages/AndroidClientCodegen.java | 3 +++ .../codegen/languages/BashClientCodegen.java | 4 ++- .../languages/CLibcurlClientCodegen.java | 3 +++ .../languages/ClojureClientCodegen.java | 3 +++ .../languages/CrystalClientCodegen.java | 3 +++ .../codegen/languages/ElmClientCodegen.java | 3 +++ .../languages/ErlangClientCodegen.java | 3 +++ .../languages/ErlangProperCodegen.java | 3 +++ .../languages/ErlangServerCodegen.java | 3 +++ .../languages/HaskellHttpClientCodegen.java | 3 +++ .../languages/HaskellServantCodegen.java | 3 +++ .../languages/HaskellYesodServerCodegen.java | 3 +++ .../languages/JMeterClientCodegen.java | 3 +++ ...JavascriptClosureAngularClientCodegen.java | 3 +++ .../codegen/languages/K6ClientCodegen.java | 3 +++ .../codegen/languages/LuaClientCodegen.java | 3 +++ .../codegen/languages/MysqlSchemaCodegen.java | 3 +++ .../codegen/languages/N4jsClientCodegen.java | 3 +++ .../codegen/languages/NimClientCodegen.java | 3 +++ .../languages/NodeJSExpressServerCodegen.java | 3 +++ .../codegen/languages/OCamlClientCodegen.java | 3 +++ .../codegen/languages/ObjcClientCodegen.java | 3 +++ .../codegen/languages/PerlClientCodegen.java | 3 +++ .../languages/PhpSilexServerCodegen.java | 3 +++ .../languages/PowerShellClientCodegen.java | 3 +++ .../codegen/languages/RClientCodegen.java | 3 +++ .../languages/ScalaFinchServerCodegen.java | 3 +++ .../languages/ScalaHttp4sServerCodegen.java | 3 +++ .../languages/Swift5ClientCodegen.java | 3 +++ .../languages/SwiftCombineClientCodegen.java | 3 +++ .../codegen/languages/XojoClientCodegen.java | 3 +++ .../resources/codegen/generatorClass.mustache | 3 +++ .../codegen/DefaultCodegenTest.java | 4 +-- .../codegen/MyclientcodegenGenerator.java | 3 +++ 51 files changed, 152 insertions(+), 24 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java index 6fedf637cc36..1c25a69f5dd3 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java @@ -100,8 +100,6 @@ public interface CodegenConfig { String escapeUnsafeCharacters(String input); - String escapeUnsafeCharactersNullGuard(String input); - String escapeReservedWord(String name); String escapeQuotationMark(String input); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 708c17e27bd3..6b2d5628c191 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -1167,19 +1167,6 @@ public String escapeUnsafeCharacters(String input) { return input; } - /** - * Same as escapeUnsafeCharacters, but with a null guard - * - * @see escapeUnsafeCharacters - */ - @Override - public String escapeUnsafeCharactersNullGuard(String input) { - if (input == null) { - return input; - } - return escapeUnsafeCharacters(input); - } - /** * Escape single and/or double quote to avoid code injection * @@ -3015,7 +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 = escapeUnsafeCharactersNullGuard(schema.getDescription()); + m.unescapedSafeDescription = escapeUnsafeCharacters(schema.getDescription()); m.classname = toModelName(name); m.classVarName = toVarName(name); m.classFilename = toModelFilename(name); @@ -3909,7 +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 = escapeUnsafeCharactersNullGuard(p.getDescription()); + property.unescapedSafeDescription = escapeUnsafeCharacters(p.getDescription()); property.title = p.getTitle(); property.getter = toGetter(name); property.setter = toSetter(name); @@ -4116,7 +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 = escapeUnsafeCharactersNullGuard(p.getDescription()); + property.unescapedSafeDescription = escapeUnsafeCharacters(p.getDescription()); } if (original.getMaxLength() != null) { property.setMaxLength(original.getMaxLength()); @@ -5115,7 +5102,7 @@ public CodegenParameter fromParameter(Parameter parameter, Set imports) codegenParameter.baseName = parameter.getName(); codegenParameter.description = escapeText(parameter.getDescription()); codegenParameter.unescapedDescription = parameter.getDescription(); - codegenParameter.unescapedSafeDescription = escapeUnsafeCharactersNullGuard(parameter.getDescription()); + codegenParameter.unescapedSafeDescription = escapeUnsafeCharacters(parameter.getDescription()); if (parameter.getRequired() != null) { codegenParameter.required = parameter.getRequired(); } @@ -7269,7 +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 = escapeUnsafeCharactersNullGuard(codegenProperty.getDescription()); + codegenParameter.unescapedSafeDescription = escapeUnsafeCharacters(codegenProperty.getDescription()); codegenParameter.jsonSchema = Json.pretty(propertySchema); codegenParameter.containerType = codegenProperty.containerType; codegenParameter.containerTypeMapped = codegenProperty.containerTypeMapped; @@ -7808,7 +7795,7 @@ public CodegenParameter fromRequestBody(RequestBody body, Set imports, S if (original.getDescription() != null) { codegenParameter.description = escapeText(original.getDescription()); codegenParameter.unescapedDescription = original.getDescription(); - codegenParameter.unescapedSafeDescription = escapeUnsafeCharactersNullGuard(original.getDescription()); + codegenParameter.unescapedSafeDescription = escapeUnsafeCharacters(original.getDescription()); } if (original.getMaxLength() != null) { codegenParameter.setMaxLength(original.getMaxLength()); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java index 40335e87c37c..7c53d56b8c0b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java @@ -177,6 +177,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractDartCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractDartCodegen.java index fba1dcecf253..6aa5dbd63562 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractDartCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractDartCodegen.java @@ -787,6 +787,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractEiffelCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractEiffelCodegen.java index 58a1e0bec04f..1068ec8a1035 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractEiffelCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractEiffelCodegen.java @@ -553,6 +553,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractFSharpCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractFSharpCodegen.java index e203225c162a..0e549cae3d96 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractFSharpCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractFSharpCodegen.java @@ -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("--", "- -"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java index 9f65605bc693..6f148e7b37cd 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java @@ -890,6 +890,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGraphQLCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGraphQLCodegen.java index 0d383f375a61..154170866b8b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGraphQLCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGraphQLCodegen.java @@ -338,6 +338,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("]]", "] ]"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java index 6ae58f6bff4c..fab156843a7c 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java @@ -2137,6 +2137,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJuliaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJuliaCodegen.java index 3f2549780f59..4670e0bc5228 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJuliaCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJuliaCodegen.java @@ -419,6 +419,9 @@ public String toDefaultValue(Schema schema) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("#=", "#_=").replace("=#", "=_#"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java index 7df7f8021c9a..4339b0e9059f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java @@ -304,6 +304,9 @@ public String escapeReservedWord(String name) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java index af33ba1f36a7..43cb4c2d74c8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java @@ -782,6 +782,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java index b833739796c4..9de3fca21266 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java @@ -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("'''", "'_'_'"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonPydanticV1Codegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonPydanticV1Codegen.java index fc2d73b3bb2a..60eb195a8e04 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonPydanticV1Codegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonPydanticV1Codegen.java @@ -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("'''", "'_'_'"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRubyCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRubyCodegen.java index 7ef29f104a72..d7f5100629ca 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRubyCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRubyCodegen.java @@ -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("#{", "\\#{"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRustCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRustCodegen.java index 567f6ec41592..da0dbddc585d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRustCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRustCodegen.java @@ -54,6 +54,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java index c4caca0c6227..16c3c2541506 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java @@ -1076,6 +1076,9 @@ public String escapeText(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AndroidClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AndroidClientCodegen.java index b94c939f8e1a..14b3d6c478f5 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AndroidClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AndroidClientCodegen.java @@ -511,6 +511,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/BashClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/BashClientCodegen.java index 5a989fe113ab..b6507306b026 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/BashClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/BashClientCodegen.java @@ -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. */ diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java index a1154fb8a92a..f445468e16a7 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java @@ -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"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ClojureClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ClojureClientCodegen.java index 93aeaf744d67..cd2135060918 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ClojureClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ClojureClientCodegen.java @@ -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"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CrystalClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CrystalClientCodegen.java index cd7c18145c6a..d23998ad2fbb 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CrystalClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CrystalClientCodegen.java @@ -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("#{", "\\#{"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java index 3bc81accdc3a..14503501c855 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java @@ -174,6 +174,9 @@ protected ImmutableMap.Builder addMustacheLambdas() { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangClientCodegen.java index 72379dbeb4a3..08ec82ed442a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangClientCodegen.java @@ -398,6 +398,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangProperCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangProperCodegen.java index 0e70c15848ff..e49ee7a48170 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangProperCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangProperCodegen.java @@ -431,6 +431,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangServerCodegen.java index d41136eb6761..e3ec13c1537b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangServerCodegen.java @@ -318,6 +318,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } // ref: http://stackoverflow.com/a/30421295/677735 return input.replace("-ifdef", "- if def").replace("-endif", "- end if"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellHttpClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellHttpClientCodegen.java index a78e9a703cae..cfe08de78388 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellHttpClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellHttpClientCodegen.java @@ -894,6 +894,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("{-", "{_-").replace("-}", "-_}"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellServantCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellServantCodegen.java index a7785024a06f..da7a2381bd8b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellServantCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellServantCodegen.java @@ -691,6 +691,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("{-", "{_-").replace("-}", "-_}"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellYesodServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellYesodServerCodegen.java index f3587ad772f4..c2dd84dd930d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellYesodServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellYesodServerCodegen.java @@ -558,6 +558,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("{-", "{_-").replace("-}", "-_}"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JMeterClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JMeterClientCodegen.java index d005f54111b6..9f27dfa303f2 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JMeterClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JMeterClientCodegen.java @@ -245,6 +245,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClosureAngularClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClosureAngularClientCodegen.java index 2062ba27da35..32bbb699c8c4 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClosureAngularClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClosureAngularClientCodegen.java @@ -321,6 +321,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/K6ClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/K6ClientCodegen.java index dcfb3333eed0..0e807a667bf6 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/K6ClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/K6ClientCodegen.java @@ -881,6 +881,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/LuaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/LuaClientCodegen.java index 9f6ff2977ced..efbfe9caa277 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/LuaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/LuaClientCodegen.java @@ -512,6 +512,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("]]", "] ]"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/MysqlSchemaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/MysqlSchemaCodegen.java index 828874976d7b..ffcc58c0d9d1 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/MysqlSchemaCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/MysqlSchemaCodegen.java @@ -1161,6 +1161,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/N4jsClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/N4jsClientCodegen.java index 6f154dbb2731..ff7b3023a546 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/N4jsClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/N4jsClientCodegen.java @@ -693,6 +693,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/NimClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/NimClientCodegen.java index b2332a2d9642..c81aaefe533e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/NimClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/NimClientCodegen.java @@ -210,6 +210,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/NodeJSExpressServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/NodeJSExpressServerCodegen.java index c6aa293cdeea..71b107bfdeb4 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/NodeJSExpressServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/NodeJSExpressServerCodegen.java @@ -411,6 +411,9 @@ public String removeNonNameElementToCamelCase(String name) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/OCamlClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/OCamlClientCodegen.java index 32329d4a8595..27e0fb7a8e8a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/OCamlClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/OCamlClientCodegen.java @@ -764,6 +764,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input .replace("*)", "*_)") .replace("(*", "(_*") diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ObjcClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ObjcClientCodegen.java index 9c388464071f..ab57a0b9009b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ObjcClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ObjcClientCodegen.java @@ -765,6 +765,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PerlClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PerlClientCodegen.java index 67dee27a017d..1bd7169590ea 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PerlClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PerlClientCodegen.java @@ -618,6 +618,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } // remove =end, =cut to avoid code injection return input.replace("=begin", "=_begin").replace("=end", "=_end").replace("=cut", "=_cut").replace("=pod", "=_pod"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSilexServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSilexServerCodegen.java index 6335eafdd160..685bc5ca177a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSilexServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSilexServerCodegen.java @@ -256,6 +256,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java index 6550d352bb5d..d5f2f83acc14 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java @@ -803,6 +803,9 @@ public String escapeText(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("#>", "#_>").replace("<#", "<_#"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java index 7e7d8ebb3515..127757a65052 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java @@ -671,6 +671,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("]]", "] ]"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaFinchServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaFinchServerCodegen.java index a869bbecad17..96464e881228 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaFinchServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaFinchServerCodegen.java @@ -294,6 +294,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaHttp4sServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaHttp4sServerCodegen.java index 59dc936667d3..50d9a65da077 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaHttp4sServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaHttp4sServerCodegen.java @@ -743,6 +743,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java index 33e4cdd5c718..7cdc2b6d4030 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java @@ -1153,6 +1153,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SwiftCombineClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SwiftCombineClientCodegen.java index 1a927937c888..272f58f3f33a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SwiftCombineClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SwiftCombineClientCodegen.java @@ -689,6 +689,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/XojoClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/XojoClientCodegen.java index c9101b863284..5ee321b0f4ee 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/XojoClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/XojoClientCodegen.java @@ -361,6 +361,9 @@ public String escapeQuotationMark(String input) { @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } // if a backslash occurs in a property note for instance, Xojo crashes. return input.replace("*/", "*_/").replace("/*", "/_*").replace("\\", ""); } diff --git a/modules/openapi-generator/src/main/resources/codegen/generatorClass.mustache b/modules/openapi-generator/src/main/resources/codegen/generatorClass.mustache index 4f89b0f502ad..3df3857b8b2f 100644 --- a/modules/openapi-generator/src/main/resources/codegen/generatorClass.mustache +++ b/modules/openapi-generator/src/main/resources/codegen/generatorClass.mustache @@ -181,6 +181,9 @@ public class {{generatorClass}} extends DefaultCodegen implements CodegenConfig */ @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } //TODO: check that this logic is safe to escape unsafe characters to avoid code injection return input; } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java index 36ac06f05ac5..b795bd2382ed 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java @@ -781,11 +781,11 @@ public void testEscapeTextWhileAllowingNewLines() { } @Test - public void testEscapeUnsafeCharactersNullGuard() { + public void testescapeUnsafeCharacters() { final DefaultCodegen codegen = new DefaultCodegen(); // allow null - Assertions.assertEquals(codegen.escapeUnsafeCharactersNullGuard(null), null); + Assertions.assertEquals(codegen.escapeUnsafeCharacters(null), null); } @Test diff --git a/samples/meta-codegen/lib/src/main/java/com/my/company/codegen/MyclientcodegenGenerator.java b/samples/meta-codegen/lib/src/main/java/com/my/company/codegen/MyclientcodegenGenerator.java index 379443c0dfc5..c8c035686b27 100644 --- a/samples/meta-codegen/lib/src/main/java/com/my/company/codegen/MyclientcodegenGenerator.java +++ b/samples/meta-codegen/lib/src/main/java/com/my/company/codegen/MyclientcodegenGenerator.java @@ -181,6 +181,9 @@ public String apiFileFolder() { */ @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return input; + } //TODO: check that this logic is safe to escape unsafe characters to avoid code injection return input; } From adb699bb18944a29900d6050403610de830dfcc3 Mon Sep 17 00:00:00 2001 From: Joscha Feth Date: Mon, 9 Sep 2024 20:42:55 +1000 Subject: [PATCH 4/4] Update modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java --- .../java/org/openapitools/codegen/DefaultCodegenTest.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java index b795bd2382ed..d5da26e5be8f 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java @@ -780,14 +780,6 @@ public void testEscapeTextWhileAllowingNewLines() { Assertions.assertEquals(codegen.escapeTextWhileAllowingNewLines("\\/"), "/"); } - @Test - public void testescapeUnsafeCharacters() { - final DefaultCodegen codegen = new DefaultCodegen(); - - // allow null - Assertions.assertEquals(codegen.escapeUnsafeCharacters(null), null); - } - @Test public void updateCodegenPropertyEnum() { final DefaultCodegen codegen = new DefaultCodegen();