Skip to content

fix(javascript): revert: do not send user-agent for Predict (#919) #957

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

Merged
merged 2 commits into from
Aug 25, 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 @@ -110,15 +110,12 @@ export function createTransporter({
: {};

const queryParameters: QueryParameters = {
'x-algolia-agent': algoliaAgent.value,
...baseQueryParameters,
...request.queryParameters,
...dataQueryParameters,
};

if (algoliaAgent.value) {
queryParameters['x-algolia-agent'] = algoliaAgent.value;
}

if (requestOptions && requestOptions.queryParameters) {
for (const key of Object.keys(requestOptions.queryParameters)) {
// We want to keep `undefined` and `null` values,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ private void setDefaultGeneratorOptions() {
additionalProperties.put("isSearchClient", CLIENT.equals("search"));
additionalProperties.put("isAlgoliasearchClient", isAlgoliasearchClient);

// PRED-523 - tmp addition until the predict client supports user-agent in their API
additionalProperties.put("isPredictClient", CLIENT.equals("predict"));

if (isAlgoliasearchClient) {
// Files used to create the package.json of the algoliasearch package
additionalProperties.put("analyticsVersion", Utils.getOpenApiToolsField("javascript", "analytics", "packageVersion"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public TestsClient(String language, String client) {

@Override
public boolean available() {
// no `algoliasearch` client tests for now, only `lite`.
// no `lite` client test for now
if (language.equals("javascript") && client.equals("algoliasearch")) {
return false;
}
Expand All @@ -28,15 +28,6 @@ public boolean available() {
return templates.exists();
}

public boolean isTestAvailable(String testName) {
// PRED-523 - tmp addition until the predict client supports user-agent in their API
if (client.equals("predict") && testName.equals("calls api with correct user agent")) {
return false;
}

return true;
}

@Override
public void addSupportingFiles(List<SupportingFile> supportingFiles, String outputFolder, String extension) {
if (!available()) {
Expand All @@ -59,11 +50,6 @@ public void run(Map<String, CodegenModel> models, Map<String, CodegenOperation>
for (ClientTestData test : blockEntry.getValue()) {
Map<String, Object> testOut = new HashMap<>();
List<Object> steps = new ArrayList<>();

if (!isTestAvailable(test.testName)) {
continue;
}

testOut.put("testName", test.testName);
testOut.put("testIndex", testIndex++);
testOut.put("autoCreateClient", test.autoCreateClient);
Expand Down
13 changes: 5 additions & 8 deletions templates/javascript/clients/api-single.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ export function create{{capitalizedApiName}}({
const transporter = createTransporter({
hosts: getDefaultHosts({{^hasRegionalHost}}appIdOption{{/hasRegionalHost}}{{#hasRegionalHost}}regionOption{{/hasRegionalHost}}),
...options,
{{! // PRED-523 - tmp addition until the predict client supports user-agent in their API }}
algoliaAgent:
{{#isPredictClient}}
{...getAlgoliaAgent({ algoliaAgents, client: '{{{algoliaAgent}}}', version: apiClientVersion }), value: '' },
{{/isPredictClient}}
{{^isPredictClient}}
getAlgoliaAgent({ algoliaAgents, client: '{{{algoliaAgent}}}', version: apiClientVersion }),
{{/isPredictClient}}
algoliaAgent: getAlgoliaAgent({
algoliaAgents,
client: '{{{algoliaAgent}}}',
version: apiClientVersion,
}),
baseHeaders: {
'content-type': 'text/plain',
...auth.headers(),
Expand Down