22
33import com .algolia .codegen .exceptions .*;
44import com .algolia .codegen .utils .*;
5+ import com .fasterxml .jackson .databind .JsonNode ;
56import io .swagger .v3 .oas .models .OpenAPI ;
67import io .swagger .v3 .oas .models .Operation ;
78import io .swagger .v3 .oas .models .servers .Server ;
@@ -28,7 +29,7 @@ public String getName() {
2829 public void processOpts () {
2930 super .processOpts ();
3031
31- CLIENT = Helpers .camelize (( String ) additionalProperties .get ("client" ));
32+ CLIENT = Helpers .camelize (getClientName (( String ) additionalProperties .get ("client" ) ));
3233 isAlgoliasearchClient = CLIENT .equals ("algoliasearch" );
3334
3435 // generator specific options
@@ -146,14 +147,31 @@ public static String getPackageName(String client) throws ConfigException {
146147 return output .substring (output .lastIndexOf ("/" ) + 1 );
147148 }
148149
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+
149168 /** Set default generator options */
150169 private void setDefaultGeneratorOptions () {
151170 String clientName = CLIENT + Helpers .API_SUFFIX ;
152171 String packageName = getPackageName ((String ) additionalProperties .get ("client" ));
153172
154173 additionalProperties .put ("apiName" , CLIENT );
155- // Just so the full client doesn't have the weird Full naming
156- additionalProperties .put ("clientName" , CLIENT .contains ("composition" ) ? "composition" + Helpers .API_SUFFIX : clientName );
174+ additionalProperties .put ("clientName" , clientName );
157175 additionalProperties .put ("algoliaAgent" , Helpers .capitalize (CLIENT ));
158176 additionalProperties .put ("is" + Helpers .capitalize (Helpers .camelize ((String ) additionalProperties .get ("client" ))) + "Client" , true );
159177 additionalProperties .put ("isSearchClient" , CLIENT .equals ("search" ) || isAlgoliasearchClient );
0 commit comments