Skip to content

Commit d2f5351

Browse files
committed
fix: tests maybe
1 parent 30aac91 commit d2f5351

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.algolia.codegen.exceptions.*;
44
import com.algolia.codegen.utils.*;
5-
import com.fasterxml.jackson.databind.JsonNode;
65
import io.swagger.v3.oas.models.OpenAPI;
76
import io.swagger.v3.oas.models.Operation;
87
import io.swagger.v3.oas.models.servers.Server;
@@ -29,7 +28,7 @@ public String getName() {
2928
public void processOpts() {
3029
super.processOpts();
3130

32-
CLIENT = Helpers.camelize(getClientName((String) additionalProperties.get("client")));
31+
CLIENT = Helpers.camelize(Helpers.getClientName((String) additionalProperties.get("client")));
3332
isAlgoliasearchClient = CLIENT.equals("algoliasearch");
3433

3534
// generator specific options
@@ -147,24 +146,6 @@ public static String getPackageName(String client) throws ConfigException {
147146
return output.substring(output.lastIndexOf("/") + 1);
148147
}
149148

150-
// Get the clientName from the clients.config.json
151-
public static String getClientName(String client) throws ConfigException {
152-
JsonNode clientName = StreamSupport.stream(
153-
Spliterators.spliteratorUnknownSize(Helpers.getClientConfig("javascript").get("clients").elements(), Spliterator.ORDERED),
154-
false
155-
)
156-
.filter(node -> node.get("name").asText().equals(client))
157-
.findFirst()
158-
.orElseThrow(() -> new ConfigException("Cannot find client " + client + " in config/clients.config.json"))
159-
.get("clientName");
160-
161-
if (clientName == null) {
162-
return client;
163-
}
164-
165-
return clientName.asText();
166-
}
167-
168149
/** Set default generator options */
169150
private void setDefaultGeneratorOptions() {
170151
String clientName = CLIENT + Helpers.API_SUFFIX;

generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void processOpts() {
4242
super.processOpts();
4343

4444
language = (String) additionalProperties.get("language");
45-
client = (String) additionalProperties.get("client");
45+
client = Helpers.getClientName((String) additionalProperties.get("client"));
4646
mode = (String) additionalProperties.get("mode");
4747
ctsManager = CTSManagerFactory.getManager(language, client);
4848

generators/src/main/java/com/algolia/codegen/utils/Helpers.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.net.URL;
1111
import java.nio.file.Files;
1212
import java.util.*;
13+
import java.util.stream.StreamSupport;
1314
import org.apache.commons.lang3.StringUtils;
1415
import org.openapitools.codegen.CodegenOperation;
1516
import org.openapitools.codegen.CodegenServer;
@@ -192,6 +193,29 @@ public static String getPackageJsonVersion(String client) throws ConfigException
192193
}
193194
}
194195

196+
// Get the clientName from the clients.config.json
197+
public static String getClientName(String client) throws ConfigException {
198+
JsonNode clientField = StreamSupport.stream(
199+
Spliterators.spliteratorUnknownSize(Helpers.getClientConfig("javascript").get("clients").elements(), Spliterator.ORDERED),
200+
false
201+
)
202+
.filter(node -> node.get("name").asText().equals(client))
203+
.findFirst()
204+
.orElse(null);
205+
206+
if (clientField == null) {
207+
return client;
208+
}
209+
210+
JsonNode clientName = clientField.get("clientName");
211+
212+
if (clientName == null) {
213+
return client;
214+
}
215+
216+
return clientName.asText();
217+
}
218+
195219
/** Get the `field` value in the `config/clients.config.json` file for the given language */
196220
public static String getClientConfigField(String language, String... fields) throws ConfigException {
197221
if (fields.length == 0) {

0 commit comments

Comments
 (0)