Repository: algolia/algoliasearch-client-go
Pull request #519 (2019-07-15 12:48:52)

changed(compression): set back default compression to 'None' on POST/PUT requests


Patch:
diff --git a/algolia/search/client.go b/algolia/search/client.go
index bb7cb43c..a2e4db9c 100644
--- a/algolia/search/client.go
+++ b/algolia/search/client.go
@@ -32,7 +32,7 @@ func NewClient(appID, apiKey string) *Client {
 		Configuration{
 			AppID:       appID,
 			APIKey:      apiKey,
-			Compression: compression.GZIP,
+			Compression: compression.None,
 		},
 	)
 }
diff --git a/algolia/search/synonym.go b/algolia/search/synonym.go
index 5be4bebc..48de62b5 100644
--- a/algolia/search/synonym.go
+++ b/algolia/search/synonym.go
@@ -18,6 +18,12 @@ const (
 	AltCorrection1Type SynonymType = "altCorrection1"
 	AltCorrection2Type SynonymType = "altCorrection2"
 	PlaceholderType    SynonymType = "placeholder"
+
+	// Non-exported constant to represent synonym types as exported
+	// by the Algolia dashboard, which lower-cases the type field.
+	oneWaySynonymTypeLower  SynonymType = "onewaysynonym"
+	altCorrection1TypeLower SynonymType = "altcorrection1"
+	altCorrection2TypeLower SynonymType = "altcorrection2"
 )
 
 type rawSynonym struct{ impl Synonym }
@@ -48,17 +54,17 @@ func (s *rawSynonym) UnmarshalJSON(data []byte) error {
 		err = json.Unmarshal(data, &syn)
 		s.impl = syn
 
-	case OneWaySynonymType:
+	case OneWaySynonymType, oneWaySynonymTypeLower:
 		var syn OneWaySynonym
 		err = json.Unmarshal(data, &syn)
 		s.impl = syn
 
-	case AltCorrection1Type:
+	case AltCorrection1Type, altCorrection1TypeLower:
 		var syn AltCorrection1
 		err = json.Unmarshal(data, &syn)
 		s.impl = syn
 
-	case AltCorrection2Type:
+	case AltCorrection2Type, altCorrection2TypeLower:
 		var syn AltCorrection2
 		err = json.Unmarshal(data, &syn)
 		s.impl = syn
diff --git a/algolia/search/synonym_alt_correction_1.go b/algolia/search/synonym_alt_correction_1.go
index e4a5ef0b..a63f42fd 100644
--- a/algolia/search/synonym_alt_correction_1.go
+++ b/algolia/search/synonym_alt_correction_1.go
@@ -40,7 +40,7 @@ func (s *AltCorrection1) UnmarshalJSON(data []byte) error {
 		return fmt.Errorf("cannot unmarshal AltCorrection1: %v", err)
 	}
 
-	if synonym.Type != s.Type() {
+	if synonym.Type != s.Type() && synonym.Type != altCorrection1TypeLower {
 		return fmt.Errorf("cannot deserialize synonym of type %s into AltCorretion1", synonym.Type)
 	}
 
diff --git a/algolia/search/synonym_alt_correction_2.go b/algolia/search/synonym_alt_correction_2.go
index 9c0b590c..fd0fd187 100644
--- a/algolia/search/synonym_alt_correction_2.go
+++ b/algolia/search/synonym_alt_correction_2.go
@@ -29,7 +29,7 @@ func (s *AltCorrection2) UnmarshalJSON(data []byte) error {
 		return fmt.Errorf("cannot unmarshal AltCorrection2: %v", err)
 	}
 
-	if synonym.Type != s.Type() {
+	if synonym.Type != s.Type() && synonym.Type != altCorrection2TypeLower {
 		return fmt.Errorf("cannot deserialize synonym of type %s into AltCorretion2", synonym.Type)
 	}
 
diff --git a/algolia/search/synonym_one_way.go b/algolia/search/synonym_one_way.go
index bc869869..9e1a9439 100644
--- a/algolia/search/synonym_one_way.go
+++ b/algolia/search/synonym_one_way.go
@@ -40,7 +40,7 @@ func (s *OneWaySynonym) UnmarshalJSON(data []byte) error {
 		return fmt.Errorf("cannot unmarshal OneWaySynonym: %v", err)
 	}
 
-	if synonym.Type != s.Type() {
+	if synonym.Type != s.Type() && synonym.Type != oneWaySynonymTypeLower {
 		return fmt.Errorf("cannot deserialize synonym of type %s into OneWaySynonym", synonym.Type)
 	}
 


Test patch:
diff --git a/algolia/search/synonym_test.go b/algolia/search/synonym_test.go
new file mode 100644
index 00000000..daee9f28
--- /dev/null
+++ b/algolia/search/synonym_test.go
@@ -0,0 +1,27 @@
+package search
+
+import (
+	"encoding/json"
+	"testing"
+
+	"github.com/stretchr/testify/require"
+)
+
+func TestSynonymUnmarshalType(t *testing.T) {
+	for _, c := range []struct {
+		payload  string
+	}{
+		{`{"type": "synonym"}`},
+		{`{"type": "oneWaySynonym"}`},
+		{`{"type": "altCorrection1"}`},
+		{`{"type": "altCorrection2"}`},
+		{`{"type": "placeholder"}`},
+		{`{"type": "onewaysynonym"}`},
+		{`{"type": "altcorrection1"}`},
+		{`{"type": "altcorrection2"}`},
+	} {
+		var s rawSynonym
+		err := json.Unmarshal([]byte(c.payload), &s)
+		require.NoError(t, err, "payload=%q", c.payload)
+	}
+}