Skip to content

chore(go): update enum casing #3163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.algolia.codegen;

import com.algolia.codegen.exceptions.*;
import com.algolia.codegen.lambda.ScreamingSnakeCaseLambda;
import com.algolia.codegen.utils.*;
import com.algolia.codegen.utils.OneOf;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.samskivert.mustache.Mustache;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.servers.Server;
Expand Down Expand Up @@ -55,6 +58,11 @@ public void processOpts() {
}
}

@Override
protected ImmutableMap.Builder<String, Mustache.Lambda> addMustacheLambdas() {
return super.addMustacheLambdas().put("screamingSnakeCase", new ScreamingSnakeCaseLambda());
}

@Override
public void processOpenAPI(OpenAPI openAPI) {
super.processOpenAPI(openAPI);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.algolia.codegen.lambda;

import com.algolia.codegen.utils.Helpers;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
import java.io.IOException;
import java.io.Writer;
import java.util.Locale;

public class ScreamingSnakeCaseLambda implements Mustache.Lambda {

@Override
public void execute(Template.Fragment fragment, Writer writer) throws IOException {
writer.write(Helpers.toSnakeCase(fragment.execute()).toUpperCase(Locale.ROOT));
}
}
2 changes: 1 addition & 1 deletion playground/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.19.0 // indirect
github.com/go-playground/validator/v10 v10.21.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions playground/go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4=
github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-playground/validator/v10 v10.21.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
Expand Down
4 changes: 2 additions & 2 deletions templates/go/model_enum.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const (
{{#enumVars}}
{{^-first}}
{{/-first}}
{{#enumClassPrefix}}{{{classname.toUpperCase}}}_{{/enumClassPrefix}}{{name}} {{{classname}}} = {{{value}}}
{{#enumClassPrefix}}{{#lambda.screamingSnakeCase}}{{{classname}}}{{/lambda.screamingSnakeCase}}_{{/enumClassPrefix}}{{name}} {{{classname}}} = {{{value}}}
{{/enumVars}}
{{/allowableValues}}
)
Expand Down Expand Up @@ -98,4 +98,4 @@ func (v Nullable{{{classname}}}) MarshalJSON() ([]byte, error) {
func (v *Nullable{{{classname}}}) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value) //nolint:wrapcheck
}
}
18 changes: 9 additions & 9 deletions templates/go/search_helpers.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (c *APIClient) WaitForTaskWithContext(
return false
}

return response.Status == TASKSTATUS_PUBLISHED
return response.Status == TASK_STATUS_PUBLISHED
},
maxRetries,
initialDelay,
Expand Down Expand Up @@ -151,7 +151,7 @@ func (c *APIClient) WaitForAppTaskWithContext(
return false
}

return response.Status == TASKSTATUS_PUBLISHED
return response.Status == TASK_STATUS_PUBLISHED
},
maxRetries,
initialDelay,
Expand Down Expand Up @@ -284,11 +284,11 @@ func (c *APIClient) WaitForApiKeyWithContext(
maxDelay *time.Duration,
opts ...Option,
) (*GetApiKeyResponse, error) {
if operation != APIKEYOPERATION_ADD && operation != APIKEYOPERATION_DELETE && operation != APIKEYOPERATION_UPDATE {
if operation != API_KEY_OPERATION_ADD && operation != API_KEY_OPERATION_DELETE && operation != API_KEY_OPERATION_UPDATE {
return nil, &errs.WaitKeyOperationError{}
}

if operation == APIKEYOPERATION_UPDATE {
if operation == API_KEY_OPERATION_UPDATE {
if apiKey == nil {
return nil, &errs.WaitKeyUpdateError{}
}
Expand Down Expand Up @@ -353,9 +353,9 @@ func (c *APIClient) WaitForApiKeyWithContext(
},
func(response *GetApiKeyResponse, err error) bool {
switch operation {
case APIKEYOPERATION_ADD:
case API_KEY_OPERATION_ADD:
return err == nil && response != nil && response.CreatedAt > 0
case APIKEYOPERATION_DELETE:
case API_KEY_OPERATION_DELETE:
if _, ok := err.(*APIError); ok {
apiErr := err.(*APIError)

Expand Down Expand Up @@ -520,7 +520,7 @@ func (c *APIClient) ChunkedBatch(indexName string, objects []map[string]any, act
func (c *APIClient) ReplaceAllObjects(indexName string, objects []map[string]any, batchSize *int) (*ReplaceAllObjectsResponse, error) {
tmpIndexName := fmt.Sprintf("%s_tmp_%d", indexName, time.Now().UnixNano())

copyResp, err := c.OperationIndex(c.NewApiOperationIndexRequest(indexName, NewOperationIndexParams(OPERATIONTYPE_COPY, tmpIndexName, WithOperationIndexParamsScope([]ScopeType{SCOPETYPE_RULES, SCOPETYPE_SETTINGS, SCOPETYPE_SYNONYMS}))))
copyResp, err := c.OperationIndex(c.NewApiOperationIndexRequest(indexName, NewOperationIndexParams(OPERATION_TYPE_COPY, tmpIndexName, WithOperationIndexParamsScope([]ScopeType{SCOPE_TYPE_RULES, SCOPE_TYPE_SETTINGS, SCOPE_TYPE_SYNONYMS}))))
if err != nil {
return nil, err
}
Expand All @@ -537,7 +537,7 @@ func (c *APIClient) ReplaceAllObjects(indexName string, objects []map[string]any
return nil, err
}

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

moveResp, err := c.OperationIndex(c.NewApiOperationIndexRequest(tmpIndexName, NewOperationIndexParams(OPERATIONTYPE_MOVE, indexName)))
moveResp, err := c.OperationIndex(c.NewApiOperationIndexRequest(tmpIndexName, NewOperationIndexParams(OPERATION_TYPE_MOVE, indexName)))
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions website/src/snippets.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ export function waitForApiKeySnippet(language, operation) {
'delete': ``,
},
'go': {
'add': `waitResponse, err := client.WaitForApiKey(search.APIKEYOPERATION_ADD, response.Key, nil)
'add': `waitResponse, err := client.WaitForApiKey(search.API_KEY_OPERATION_ADD, response.Key, nil)
if err != nil {
panic(err)
}`,
'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))
'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))
if err != nil {
panic(err)
}`,
'delete': `waitResponse, err := client.WaitForApiKey(search.APIKEYOPERATION_DELETE, response.Key, nil)
'delete': `waitResponse, err := client.WaitForApiKey(search.API_KEY_OPERATION_DELETE, response.Key, nil)
if err != nil {
panic(err)
}`,
Expand Down
Loading