Skip to content
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

feat(specs): update predict client API URL #1010

Merged
merged 8 commits into from
Sep 12, 2022
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
Expand Up @@ -88,9 +88,16 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> obj

Object lambda = objs.get("lambda");
List<CodegenServer> servers = (List<CodegenServer>) objs.get("servers");
boolean hasRegionalHost = servers
.stream()
.anyMatch(server -> server.variables.stream().anyMatch(variable -> variable.name.equals("region")));
CodegenServerVariable regionVariable = null;
outerLoop:for (CodegenServer server : servers) {
for (CodegenServerVariable var : server.variables) {
if (var.name.equals("region")) {
regionVariable = var;
break outerLoop;
}
}
}
boolean hasRegionalHost = regionVariable != null;

Map<String, Object> bundle = objs;
bundle.clear();
Expand All @@ -106,7 +113,9 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> obj
bundle.put("client", Utils.createClientName(importClientName, language) + "Client");
bundle.put("clientPrefix", Utils.createClientName(importClientName, language));
bundle.put("hasRegionalHost", hasRegionalHost);
bundle.put("defaultRegion", client.equals("predict") ? "ew" : "us");
if (hasRegionalHost) {
bundle.put("defaultRegion", regionVariable.defaultValue);
}
bundle.put("lambda", lambda);

ctsManager.addDataToBundle(bundle);
Expand Down
2 changes: 1 addition & 1 deletion playground/javascript/node/predict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const apiKey =
const userId = process.env.ALGOLIA_PREDICT_USER_ID || 'user1';

// Init client with appId and apiKey
const client = predictClient(appId, apiKey, 'ew');
const client = predictClient(appId, apiKey, 'eu');

async function testPredict() {
try {
Expand Down
12 changes: 6 additions & 6 deletions specs/predict/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ components:
apiKey:
$ref: '../common/securitySchemes.yml#/apiKey'
servers:
- url: https://predict-api-432xa6wemq-{region}.a.run.app
- url: https://predict.{region}.algolia.com
variables:
region:
enum:
- ue
- ew
default: ew
- eu
- us
default: eu
description: >
Region where your Predict data is stored and processed:
* `ew` - europe-west
* `ue` - us-east.
* `eu` - Europe
* `us` - United States.
security:
- appId: []
apiKey: []
Expand Down
6 changes: 3 additions & 3 deletions tests/CTS/client/predict/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"region": ""
},
"expected": {
"error": "`region` is required and must be one of the following: ue, ew"
"error": "`region` is required and must be one of the following: eu, us"
}
}
]
Expand All @@ -28,7 +28,7 @@
"region": "not_a_region"
},
"expected": {
"error": "`region` is required and must be one of the following: ue, ew"
"error": "`region` is required and must be one of the following: eu, us"
}
}
]
Expand All @@ -42,7 +42,7 @@
"parameters": {
"appId": "my-app-id",
"apiKey": "my-api-key",
"region": "ew"
"region": "eu"
},
"expected": {}
}
Expand Down