Skip to content

Commit 39eb92b

Browse files
authored
chore(go): update enum casing (#3163)
1 parent d67050d commit 39eb92b

File tree

7 files changed

+40
-15
lines changed

7 files changed

+40
-15
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.algolia.codegen;
22

33
import com.algolia.codegen.exceptions.*;
4+
import com.algolia.codegen.lambda.ScreamingSnakeCaseLambda;
45
import com.algolia.codegen.utils.*;
56
import com.algolia.codegen.utils.OneOf;
7+
import com.google.common.collect.ImmutableMap;
68
import com.google.common.collect.Iterables;
9+
import com.samskivert.mustache.Mustache;
710
import io.swagger.v3.oas.models.OpenAPI;
811
import io.swagger.v3.oas.models.Operation;
912
import io.swagger.v3.oas.models.servers.Server;
@@ -55,6 +58,11 @@ public void processOpts() {
5558
}
5659
}
5760

61+
@Override
62+
protected ImmutableMap.Builder<String, Mustache.Lambda> addMustacheLambdas() {
63+
return super.addMustacheLambdas().put("screamingSnakeCase", new ScreamingSnakeCaseLambda());
64+
}
65+
5866
@Override
5967
public void processOpenAPI(OpenAPI openAPI) {
6068
super.processOpenAPI(openAPI);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.algolia.codegen.lambda;
2+
3+
import com.algolia.codegen.utils.Helpers;
4+
import com.samskivert.mustache.Mustache;
5+
import com.samskivert.mustache.Template;
6+
import java.io.IOException;
7+
import java.io.Writer;
8+
import java.util.Locale;
9+
10+
public class ScreamingSnakeCaseLambda implements Mustache.Lambda {
11+
12+
@Override
13+
public void execute(Template.Fragment fragment, Writer writer) throws IOException {
14+
writer.write(Helpers.toSnakeCase(fragment.execute()).toUpperCase(Locale.ROOT));
15+
}
16+
}

playground/go/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
1414
github.com/go-playground/locales v0.14.1 // indirect
1515
github.com/go-playground/universal-translator v0.18.1 // indirect
16-
github.com/go-playground/validator/v10 v10.19.0 // indirect
16+
github.com/go-playground/validator/v10 v10.21.0 // indirect
1717
github.com/leodido/go-urn v1.4.0 // indirect
1818
golang.org/x/crypto v0.22.0 // indirect
1919
golang.org/x/net v0.24.0 // indirect

playground/go/go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
1010
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
1111
github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4=
1212
github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
13+
github.com/go-playground/validator/v10 v10.21.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
1314
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
1415
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
1516
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=

templates/go/model_enum.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const (
77
{{#enumVars}}
88
{{^-first}}
99
{{/-first}}
10-
{{#enumClassPrefix}}{{{classname.toUpperCase}}}_{{/enumClassPrefix}}{{name}} {{{classname}}} = {{{value}}}
10+
{{#enumClassPrefix}}{{#lambda.screamingSnakeCase}}{{{classname}}}{{/lambda.screamingSnakeCase}}_{{/enumClassPrefix}}{{name}} {{{classname}}} = {{{value}}}
1111
{{/enumVars}}
1212
{{/allowableValues}}
1313
)
@@ -98,4 +98,4 @@ func (v Nullable{{{classname}}}) MarshalJSON() ([]byte, error) {
9898
func (v *Nullable{{{classname}}}) UnmarshalJSON(src []byte) error {
9999
v.isSet = true
100100
return json.Unmarshal(src, &v.value) //nolint:wrapcheck
101-
}
101+
}

templates/go/search_helpers.mustache

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (c *APIClient) WaitForTaskWithContext(
7373
return false
7474
}
7575

76-
return response.Status == TASKSTATUS_PUBLISHED
76+
return response.Status == TASK_STATUS_PUBLISHED
7777
},
7878
maxRetries,
7979
initialDelay,
@@ -151,7 +151,7 @@ func (c *APIClient) WaitForAppTaskWithContext(
151151
return false
152152
}
153153

154-
return response.Status == TASKSTATUS_PUBLISHED
154+
return response.Status == TASK_STATUS_PUBLISHED
155155
},
156156
maxRetries,
157157
initialDelay,
@@ -284,11 +284,11 @@ func (c *APIClient) WaitForApiKeyWithContext(
284284
maxDelay *time.Duration,
285285
opts ...Option,
286286
) (*GetApiKeyResponse, error) {
287-
if operation != APIKEYOPERATION_ADD && operation != APIKEYOPERATION_DELETE && operation != APIKEYOPERATION_UPDATE {
287+
if operation != API_KEY_OPERATION_ADD && operation != API_KEY_OPERATION_DELETE && operation != API_KEY_OPERATION_UPDATE {
288288
return nil, &errs.WaitKeyOperationError{}
289289
}
290290

291-
if operation == APIKEYOPERATION_UPDATE {
291+
if operation == API_KEY_OPERATION_UPDATE {
292292
if apiKey == nil {
293293
return nil, &errs.WaitKeyUpdateError{}
294294
}
@@ -353,9 +353,9 @@ func (c *APIClient) WaitForApiKeyWithContext(
353353
},
354354
func(response *GetApiKeyResponse, err error) bool {
355355
switch operation {
356-
case APIKEYOPERATION_ADD:
356+
case API_KEY_OPERATION_ADD:
357357
return err == nil && response != nil && response.CreatedAt > 0
358-
case APIKEYOPERATION_DELETE:
358+
case API_KEY_OPERATION_DELETE:
359359
if _, ok := err.(*APIError); ok {
360360
apiErr := err.(*APIError)
361361
@@ -520,7 +520,7 @@ func (c *APIClient) ChunkedBatch(indexName string, objects []map[string]any, act
520520
func (c *APIClient) ReplaceAllObjects(indexName string, objects []map[string]any, batchSize *int) (*ReplaceAllObjectsResponse, error) {
521521
tmpIndexName := fmt.Sprintf("%s_tmp_%d", indexName, time.Now().UnixNano())
522522
523-
copyResp, err := c.OperationIndex(c.NewApiOperationIndexRequest(indexName, NewOperationIndexParams(OPERATIONTYPE_COPY, tmpIndexName, WithOperationIndexParamsScope([]ScopeType{SCOPETYPE_RULES, SCOPETYPE_SETTINGS, SCOPETYPE_SYNONYMS}))))
523+
copyResp, err := c.OperationIndex(c.NewApiOperationIndexRequest(indexName, NewOperationIndexParams(OPERATION_TYPE_COPY, tmpIndexName, WithOperationIndexParamsScope([]ScopeType{SCOPE_TYPE_RULES, SCOPE_TYPE_SETTINGS, SCOPE_TYPE_SYNONYMS}))))
524524
if err != nil {
525525
return nil, err
526526
}
@@ -537,7 +537,7 @@ func (c *APIClient) ReplaceAllObjects(indexName string, objects []map[string]any
537537
return nil, err
538538
}
539539

540-
copyResp, err = c.OperationIndex(c.NewApiOperationIndexRequest(indexName, NewOperationIndexParams(OPERATIONTYPE_COPY, tmpIndexName, WithOperationIndexParamsScope([]ScopeType{SCOPETYPE_RULES, SCOPETYPE_SETTINGS, SCOPETYPE_SYNONYMS}))))
540+
copyResp, err = c.OperationIndex(c.NewApiOperationIndexRequest(indexName, NewOperationIndexParams(OPERATION_TYPE_COPY, tmpIndexName, WithOperationIndexParamsScope([]ScopeType{SCOPE_TYPE_RULES, SCOPE_TYPE_SETTINGS, SCOPE_TYPE_SYNONYMS}))))
541541
if err != nil {
542542
return nil, err
543543
}
@@ -547,7 +547,7 @@ func (c *APIClient) ReplaceAllObjects(indexName string, objects []map[string]any
547547
return nil, err
548548
}
549549

550-
moveResp, err := c.OperationIndex(c.NewApiOperationIndexRequest(tmpIndexName, NewOperationIndexParams(OPERATIONTYPE_MOVE, indexName)))
550+
moveResp, err := c.OperationIndex(c.NewApiOperationIndexRequest(tmpIndexName, NewOperationIndexParams(OPERATION_TYPE_MOVE, indexName)))
551551
if err != nil {
552552
return nil, err
553553
}

website/src/snippets.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ export function waitForApiKeySnippet(language, operation) {
6666
'delete': ``,
6767
},
6868
'go': {
69-
'add': `waitResponse, err := client.WaitForApiKey(search.APIKEYOPERATION_ADD, response.Key, nil)
69+
'add': `waitResponse, err := client.WaitForApiKey(search.API_KEY_OPERATION_ADD, response.Key, nil)
7070
if err != nil {
7171
panic(err)
7272
}`,
73-
'update': `waitResponse, err := client.WaitForApiKey(search.APIKEYOPERATION_UPDATE, response.Key, search.NewEmptyApiKey().SetAcl([]search.Acl{search.Acl("search"), search.Acl("addObject")}).SetValidity(300).SetMaxQueriesPerIPPerHour(100).SetMaxHitsPerQuery(20))
73+
'update': `waitResponse, err := client.WaitForApiKey(search.API_KEY_OPERATION_UPDATE, response.Key, search.NewEmptyApiKey().SetAcl([]search.Acl{search.Acl("search"), search.Acl("addObject")}).SetValidity(300).SetMaxQueriesPerIPPerHour(100).SetMaxHitsPerQuery(20))
7474
if err != nil {
7575
panic(err)
7676
}`,
77-
'delete': `waitResponse, err := client.WaitForApiKey(search.APIKEYOPERATION_DELETE, response.Key, nil)
77+
'delete': `waitResponse, err := client.WaitForApiKey(search.API_KEY_OPERATION_DELETE, response.Key, nil)
7878
if err != nil {
7979
panic(err)
8080
}`,

0 commit comments

Comments
 (0)