1919
2020import org .openapitools .codegen .CliOption ;
2121import org .openapitools .codegen .CodegenConstants ;
22- import org .openapitools .codegen .CodegenModel ;
2322import org .openapitools .codegen .CodegenOperation ;
24- import org .openapitools .codegen .CodegenProperty ;
2523import org .openapitools .codegen .CodegenType ;
2624import org .openapitools .codegen .SupportingFile ;
2725
2826import java .io .File ;
2927import java .util .HashMap ;
30- import java .util .HashSet ;
31- import java .util .Iterator ;
3228import java .util .List ;
3329import java .util .Map ;
34- import java .util .Set ;
35- import java .util .regex .Pattern ;
3630
3731public class KotlinClientCodegen extends AbstractKotlinCodegen {
3832
39- protected static final String VENDOR_EXTENSION_ESCAPED_NAME = "x-escapedName" ;
40-
4133 protected static final String JVM = "jvm" ;
4234 protected static final String MULTIPLATFORM = "multiplatform" ;
4335
@@ -47,14 +39,6 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
4739 protected String dateLibrary = DateLibrary .JAVA8 .value ;
4840 protected String collectionType = CollectionType .ARRAY .value ;
4941
50- // https://kotlinlang.org/docs/reference/grammar.html#Identifier
51- protected static final Pattern IDENTIFIER_PATTERN =
52- Pattern .compile ("[\\ p{Ll}\\ p{Lm}\\ p{Lo}\\ p{Lt}\\ p{Lu}\\ p{Nl}_][\\ p{Ll}\\ p{Lm}\\ p{Lo}\\ p{Lt}\\ p{Lu}\\ p{Nl}\\ p{Nd}_]*" );
53-
54- // https://kotlinlang.org/docs/reference/grammar.html#Identifier
55- protected static final String IDENTIFIER_REPLACEMENTS =
56- "[.;:/\\ [\\ ]<>]" ;
57-
5842 public enum DateLibrary {
5943 STRING ("string" ),
6044 THREETENBP ("threetenbp" ),
@@ -212,7 +196,6 @@ public void processOpts() {
212196 supportingFiles .add (new SupportingFile ("infrastructure/HttpResponse.kt.mustache" , infrastructureFolder , "HttpResponse.kt" ));
213197
214198 // multiplatform specific testing files
215- final String testFolder = (sourceFolder + File .separator + packageName + File .separator + "infrastructure" ).replace ("." , "/" );
216199 supportingFiles .add (new SupportingFile ("commonTest/coroutine.mustache" , "src/commonTest/kotlin/util" , "Coroutine.kt" ));
217200 supportingFiles .add (new SupportingFile ("iosTest/coroutine.mustache" , "src/iosTest/kotlin/util" , "Coroutine.kt" ));
218201 supportingFiles .add (new SupportingFile ("jvmTest/coroutine.mustache" , "src/jvmTest/kotlin/util" , "Coroutine.kt" ));
@@ -253,58 +236,6 @@ public void processOpts() {
253236 }
254237 }
255238
256- @ Override
257- public Map <String , Object > postProcessModels (Map <String , Object > objs ) {
258- objs = super .postProcessModels (objs );
259- return postProcessModelsEscapeNames (objs );
260- }
261-
262- @ SuppressWarnings ("unchecked" )
263- private static Map <String , Object > postProcessModelsEscapeNames (Map <String , Object > objs ) {
264- List <Object > models = (List <Object >) objs .get ("models" );
265- for (Object _mo : models ) {
266- Map <String , Object > mo = (Map <String , Object >) _mo ;
267- CodegenModel cm = (CodegenModel ) mo .get ("model" );
268-
269- if (cm .vars != null ) {
270- for (CodegenProperty var : cm .vars ) {
271- var .vendorExtensions .put (VENDOR_EXTENSION_ESCAPED_NAME , escapeIdentifier (var .name ));
272- }
273- }
274- if (cm .requiredVars != null ) {
275- for (CodegenProperty var : cm .requiredVars ) {
276- var .vendorExtensions .put (VENDOR_EXTENSION_ESCAPED_NAME , escapeIdentifier (var .name ));
277- }
278- }
279- if (cm .optionalVars != null ) {
280- for (CodegenProperty var : cm .optionalVars ) {
281- var .vendorExtensions .put (VENDOR_EXTENSION_ESCAPED_NAME , escapeIdentifier (var .name ));
282- }
283- }
284- }
285- return objs ;
286- }
287-
288- private static String escapeIdentifier (String identifier ) {
289-
290- // the kotlin grammar permits a wider set of characters in their identifiers that all target
291- // platforms permit (namely jvm). in order to remain compatible with target platforms, we
292- // initially replace all illegal target characters before escaping the identifier if required.
293- identifier = identifier .replaceAll (IDENTIFIER_REPLACEMENTS , "_" );
294- if (IDENTIFIER_PATTERN .matcher (identifier ).matches ()) return identifier ;
295- return '`' + identifier + '`' ;
296- }
297-
298- private static void removeDuplicates (List <CodegenProperty > list ) {
299- Set <String > set = new HashSet <>();
300- Iterator <CodegenProperty > iterator = list .iterator ();
301- while (iterator .hasNext ()) {
302- CodegenProperty item = iterator .next ();
303- if (set .contains (item .name )) iterator .remove ();
304- else set .add (item .name );
305- }
306- }
307-
308239 @ Override
309240 @ SuppressWarnings ("unchecked" )
310241 public Map <String , Object > postProcessOperationsWithModels (Map <String , Object > objs , List <Object > allModels ) {
0 commit comments