1+ {{define " structHeader" }}
2+ package {{Variable .Variables " structPackage" }};
3+
4+ import com.fasterxml.jackson.databind.JsonNode ;
5+ import lombok.AllArgsConstructor ;
6+ import lombok.Data ;
7+ import lombok.NoArgsConstructor ;
8+
9+ import java.io.Serializable ;
10+ import java.util.List ;
11+ import java.util.Map ;
12+ {{end }}
13+
14+ {{define " struct" }}
15+
16+ /* *
17+ * {{.Description}}
18+ * {{.Summary}}
19+ */
20+ @Data
21+ @NoArgsConstructor
22+ @AllArgsConstructor
23+ public class {{.Type.Expression }} implements Serializable {
24+ {{range $val := .Properties -}}
25+ /* *
26+ * {{.Description}}
27+ * {{.Summary}}
28+ */
29+ private {{$val .Type.Expression }} {{$val .Name }};
30+ {{end }}
31+ }
32+ {{end }}
33+
34+
35+ {{define " apiHeader" }}
36+ package {{Variable .Variables " apiPackage" }};
37+
38+ import {{Variable .Variables " structPackage" }}. *;
39+ import {{Variable .Variables " clientPackage" }}.ApiClient ;
40+ import com.fasterxml.jackson.core.type.TypeReference ;
41+ import com.fasterxml.jackson.databind.JsonNode ;
42+ import java.util.List ;
43+ import java.util.Map ;
44+ import java.util.HashMap ;
45+ {{end }}
46+
47+ {{define " api" }}
48+ /* *
49+ * {{.Description}}
50+ */
51+ public class {{Capitalize .Name }} {
52+
53+ private final ApiClient client;
54+
55+ public {{Capitalize .Name }}(ApiClient client) {
56+ this.client = client;
57+ }
58+
59+ {{range $val := .Paths -}}
60+ {{template " path" $val }}
61+ {{end }}
62+ }
63+ {{end }}
64+
65+
66+
67+ {{define " path" }}
68+
69+ public static final TypeReference<{{.Response.Expression }}> {{.Name }}ResultType = new TypeReference<{{.Response.Expression }}>() {
70+ };
71+
72+ /* *
73+ * {{.Description}}
74+ * {{.Summary}}
75+ */
76+ public {{.Response.Expression }} {{.Name }}({{template " parameters" . }}) {
77+ {{ if .Queries -}}
78+ Map<String,Object> params = new HashMap<String,Object>();
79+ {{range $idx ,$val := .Parameters -}}
80+ params.put (" {{$val.Name}}" ,{{$val .Alias }});
81+ {{end }}
82+ {{- else -}}
83+ {{if .Request }}{{else }}Map<String,Object> params = new HashMap<String,Object>();{{end }}
84+ {{- end }}
85+ return client. {{.Method }}({{.Path }}, {{- if .Request }}body{{else }}params{{end }}, {{.Name }}ResultType);
86+ }
87+ {{end }}
88+
89+
90+
91+
92+ {{define " parameters" }}
93+ {{- range $idx ,$val := .Parameters -}}{{if gt $idx 0}},{{end }} {{$val .Type.Expression }} {{$val .Alias }}{{- end -}}
94+ {{end }}
95+
96+
97+ {{define " client" }}
98+
99+ package {{Variable .Variables " clientPackage" }};
100+
101+ import com.fasterxml.jackson.core.type.TypeReference ;
102+
103+ import java.util.Map ;
104+
105+ public interface ApiClient {
106+
107+ <T> T get(String path, Map<String, Object> params, TypeReference<T> resultType);
108+
109+ <P, T> T put(String path, P body, TypeReference<T> resultType);
110+
111+ <P, T> T post(String path, P params, TypeReference<T> resultType);
112+
113+ <P, T> T delete(String path, P params, TypeReference<T> resultType);
114+ }
115+ {{end }}
0 commit comments