-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathCustomRegionGenerator.java
More file actions
71 lines (58 loc) · 2.22 KB
/
CustomRegionGenerator.java
File metadata and controls
71 lines (58 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package cloud.stackit.codegen;
import org.openapitools.codegen.CodegenProperty;
import org.openapitools.codegen.languages.GoClientCodegen;
import org.openapitools.codegen.CodegenParameter;
import java.util.Set;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.parameters.Parameter;
public class CustomRegionGenerator extends GoClientCodegen {
@Override
public String getName() {
// This is the name you will pass to the -g flag
return "cloud.stackit.codegen.CustomRegionGenerator";
}
public CustomRegionGenerator() {
super();
System.out.println("=== CUSTOM GO CLIENT GENERATOR INITIALIZED ===");
}
@Override
public CodegenProperty fromProperty(String name, Schema p, boolean required) {
CodegenProperty property = super.fromProperty(name, p, required);
if (isRegionField(property.name)) {
property.dataType = "string";
property.datatypeWithEnum = "string";
property.baseType = "string";
// Force template engine to treat this as a string
property.isString = true;
property.isInteger = false;
property.isLong = false;
property.isNumber = false;
property.isNumeric = false;
}
return property;
}
/**
* Intercepts operation parameters (query, path, header, body).
*/
@Override
public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
CodegenParameter parameter = super.fromParameter(param, imports);
if (isRegionField(parameter.paramName)) {
parameter.dataType = "string";
// Force template engine to treat this as a string
parameter.isString = true;
parameter.isInteger = false;
parameter.isLong = false;
parameter.isNumber = false;
// If it was previously an enum or another complex type, clear it
parameter.isEnum = false;
}
return parameter;
}
private boolean isRegionField(String name) {
if (name == null) {
return false;
}
return name.equalsIgnoreCase("region") || name.equalsIgnoreCase("regionId");
}
}