-
Notifications
You must be signed in to change notification settings - Fork 17
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
fix(generator): add hostWithFallback
#479
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,12 @@ components: | |
apiKey: | ||
$ref: '../common/securitySchemes.yml#/apiKey' | ||
servers: | ||
- url: https://predict-api-432xa6wemq-ew.a.run.app | ||
- url: https://predict-api-432xa6wemq-{region}.a.run.app | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should switch the order of the stack PR so this doesn't appear here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not the same change as in #473, it just fixes the spec because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah ok I didn't know ! Which region is it ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Western Europe I believe? cc @anghelalexandra :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Europe West ? 🤨 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
variables: | ||
region: | ||
enum: | ||
- ew | ||
default: ew | ||
security: | ||
- appId: [] | ||
apiKey: [] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,11 +50,11 @@ public class {{classname}} extends ApiClient { | |
|
||
{{^hasRegionalHost}} | ||
public {{classname}}(String appId, String apiKey) { | ||
this(appId, apiKey, new HttpRequester(getDefaultHosts({{^isExperimentalHost}}appId{{/isExperimentalHost}})), null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is this variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You missed it because you did not generated the Predict client for PHP It was there because the URL was not following the correct schema, but in fact the We now don't use this variable anymore |
||
this(appId, apiKey, new HttpRequester(getDefaultHosts(appId)), null); | ||
} | ||
|
||
public {{classname}}(String appId, String apiKey, UserAgent.Segment[] userAgentSegments) { | ||
this(appId, apiKey, new HttpRequester(getDefaultHosts({{^isExperimentalHost}}appId{{/isExperimentalHost}})), userAgentSegments); | ||
this(appId, apiKey, new HttpRequester(getDefaultHosts(appId)), userAgentSegments); | ||
} | ||
{{/hasRegionalHost}} | ||
|
||
|
@@ -66,7 +66,7 @@ public class {{classname}} extends ApiClient { | |
super(appId, apiKey, requester, "{{{baseName}}}", userAgentSegments); | ||
} | ||
|
||
{{^hasRegionalHost}}{{^isExperimentalHost}} | ||
{{^hasRegionalHost}} | ||
private static List<StatefulHost> getDefaultHosts(String appId) { | ||
List<StatefulHost> hosts = new ArrayList<StatefulHost>(); | ||
hosts.add(new StatefulHost(appId + "-dsn.algolia.net", "https", EnumSet.of(CallType.READ))); | ||
|
@@ -81,20 +81,15 @@ public class {{classname}} extends ApiClient { | |
|
||
return Stream.concat(hosts.stream(), commonHosts.stream()).collect(Collectors.toList()); | ||
} | ||
{{/isExperimentalHost}}{{/hasRegionalHost}} | ||
|
||
{{#isExperimentalHost}} | ||
private static List<StatefulHost> getDefaultHosts() { | ||
List<StatefulHost> hosts = new ArrayList<StatefulHost>(); | ||
hosts.add(new StatefulHost("{{{host}}}", "https", EnumSet.of(CallType.READ, CallType.WRITE))); | ||
return hosts; | ||
} | ||
{{/isExperimentalHost}} | ||
{{/hasRegionalHost}} | ||
|
||
{{#hasRegionalHost}} | ||
private static List<StatefulHost> getDefaultHosts(String region) { | ||
List<StatefulHost> hosts = new ArrayList<StatefulHost>(); | ||
hosts.add(new StatefulHost("{{{host}}}." + {{#fallbackToAliasHost}}(region == null ? "" : region + "."){{/fallbackToAliasHost}}{{^fallbackToAliasHost}}region{{/fallbackToAliasHost}} + "algolia.{{#topLevelDomain}}{{.}}{{/topLevelDomain}}{{^topLevelDomain}}com{{/topLevelDomain}}", "https", EnumSet.of(CallType.READ, CallType.WRITE))); | ||
|
||
String url = {{#fallbackToAliasHost}}region == null ? "{{{hostWithFallback}}}" : {{/fallbackToAliasHost}} "{{{host}}}".replace("{region}", region); | ||
|
||
hosts.add(new StatefulHost(url, "https", EnumSet.of(CallType.READ, CallType.WRITE))); | ||
return hosts; | ||
} | ||
{{/hasRegionalHost}} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,7 +102,8 @@ use {{invokerPackage}}\RetryStrategy\ClusterHosts; | |
// If a list of hosts was passed, we ignore the cache | ||
$clusterHosts = ClusterHosts::create($hosts); | ||
} else { | ||
$clusterHosts = ClusterHosts::create('{{host}}.'.$config->getRegion().'.algolia.{{topLevelDomain}}'); | ||
$url = str_replace('{region}', $config->getRegion(), '{{{host}}}'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does the {{{host}}} variable is supposed to contain now ? Has it changed ? Before it was "analytics", "insights", ... no ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, but it contained a lot of logic like It stores the whole domain now, and we only replace the For There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can see it in action here btw: dd5d4db to make sure the logic is right for PHP There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok I see, looks good then 👍 |
||
$clusterHosts = ClusterHosts::create($url); | ||
} | ||
{{/useCache}} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to push this fix last time