Skip to content

Commit

Permalink
fix(swift): QuerySuggestionsConfigurationResponse appID casing (#2712)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Millot <pierre.millot@algolia.com>
  • Loading branch information
Fluf22 and millotp authored Feb 16, 2024
1 parent a6aed39 commit 8c340a4
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public void processOpts() {
);

reservedWords.add("LogLevel");
nameMapping.put("appId", "appID");

setProjectName(getClientName(CLIENT));
setUseSPMFileStructure(true);
Expand Down
7 changes: 5 additions & 2 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"

export apic() {
apic() {
(cd scripts && NODE_NO_WARNINGS=1 node dist/scripts/cli/index.js $*)
}

export apicb() {
apicb() {
(cd scripts && yarn build:cli && NODE_NO_WARNINGS=1 node dist/scripts/cli/index.js $*)
}

export apic
export apicb

_list_languages() {
cat $ROOT/config/clients.config.json | jq -r 'keys[]'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ baseQuerySuggestionsConfigurationResponse:
type: object
additionalProperties: false
properties:
appId:
type: string
description: Your Algolia application ID.
sourceIndicesAPIKey:
type: string
description: API key used to read from your source index.
Expand All @@ -20,4 +17,4 @@ baseQuerySuggestionsConfigurationResponse:
externalIndicesAPIKey:
type: string
default: ''
description: API key used to read from external Algolia indices.
description: API key used to read from external Algolia indices.
42 changes: 16 additions & 26 deletions templates/php/tests/requests/requests.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ use Psr\Http\Message\RequestInterface;
use Dotenv\Dotenv;

// we only read .env file if we run locally
if (isset($_ENV['DOCKER']) && $_ENV['DOCKER'] === "true") {
if (getenv('ALGOLIA_APPLICATION_ID')) {
$_ENV = getenv();
} else {
$dotenv = Dotenv::createImmutable('tests');
$dotenv->load();
} else {
$_ENV = getenv();
}
{{/hasE2E}}

Expand All @@ -39,27 +39,17 @@ class {{clientPrefix}}Test extends TestCase implements HttpClientInterface
{{#hasE2E}}
protected function union($expected, $received)
{
$res = [];
foreach ($expected as $k => $v) {
if (isset($received[$k])) {
if (is_array($v)) {
$res[$k] = $this->union($v, $received[$k]);
} elseif (is_array($v)) {
if (!isset($res[$k])) {
$res[$k] = [];
}

foreach ($v as $iv => $v) {
$res[$k][] = $this->union($v, $received[$k][$iv]);
}
} else {
$res[$k] = $received[$k];
}
if (is_array($expected)) {
$res = [];
// array and object are the same thing in PHP (magic ✨)
foreach ($expected as $k => $v) {
$res[$k] = $this->union($v, $received[$k]);
}
}

return $res;
return $res;
}

return $received;
}
{{/hasE2E}}

Expand Down Expand Up @@ -114,14 +104,14 @@ class {{clientPrefix}}Test extends TestCase implements HttpClientInterface
{{#hasE2E}}
protected function getE2EClient()
{
return {{client}}::create($_ENV['ALGOLIA_APPLICATION_ID'], $_ENV['ALGOLIA_ADMIN_KEY']);
return {{client}}::create($_ENV['ALGOLIA_APPLICATION_ID'], $_ENV['ALGOLIA_ADMIN_KEY']{{#hasRegionalHost}},'{{defaultRegion}}' {{/hasRegionalHost}});
}
{{/hasE2E}}

protected function getClient()
{
$api = new ApiWrapper($this, {{clientPrefix}}Config::create(getenv('ALGOLIA_APP_ID'), getenv('ALGOLIA_API_KEY'){{#hasRegionalHost}},'{{defaultRegion}}' {{/hasRegionalHost}}), ClusterHosts::create('127.0.0.1'));
$config = {{clientPrefix}}Config::create('foo', 'bar'{{#hasRegionalHost}},'{{defaultRegion}}' {{/hasRegionalHost}});
$config = {{clientPrefix}}Config::create('appID', 'apiKey'{{#hasRegionalHost}},'{{defaultRegion}}' {{/hasRegionalHost}});
$api = new ApiWrapper($this, $config, ClusterHosts::create('127.0.0.1'));

return new {{client}}($api, $config);
}
Expand Down Expand Up @@ -193,4 +183,4 @@ class {{clientPrefix}}Test extends TestCase implements HttpClientInterface
}
{{/tests}}
{{/blocksRequests}}
}
}
36 changes: 34 additions & 2 deletions tests/CTS/requests/query-suggestions/getConfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
[
{
"testName": "Retrieve QS config e2e",
"parameters": {
"indexName": "theIndexName"
"indexName": "cts_e2e_browse_query_suggestions"
},
"request": {
"path": "/1/configs/theIndexName",
"path": "/1/configs/cts_e2e_browse_query_suggestions",
"method": "GET"
},
"response": {
"statusCode": 200,
"body": {
"allowSpecialCharacters": true,
"enablePersonalization": false,
"exclude": [
"^cocaines$"
],
"indexName": "cts_e2e_browse_query_suggestions",
"languages": [],
"sourceIndices": [
{
"facets": [
{
"amount": 1,
"attribute": "title"
}
],
"generate": [
[
"year"
]
],
"indexName": "cts_e2e_browse",
"minHits": 5,
"minLetters": 4,
"replicas": false
}
]
}
}
}
]
43 changes: 17 additions & 26 deletions tests/output/javascript/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,25 @@
export function union(
expected: Record<string, any>,
received: Record<string, any>
): Record<string, any> {
const res = {};

if (!expected) {
return expected;
}
export function union(expected: any, received: any): any {
if (Array.isArray(expected)) {
if (Array.isArray(received)) {
const res = new Array(expected.length);
for (const [i, v] of expected.entries()) {
res[i] = union(v, received[i]);
}

if (typeof expected !== 'object' && !Array.isArray(expected)) {
return expected;
return res;
}
return received;
}

for (const [key, value] of Object.entries(expected)) {
if (key in received) {
if (Array.isArray(value)) {
if (res[key] === undefined) {
res[key] = [];
}

for (const [i, v] of value.entries()) {
res[key].push(union(v, received[key][i]));
}
} else if (typeof value === 'object') {
if (typeof expected === 'object' && expected !== null) {
const res = {};
for (const [key, value] of Object.entries(expected)) {
if (key in received) {
res[key] = union(value, received[key]);
} else {
res[key] = received[key];
}
}

return res;
}

return res;
return received;
}
34 changes: 13 additions & 21 deletions tests/output/python/tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
class Helpers:
def union(self, expected: dict, received: dict) -> dict:
def union(self, expected, received):
"""
creates a new dict based on the keys of 'expected' that are also in 'received'
creates a new result based on the keys of 'expected' that are also in 'received'
"""
_res = {}

if not isinstance(expected, dict) or not isinstance(received, dict):
return received

for k, v in expected.items():
if k in received:
if isinstance(v, dict):
_res[k] = self.union(v, received[k])
elif isinstance(v, list):
if _res.get(k) is None:
_res[k] = []

for _iv, _v in enumerate(v):
_res[k].append(self.union(_v, received[k][_iv]))
else:
_res[k] = received[k]

return _res
if isinstance(expected, list):
_res = []
for _iv, _v in enumerate(expected):
_res.append(self.union(_v, received[_iv]))
return _res
if isinstance(expected, dict):
_res = {}
for k, v in expected.items():
_res[k] = self.union(v, received[k])
return _res
return received
39 changes: 15 additions & 24 deletions tests/output/ruby/test/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
def union(expected, received)
res = {}

if !expected.is_a?(Array) and !expected.is_a?(Hash)
return expected
end

if received.nil?
return nil
end

expected.each do |key, value|
if received.key?(key)
if value.is_a?(Array)
res[key] = [] if res[key].nil?
case expected
when Array
res = []
expected.each_with_index do |v, i|
res.push(union(v, received[i]))
end

value.each_with_index do |v, i|
res[key].push(union(v, received[key][i]))
end
elsif value.is_a?(Hash)
res[key] = union(value, received[key])
else
res[key] = received[key]
end
return res
when Hash
res = {}
expected.each do |key, value|
res[key] = union(value, received[key])
end
end

res
return res
else
return received
end
end
Loading

0 comments on commit 8c340a4

Please # to comment.