-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(go): initial setup for go client (#1423)
## 🧭 What and Why 🎟 JIRA Ticket: https://algolia.atlassian.net/browse/APIC-656 Go API client generation initial setup to prepare the groundwork is implemented. It is heavily inspired by #1102. As decided in the RFC Go 1.19 is set as the version to go for now. ### Changes included: - CI pipeline updated to not break current flows. - Dockerfile updated to support go. - Client configs are created according to https://github.com/algolia/algoliasearch-client-go. - Go code generator implemented in `generators/src/main/java/com/algolia/codegen/AlgoliaGoGenerator.java` to follow a similar folder/packaging as the original client. - Basic playground setup for ingestion client is created. - Initial Go templates are created. It is mostly copied from #1102 and some parts are altered to cover other cases. Most of the creation problems are fixed but still, there are some problems to be handled in the future. Since it is already far from ready. It is not logical to block groundwork development for now. ### Future Steps: - Go mustache templates still need more improvements. - Optional body parameters are not properly handled yet. In some cases, code generation is not working as expected. - All the [client requirements](https://api-clients-automation.netlify.app/docs/contributing/add-new-language/#algolia-requirements) should be implemented in the generated code. - CTS development should be done. - The release pipeline for the generated code should be set to create automated releases on the API client. - (Nice to Have) fix docker container PATH to recognize go with yarn commands. - Somehow [`run`](https://github.com/algolia/api-clients-automation/blob/main/scripts/common.ts#L78) function PATH was not capturing the PATH updates that I made in Dockerfile. I have tried different approaches but couldn't resolve it properly. ## 🧪 Test A small playground example was added. Initial linting with the generated code is fine except for some cases mentioned on `Future Steps`.
- Loading branch information
1 parent
9bdc5ad
commit 3e12a19
Showing
36 changed files
with
1,701 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.0.20 | ||
0.0.21 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/algolia/algoliasearch-client-go/v4 | ||
|
||
go 1.19 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.19.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
generators/src/main/java/com/algolia/codegen/AlgoliaGoGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.algolia.codegen; | ||
|
||
import com.algolia.codegen.exceptions.*; | ||
import java.io.File; | ||
import org.openapitools.codegen.SupportingFile; | ||
import org.openapitools.codegen.languages.GoClientCodegen; | ||
|
||
public class AlgoliaGoGenerator extends GoClientCodegen { | ||
|
||
@Override | ||
public String getName() { | ||
return "algolia-go"; | ||
} | ||
|
||
@Override | ||
public void processOpts() { | ||
String client = (String) additionalProperties.get("client"); | ||
additionalProperties.put("enumClassPrefix", true); | ||
|
||
String outputFolder = "algolia" + File.separator + client; | ||
setOutputDir(getOutputDir() + File.separator + outputFolder); | ||
|
||
super.processOpts(); | ||
|
||
// Generation notice, added on every generated files | ||
Utils.setGenerationBanner(additionalProperties); | ||
|
||
apiTestTemplateFiles.clear(); | ||
modelTestTemplateFiles.clear(); | ||
apiDocTemplateFiles.clear(); | ||
modelDocTemplateFiles.clear(); | ||
|
||
supportingFiles.clear(); | ||
supportingFiles.add(new SupportingFile("configuration.mustache", "", "configuration.go")); | ||
supportingFiles.add(new SupportingFile("client.mustache", "", "client.go")); | ||
supportingFiles.add(new SupportingFile("response.mustache", "", "response.go")); | ||
|
||
try { | ||
Utils.generateServer(client, additionalProperties); | ||
|
||
additionalProperties.put("packageVersion", Utils.getClientConfigField("go", "packageVersion")); | ||
} catch (GeneratorException e) { | ||
e.printStackTrace(); | ||
System.exit(1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
generators/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module playground | ||
|
||
go 1.19 | ||
|
||
replace github.com/algolia/algoliasearch-client-go/v4 v4.0.0 => ../../clients/algoliasearch-client-go | ||
|
||
require ( | ||
github.com/algolia/algoliasearch-client-go/v4 v4.0.0 | ||
github.com/joho/godotenv v1.4.0 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= | ||
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/algolia/algoliasearch-client-go/v4/algolia/ingestion" | ||
"github.com/joho/godotenv" | ||
"os" | ||
) | ||
|
||
func main() { | ||
fmt.Println("Go playground") | ||
godotenv.Load("../.env") | ||
appID := os.Getenv("ALGOLIA_APPLICATION_ID") | ||
apiKey := os.Getenv("ALGOLIA_ADMIN_KEY") | ||
client := ingestion.NewClient(appID, apiKey, ingestion.US) | ||
|
||
auths, err := client.GetAuthentications() | ||
fmt.Println(auths, err) | ||
|
||
/* | ||
auth, err := client.CreateAuthentication(ingestion.NewAuthenticationCreate( | ||
ingestion.AUTHENTICATIONTYPE_ALGOLIA, | ||
"test-auth-2", | ||
ingestion.AuthAlgoliaAsAuthInput(ingestion.NewAuthAlgolia(appID, apiKey)))) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
fmt.Println(auth)*/ | ||
/* | ||
dest, err := client.CreateDestination(ingestion.NewDestinationCreate( | ||
ingestion.DESTINATIONTYPE_SEARCH, | ||
"test-dest", | ||
ingestion.DestinationIndexPrefixAsDestinationInput(ingestion.NewDestinationIndexPrefix("commercetools_")), | ||
auth.AuthenticationID)) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
fmt.Println(dest)*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.