1- package cloud .stackit .codegen ;
2-
1+ import io .swagger .v3 .oas .models .media .Schema ;
2+ import io .swagger .v3 .oas .models .parameters .Parameter ;
3+ import org .openapitools .codegen .CodegenParameter ;
34import org .openapitools .codegen .CodegenProperty ;
45import org .openapitools .codegen .languages .GoClientCodegen ;
6+ import shared .PostProcessFileReplace ;
57
6- import org .openapitools .codegen .CodegenParameter ;
7-
8+ import java .io .File ;
89import java .util .Set ;
9- import io .swagger .v3 .oas .models .media .Schema ;
10- import io .swagger .v3 .oas .models .parameters .Parameter ;
1110
12- public class CustomRegionGenerator extends GoClientCodegen {
11+ public class GoGenerator extends GoClientCodegen {
12+ private static RegionFix regionFix = new RegionFix ();
13+ private static PostProcessFileReplace postProcessFileReplace = new PostProcessFileReplace ("overrides/go" );
1314
1415 @ Override
1516 public String getName () {
16- // This is the name you will pass to the -g flag
17- return "cloud.stackit.codegen.CustomRegionGenerator" ;
17+ return "GoClientCodegen" ;
1818 }
1919
20- public CustomRegionGenerator () {
20+ public GoGenerator () {
2121 super ();
22- System .out .println ("=== CUSTOM GO CLIENT GENERATOR INITIALIZED ===" );
22+ System .out .println ("=== Custom Go Generator initialized ===" );
2323 }
2424
2525 @ Override
2626 public CodegenProperty fromProperty (String name , Schema p , boolean required ) {
27- CodegenProperty property = super .fromProperty (name , p , required );
27+ return regionFix .fromProperty (super .fromProperty (name , p , required ));
28+ }
2829
30+ @ Override
31+ public CodegenParameter fromParameter (Parameter parameter , Set <String > imports ) {
32+ return regionFix .fromParameter (super .fromParameter (parameter , imports ));
33+ }
34+
35+ @ Override
36+ public void postProcessFile (File file , String fileType ) {
37+ postProcessFileReplace .process (file );
38+ super .postProcessFile (file , fileType );
39+ }
40+ }
41+
42+ class RegionFix {
43+ CodegenProperty fromProperty (CodegenProperty property ) {
2944 if (isRegionField (property .name )) {
3045 property .dataType = "string" ;
3146 property .datatypeWithEnum = "string" ;
@@ -41,13 +56,7 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required) {
4156 return property ;
4257 }
4358
44- /**
45- * Intercepts operation parameters (query, path, header, body).
46- */
47- @ Override
48- public CodegenParameter fromParameter (Parameter param , Set <String > imports ) {
49- CodegenParameter parameter = super .fromParameter (param , imports );
50-
59+ CodegenParameter fromParameter (CodegenParameter parameter ) {
5160 if (isRegionField (parameter .paramName )) {
5261 parameter .dataType = "string" ;
5362
@@ -62,7 +71,7 @@ public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
6271 return parameter ;
6372 }
6473
65- private boolean isRegionField (String name ) {
74+ private static boolean isRegionField (String name ) {
6675 if (name == null ) {
6776 return false ;
6877 }
0 commit comments