Skip to content

Commit aeb13a9

Browse files
committed
[kotlin] Added path sanitization in javadoc comments
1 parent 4ad76cc commit aeb13a9

File tree

6 files changed

+40
-7
lines changed

6 files changed

+40
-7
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,35 @@
4040
import java.util.stream.Collectors;
4141
import java.util.stream.Stream;
4242

43+
import com.samskivert.mustache.Mustache;
44+
import lombok.Getter;
45+
import lombok.Setter;
46+
import org.apache.commons.lang3.StringUtils;
47+
import org.openapitools.codegen.CliOption;
48+
import org.openapitools.codegen.CodegenConstants;
49+
import org.openapitools.codegen.CodegenModel;
50+
import org.openapitools.codegen.CodegenOperation;
51+
import org.openapitools.codegen.CodegenParameter;
52+
import org.openapitools.codegen.CodegenProperty;
53+
import org.openapitools.codegen.CodegenType;
54+
import org.openapitools.codegen.SupportingFile;
55+
import org.openapitools.codegen.VendorExtension;
56+
import org.openapitools.codegen.meta.features.ClientModificationFeature;
57+
import org.openapitools.codegen.meta.features.DocumentationFeature;
58+
import org.openapitools.codegen.meta.features.GlobalFeature;
59+
import org.openapitools.codegen.meta.features.ParameterFeature;
60+
import org.openapitools.codegen.meta.features.SchemaSupportFeature;
61+
import org.openapitools.codegen.meta.features.SecurityFeature;
62+
import org.openapitools.codegen.meta.features.WireFormatFeature;
63+
import org.openapitools.codegen.model.ModelMap;
64+
import org.openapitools.codegen.model.ModelsMap;
65+
import org.openapitools.codegen.model.OperationMap;
66+
import org.openapitools.codegen.model.OperationsMap;
67+
import org.openapitools.codegen.templating.mustache.ReplaceAllLambda;
68+
import org.openapitools.codegen.utils.ProcessUtils;
69+
import org.slf4j.Logger;
70+
import org.slf4j.LoggerFactory;
71+
4372
import static java.util.Collections.sort;
4473

4574
public class KotlinClientCodegen extends AbstractKotlinCodegen {
@@ -534,6 +563,10 @@ public void processOpts() {
534563
}
535564
writer.write(content);
536565
});
566+
// When a path is added to a Javadoc, if it ends with a `/*` is will cause a compiler error
567+
// as the parser interrupts that as a start of a multiline comment.
568+
// We replace paths like `/v1/foo/*` with `/v1/foo/<*>` to avoid this
569+
additionalProperties.put("sanitizePathComment", new ReplaceAllLambda("\\/\\*", "/<*>"));
537570
}
538571

539572
private void processDateLibrary() {

modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-ktor/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
4343
4444
{{#operation}}
4545
/**
46-
* {{{httpMethod}}} {{{path}}}
46+
* {{{httpMethod}}} {{#sanitizePathComment}}{{{path}}}{{/sanitizePathComment}}
4747
* {{summary}}
4848
* {{notes}}
4949
{{#allParams}} * @param {{{paramName}}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}

modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/api.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ import {{packageName}}.infrastructure.toMultiValue
123123
{{/isEnum}}
124124
{{/allParams}}
125125
/**
126-
* {{{httpMethod}}} {{{path}}}
126+
* {{{httpMethod}}} {{#sanitizePathComment}}{{{path}}}{{/sanitizePathComment}}
127127
* {{summary}}
128128
* {{notes}}
129129
{{#allParams}}* @param {{{paramName}}} {{description}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}{{/required}}
@@ -161,7 +161,7 @@ import {{packageName}}.infrastructure.toMultiValue
161161
}
162162

163163
/**
164-
* {{{httpMethod}}} {{{path}}}
164+
* {{{httpMethod}}} {{#sanitizePathComment}}{{{path}}}{{/sanitizePathComment}}
165165
* {{summary}}
166166
* {{notes}}
167167
{{#allParams}}* @param {{{paramName}}} {{description}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}{{/required}}

modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ import okhttp3.MultipartBody
131131
{{/isEnum}}
132132
{{/allParams}}
133133
/**
134-
* {{{httpMethod}}} {{{path}}}
134+
* {{{httpMethod}}} {{#sanitizePathComment}}{{{path}}}{{/sanitizePathComment}}
135135
* {{summary}}
136136
* {{notes}}
137137
* Responses:{{#responses}}

modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-vertx/api.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ import {{packageName}}.infrastructure.*
8888
{{/isEnum}}
8989
{{/allParams}}
9090
/**
91-
* {{{httpMethod}}} {{{path}}}
91+
* {{{httpMethod}}} {{#sanitizePathComment}}{{{path}}}{{/sanitizePathComment}}
9292
* {{summary}}
9393
* {{notes}}
9494
{{#allParams}}* @param {{{paramName}}} {{description}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}{{/required}}
@@ -123,7 +123,7 @@ import {{packageName}}.infrastructure.*
123123
}
124124

125125
/**
126-
* {{{httpMethod}}} {{{path}}}
126+
* {{{httpMethod}}} {{#sanitizePathComment}}{{{path}}}{{/sanitizePathComment}}
127127
* {{summary}}
128128
* {{notes}}
129129
{{#allParams}}* @param {{{paramName}}} {{description}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}{{/required}}

modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-volley/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {{packageName}}.infrastructure.CollectionFormats.*
3737
3838
{{#operation}}
3939
/**
40-
* {{{httpMethod}}} {{{path}}}
40+
* {{{httpMethod}}} {{#sanitizePathComment}}{{{path}}}{{/sanitizePathComment}}
4141
* {{summary}}
4242
* {{notes}}
4343
{{#allParams}}* @param {{{paramName}}} {{description}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}{{/required}}

0 commit comments

Comments
 (0)