Skip to content

Commit 5b95839

Browse files
committed
good format
1 parent 768373d commit 5b95839

File tree

10 files changed

+330
-156
lines changed

10 files changed

+330
-156
lines changed

generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java

Lines changed: 82 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
package com.algolia.codegen;
22

3+
import io.swagger.v3.oas.models.Operation;
4+
import io.swagger.v3.oas.models.media.Schema;
5+
import io.swagger.v3.oas.models.servers.Server;
6+
import java.io.FileInputStream;
7+
import java.net.URL;
8+
import java.util.*;
39
import org.openapitools.codegen.*;
410
import org.openapitools.codegen.languages.JavaClientCodegen;
511
import org.openapitools.codegen.utils.ModelUtils;
612
import org.yaml.snakeyaml.Yaml;
713

8-
import java.util.*;
9-
import java.io.FileInputStream;
10-
import java.net.URL;
11-
12-
import io.swagger.v3.oas.models.Operation;
13-
import io.swagger.v3.oas.models.media.Schema;
14-
import io.swagger.v3.oas.models.servers.Server;
15-
1614
@SuppressWarnings("unchecked")
1715
public class AlgoliaJavaGenerator extends JavaClientCodegen {
16+
1817
/**
19-
* Configures a friendly name for the generator. This will be used by the
20-
* generator
21-
* to select the library with the -g flag.
18+
* Configures a friendly name for the generator. This will be used by the generator to select the
19+
* library with the -g flag.
2220
*
2321
* @return the friendly name for the generator
2422
*/
@@ -27,15 +25,17 @@ public String getName() {
2725
return "algolia-java";
2826
}
2927

30-
/**
31-
* Inject server info into the client to generate the right URL
32-
*/
28+
/** Inject server info into the client to generate the right URL */
3329
private void generateServer(Map<String, Object> client) {
3430
String clientName = (String) client.get("pathPrefix");
3531
Yaml yaml = new Yaml();
3632
try {
37-
Map<String, Object> spec = yaml.load(new FileInputStream("specs/" + clientName + "/spec.yml"));
38-
List<Map<String, Object>> servers = (List<Map<String, Object>>) spec.get("servers");
33+
Map<String, Object> spec = yaml.load(
34+
new FileInputStream("specs/" + clientName + "/spec.yml")
35+
);
36+
List<Map<String, Object>> servers = (List<Map<String, Object>>) spec.get(
37+
"servers"
38+
);
3939

4040
boolean hasRegionalHost = false;
4141
boolean fallbackToAliasHost = false;
@@ -47,19 +47,28 @@ private void generateServer(Map<String, Object> client) {
4747

4848
for (Map<String, Object> server : servers) {
4949
if (!server.containsKey("url")) {
50-
throw new GenerationException("Invalid server, does not contains 'url'");
50+
throw new GenerationException(
51+
"Invalid server, does not contains 'url'"
52+
);
5153
}
5254

5355
if (!server.containsKey("variables")) {
5456
continue;
5557
}
5658

57-
Map<String, Map<String, Object>> variables = (Map<String, Map<String, Object>>) server.get("variables");
59+
Map<String, Map<String, Object>> variables = (Map<String, Map<String, Object>>) server.get(
60+
"variables"
61+
);
5862

59-
if (!variables.containsKey("region") || !variables.get("region").containsKey("enum")) {
63+
if (
64+
!variables.containsKey("region") ||
65+
!variables.get("region").containsKey("enum")
66+
) {
6067
continue;
6168
}
62-
ArrayList<String> enums = (ArrayList<String>) variables.get("region").get("enum");
69+
ArrayList<String> enums = (ArrayList<String>) variables
70+
.get("region")
71+
.get("enum");
6372
hasRegionalHost = true;
6473

6574
URL url = new URL((String) server.get("url"));
@@ -95,18 +104,30 @@ private void generateServer(Map<String, Object> client) {
95104
}
96105

97106
@Override
98-
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
99-
return Utils.specifyCustomRequest(super.fromOperation(path, httpMethod, operation, servers));
107+
public CodegenOperation fromOperation(
108+
String path,
109+
String httpMethod,
110+
Operation operation,
111+
List<Server> servers
112+
) {
113+
return Utils.specifyCustomRequest(
114+
super.fromOperation(path, httpMethod, operation, servers)
115+
);
100116
}
101117

102-
/**
103-
* Provides an opportunity to inspect and modify operation data before the code
104-
* is generated.
105-
*/
118+
/** Provides an opportunity to inspect and modify operation data before the code is generated. */
106119
@Override
107-
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
108-
Map<String, Object> results = super.postProcessOperationsWithModels(objs, allModels);
109-
Map<String, Object> client = (Map<String, Object>) results.get("operations");
120+
public Map<String, Object> postProcessOperationsWithModels(
121+
Map<String, Object> objs,
122+
List<Object> allModels
123+
) {
124+
Map<String, Object> results = super.postProcessOperationsWithModels(
125+
objs,
126+
allModels
127+
);
128+
Map<String, Object> client = (Map<String, Object>) results.get(
129+
"operations"
130+
);
110131

111132
generateServer(client);
112133

@@ -118,7 +139,11 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
118139
Map<String, Object> models = super.postProcessAllModels(objs);
119140

120141
for (Object modelContainer : models.values()) {
121-
CodegenModel model = ((Map<String, List<Map<String, CodegenModel>>>) modelContainer).get("models").get(0)
142+
CodegenModel model =
143+
((Map<String, List<Map<String, CodegenModel>>>) modelContainer).get(
144+
"models"
145+
)
146+
.get(0)
122147
.get("model");
123148
if (!model.oneOf.isEmpty()) {
124149
List<HashMap<String, String>> listOneOf = new ArrayList();
@@ -127,7 +152,10 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
127152
HashMap<String, String> hashMapOneOf = new HashMap();
128153

129154
hashMapOneOf.put("type", iterateModel);
130-
hashMapOneOf.put("name", iterateModel.replace("<", "").replace(">", ""));
155+
hashMapOneOf.put(
156+
"name",
157+
iterateModel.replace("<", "").replace(">", "")
158+
);
131159

132160
listOneOf.add(hashMapOneOf);
133161
}
@@ -141,23 +169,33 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
141169
}
142170

143171
@Override
144-
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
172+
public Map<String, Object> postProcessSupportingFileData(
173+
Map<String, Object> objs
174+
) {
145175
Map<String, Object> bundle = super.postProcessSupportingFileData(objs);
146-
List<Map<String, Object>> apis = ((Map<String, List<Map<String, Object>>>) bundle.get("apiInfo")).get("apis");
176+
List<Map<String, Object>> apis =
177+
((Map<String, List<Map<String, Object>>>) bundle.get("apiInfo")).get(
178+
"apis"
179+
);
147180
for (Map<String, Object> api : apis) {
148-
List<CodegenOperation> operations = ((Map<String, List<CodegenOperation>>) api.get("operations"))
149-
.get("operation");
181+
List<CodegenOperation> operations =
182+
((Map<String, List<CodegenOperation>>) api.get("operations")).get(
183+
"operation"
184+
);
150185

151186
for (CodegenOperation ope : operations) {
152-
ope.returnType = ope.returnType.replace("Map<", "HashMap<").replace("List<", "ArrayList<");
187+
ope.returnType =
188+
ope.returnType
189+
.replace("Map<", "HashMap<")
190+
.replace("List<", "ArrayList<");
153191
}
154192
}
155193
return bundle;
156194
}
157195

158196
/**
159-
* Returns human-friendly help for the generator. Provide the consumer with help
160-
* tips, parameters here
197+
* Returns human-friendly help for the generator. Provide the consumer with help tips, parameters
198+
* here
161199
*
162200
* @return A string value for the help message
163201
*/
@@ -170,9 +208,13 @@ public String getHelp() {
170208
public void processOpts() {
171209
super.processOpts();
172210

173-
supportingFiles.add(new SupportingFile("EchoResponse.mustache",
211+
supportingFiles.add(
212+
new SupportingFile(
213+
"EchoResponse.mustache",
174214
"algoliasearch-core/com/algolia/utils/echo",
175-
"EchoResponse.java"));
215+
"EchoResponse.java"
216+
)
217+
);
176218

177219
// Prevent all useless file to generate
178220
apiTestTemplateFiles.clear();
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
package com.algolia.codegen;
22

3+
import io.swagger.v3.oas.models.Operation;
4+
import io.swagger.v3.oas.models.servers.Server;
35
import java.util.List;
4-
56
import org.openapitools.codegen.CodegenOperation;
67
import org.openapitools.codegen.languages.PhpClientCodegen;
78

8-
import io.swagger.v3.oas.models.Operation;
9-
import io.swagger.v3.oas.models.servers.Server;
10-
119
public class AlgoliaPhpGenerator extends PhpClientCodegen {
10+
1211
@Override
1312
public String getName() {
1413
return "algolia-php";
1514
}
1615

1716
@Override
18-
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
19-
return Utils.specifyCustomRequest(super.fromOperation(path, httpMethod, operation, servers));
17+
public CodegenOperation fromOperation(
18+
String path,
19+
String httpMethod,
20+
Operation operation,
21+
List<Server> servers
22+
) {
23+
return Utils.specifyCustomRequest(
24+
super.fromOperation(path, httpMethod, operation, servers)
25+
);
2026
}
2127
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.algolia.codegen;
22

33
public class GenerationException extends Exception {
4-
public GenerationException(String message) {
5-
super(message);
6-
}
4+
5+
public GenerationException(String message) {
6+
super(message);
7+
}
78
}

generators/src/main/java/com/algolia/codegen/Utils.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
package com.algolia.codegen;
22

3-
import java.util.Set;
4-
53
import com.google.common.collect.Sets;
6-
4+
import java.util.Set;
75
import org.openapitools.codegen.CodegenOperation;
86

97
public class Utils {
10-
public static final Set<String> CUSTOM_METHOD = Sets.newHashSet("del", "get", "post", "put");
8+
9+
public static final Set<String> CUSTOM_METHOD = Sets.newHashSet(
10+
"del",
11+
"get",
12+
"post",
13+
"put"
14+
);
1115

1216
public static String capitalize(String str) {
1317
return str.substring(0, 1).toUpperCase() + str.substring(1);
1418
}
1519

1620
/**
17-
* Will add the boolean `vendorExtensions.x-is-custom-request` to operations if
18-
* they should not escape '/' in the path variable
21+
* Will add the boolean `vendorExtensions.x-is-custom-request` to operations if they should not
22+
* escape '/' in the path variable
1923
*/
2024
public static CodegenOperation specifyCustomRequest(CodegenOperation ope) {
2125
if (CUSTOM_METHOD.contains(ope.nickname)) {

0 commit comments

Comments
 (0)