Skip to content

fix(cts): remove default query parameters APIC-428 #377

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 17 commits into from
Apr 28, 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 @@ -159,6 +159,7 @@ public Map<String, Object> postProcessSupportingFileData(
List<Object> tests = new ArrayList<>();
for (int i = 0; i < op.length; i++) {
Map<String, Object> test = paramsType.buildJSONForRequest(
operationId,
op[i],
entry.getValue(),
i
Expand All @@ -174,12 +175,10 @@ public Map<String, Object> postProcessSupportingFileData(

return bundle;
} catch (CTSException e) {
System.out.println(e.getMessage());
if (e.isSkipable()) {
System.out.println(e.getMessage());
System.exit(0);
}

System.out.println(e.getMessage());
System.exit(1);
} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ public ParametersWithDataType(
}

public Map<String, Object> buildJSONForRequest(
String operationId,
Request req,
CodegenOperation ope,
int testIndex
) throws CTSException, JsonMappingException, JsonProcessingException {
Map<String, Object> test = new HashMap<>();
test.put("method", req.method);
test.put("testName", req.testName == null ? req.method : req.testName);
test.put("method", operationId);
test.put("testName", req.testName == null ? operationId : req.testName);
test.put("testIndex", testIndex);
test.put("request", req.request);

Expand Down Expand Up @@ -252,7 +253,7 @@ private void handleModel(
HashMap<String, String> oneOfModel = new HashMap<>();
String typeName = getTypeName(match).replace("<", "").replace(">", "");

oneOfModel.put("classname", Utils.capitalize(baseType));
oneOfModel.put("parentClassName", Utils.capitalize(baseType));

if (typeName.equals("List")) {
CodegenProperty items = match.getItems();
Expand All @@ -264,7 +265,7 @@ private void handleModel(
typeName += getTypeName(items);
}

oneOfModel.put("name", typeName);
oneOfModel.put("type", typeName);
testOutput.put("oneOfModel", oneOfModel);

return;
Expand Down
11 changes: 4 additions & 7 deletions generators/src/main/java/com/algolia/codegen/cts/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@
public class Request {

public String testName;
public String method;

public Map<String, Object> parameters;

public RequestProp request;

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Request {\n");
sb.append(" testName: ").append(testName).append("\n");
sb.append(" method: ").append(method).append("\n");
sb.append(" parameters: ").append(parameters).append("\n");
sb.append(" request: ").append(request).append("\n");
sb.append("}");
Expand All @@ -37,19 +34,19 @@ class RequestProp {
public String method;

@JsonDeserialize(using = RawDeserializer.class)
public String data;
public String body;

@JsonDeserialize(using = RawDeserializer.class)
public String searchParams;
public String queryParameters;

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class RequestProp {\n");
sb.append(" path: ").append(path).append("\n");
sb.append(" method: ").append(method).append("\n");
sb.append(" data: ").append(data).append("\n");
sb.append(" searchParams: ").append(searchParams).append("\n");
sb.append(" body: ").append(body).append("\n");
sb.append(" queryParameters: ").append(queryParameters).append("\n");
sb.append("}");
return sb.toString();
}
Expand Down
62 changes: 31 additions & 31 deletions templates/java/libraries/okhttp-gson/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -194,36 +194,36 @@ public class {{classname}} extends ApiClient {
return res.getData();{{/returnType}}{{^returnType}}this.execute(call).getData();{{/returnType}}
}

{{#optionalParams.0}}
public {{#returnType}}{{{.}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#requiredParams}}{{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/requiredParams}}) throws AlgoliaRuntimeException {
{{#returnType}}return {{/returnType}}this.{{operationId}}({{#requiredParams}}{{paramName}}{{^-last}},{{/-last}}{{/requiredParams}}{{#requiredParams.0}},{{/requiredParams.0}}{{#optionalParams}}{{#schema}}{{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/schema}}{{^schema}}null{{/schema}}{{^-last}},{{/-last}}{{/optionalParams}});
}
{{/optionalParams.0}}

/**
* (asynchronously)
* {{notes}}{{#allParams}}
* @param {{paramName}} {{{description}}}{{#required}} (required){{/required}}{{^required}} (optional{{^isContainer}}{{#defaultValue}}, default to {{.}}{{/defaultValue}}{{/isContainer}}){{/required}}{{/allParams}}
* @param callback The callback to be executed when the API call finishes
* @return The request call
* @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request body object
{{#isDeprecated}}
* @deprecated
{{/isDeprecated}}
{{#externalDocs}}
* {{&description}}
* @see <a href="{{url}}">{{&summary}} Documentation</a>
{{/externalDocs}}
*/
{{#isDeprecated}}
@Deprecated
{{/isDeprecated}}
public Call {{operationId}}Async({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ApiCallback<{{{returnType}}}{{^returnType}}Void{{/returnType}}> callback) throws AlgoliaRuntimeException {
Call call = {{operationId}}ValidateBeforeCall({{#allParams}}{{paramName}}, {{/allParams}}callback);
{{#returnType}}Type returnType = new TypeToken<{{{returnType}}}>(){}.getType();
this.executeAsync(call, returnType, callback);{{/returnType}}{{^returnType}}this.executeAsync(call, callback);{{/returnType}}
return call;
}
{{/operation}}
{{#optionalParams.0}}
public {{#returnType}}{{{.}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#requiredParams}}{{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/requiredParams}}) throws AlgoliaRuntimeException {
{{#returnType}}return {{/returnType}}this.{{operationId}}({{#requiredParams}}{{paramName}}{{^-last}},{{/-last}}{{/requiredParams}}{{#requiredParams.0}},{{/requiredParams.0}}{{#optionalParams}}null{{^-last}},{{/-last}}{{/optionalParams}});
}
{{/optionalParams.0}}

/**
* (asynchronously)
* {{notes}}{{#allParams}}
* @param {{paramName}} {{{description}}}{{#required}} (required){{/required}}{{^required}} (optional{{^isContainer}}{{#defaultValue}}, default to {{.}}{{/defaultValue}}{{/isContainer}}){{/required}}{{/allParams}}
* @param callback The callback to be executed when the API call finishes
* @return The request call
* @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request body object
{{#isDeprecated}}
* @deprecated
{{/isDeprecated}}
{{#externalDocs}}
* {{&description}}
* @see <a href="{{url}}">{{&summary}} Documentation</a>
{{/externalDocs}}
*/
{{#isDeprecated}}
@Deprecated
{{/isDeprecated}}
public Call {{operationId}}Async({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ApiCallback<{{{returnType}}}{{^returnType}}Void{{/returnType}}> callback) throws AlgoliaRuntimeException {
Call call = {{operationId}}ValidateBeforeCall({{#allParams}}{{paramName}}, {{/allParams}}callback);
{{#returnType}}Type returnType = new TypeToken<{{{returnType}}}>(){}.getType();
this.executeAsync(call, returnType, callback);{{/returnType}}{{^returnType}}this.executeAsync(call, callback);{{/returnType}}
return call;
}
{{/operation}}
}
{{/operations}}
3 changes: 1 addition & 2 deletions tests/CTS/methods/requests/abtesting/addABTests.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[
{
"method": "addABTests",
"testName": "addABTests with minimal parameters",
"parameters": {
"endAt": "2022-12-31T00:00:00.000Z",
Expand All @@ -19,7 +18,7 @@
"request": {
"path": "/2/abtests",
"method": "POST",
"data": {
"body": {
"endAt": "2022-12-31T00:00:00.000Z",
"name": "myABTest",
"variant": [
Expand Down
1 change: 0 additions & 1 deletion tests/CTS/methods/requests/abtesting/deleteABTest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[
{
"method": "deleteABTest",
"testName": "deleteABTest",
"parameters": {
"id": 42
Expand Down
1 change: 0 additions & 1 deletion tests/CTS/methods/requests/abtesting/getABTest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[
{
"method": "getABTest",
"testName": "getABTest",
"parameters": {
"id": 42
Expand Down
3 changes: 1 addition & 2 deletions tests/CTS/methods/requests/abtesting/listABTests.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[
{
"method": "listABTests",
"testName": "listABTests with minimal parameters",
"parameters": {
"offset": 42,
Expand All @@ -9,7 +8,7 @@
"request": {
"path": "/2/abtests",
"method": "GET",
"searchParams": {
"queryParameters": {
"offset": "42",
"limit": "21"
}
Expand Down
1 change: 0 additions & 1 deletion tests/CTS/methods/requests/abtesting/stopABTest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[
{
"method": "stopABTest",
"testName": "stopABTest",
"parameters": {
"id": 42
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
[
{
"method": "getAverageClickPosition",
"testName": "get getAverageClickPosition with minimal parameters",
"parameters": {
"index": "index"
},
"request": {
"path": "/2/clicks/averageClickPosition",
"method": "GET",
"searchParams": {
"queryParameters": {
"index": "index"
}
}
},
{
"method": "getAverageClickPosition",
"testName": "get getAverageClickPosition with all parameters",
"parameters": {
"index": "index",
Expand All @@ -25,7 +23,7 @@
"request": {
"path": "/2/clicks/averageClickPosition",
"method": "GET",
"searchParams": {
"queryParameters": {
"index": "index",
"startDate": "1999-09-19",
"endDate": "2001-01-01",
Expand Down
6 changes: 2 additions & 4 deletions tests/CTS/methods/requests/analytics/getClickPositions.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
[
{
"method": "getClickPositions",
"testName": "get getClickPositions with minimal parameters",
"parameters": {
"index": "index"
},
"request": {
"path": "/2/clicks/positions",
"method": "GET",
"searchParams": {
"queryParameters": {
"index": "index"
}
}
},
{
"method": "getClickPositions",
"testName": "get getClickPositions with all parameters",
"parameters": {
"index": "index",
Expand All @@ -25,7 +23,7 @@
"request": {
"path": "/2/clicks/positions",
"method": "GET",
"searchParams": {
"queryParameters": {
"index": "index",
"startDate": "1999-09-19",
"endDate": "2001-01-01",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
[
{
"method": "getClickThroughRate",
"testName": "get getClickThroughRate with minimal parameters",
"parameters": {
"index": "index"
},
"request": {
"path": "/2/clicks/clickThroughRate",
"method": "GET",
"searchParams": {
"queryParameters": {
"index": "index"
}
}
},
{
"method": "getClickThroughRate",
"testName": "get getClickThroughRate with all parameters",
"parameters": {
"index": "index",
Expand All @@ -25,7 +23,7 @@
"request": {
"path": "/2/clicks/clickThroughRate",
"method": "GET",
"searchParams": {
"queryParameters": {
"index": "index",
"startDate": "1999-09-19",
"endDate": "2001-01-01",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
[
{
"method": "getConversationRate",
"testName": "get getConversationRate with minimal parameters",
"parameters": {
"index": "index"
},
"request": {
"path": "/2/conversions/conversionRate",
"method": "GET",
"searchParams": {
"queryParameters": {
"index": "index"
}
}
},
{
"method": "getConversationRate",
"testName": "get getConversationRate with all parameters",
"parameters": {
"index": "index",
Expand All @@ -25,7 +23,7 @@
"request": {
"path": "/2/conversions/conversionRate",
"method": "GET",
"searchParams": {
"queryParameters": {
"index": "index",
"startDate": "1999-09-19",
"endDate": "2001-01-01",
Expand Down
6 changes: 2 additions & 4 deletions tests/CTS/methods/requests/analytics/getNoClickRate.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
[
{
"method": "getNoClickRate",
"testName": "get getNoClickRate with minimal parameters",
"parameters": {
"index": "index"
},
"request": {
"path": "/2/searches/noClickRate",
"method": "GET",
"searchParams": {
"queryParameters": {
"index": "index"
}
}
},
{
"method": "getNoClickRate",
"testName": "get getNoClickRate with all parameters",
"parameters": {
"index": "index",
Expand All @@ -25,7 +23,7 @@
"request": {
"path": "/2/searches/noClickRate",
"method": "GET",
"searchParams": {
"queryParameters": {
"index": "index",
"startDate": "1999-09-19",
"endDate": "2001-01-01",
Expand Down
Loading