Skip to content

Commit b28ecf5

Browse files
committed
suppost verbatim
1 parent 442ebf0 commit b28ecf5

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

generators/src/main/java/com/algolia/codegen/cts/tests/TestsGenerator.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ public static void setOptionalParameters(
143143
int bodyPropsOptional = 0;
144144
boolean actuallyHasOptional = false;
145145
boolean isBodyTooBig = false;
146-
boolean alreadyInlinedBody = ope.allParams.size() == 1 && ope.bodyParam != null && ope.bodyParam.isModel;
146+
boolean isBodyRequired = (ope.bodyParam != null && ope.bodyParam.required);
147+
boolean alreadyInlinedBody = ope.allParams.size() == 1 && ope.bodyParam != null && !ope.bodyParam.isArray;
147148

148149
if (AlgoliaGoGenerator.canFlattenBody(ope)) {
149150
bodyPropsOptional = (int) ope.bodyParam.getVars().stream().filter(prop -> !prop.required).count();
@@ -152,7 +153,14 @@ public static void setOptionalParameters(
152153
// edge case where the body is already flattened
153154
Map<String, Object> paramBody = paramBody = parameters;
154155
if (!alreadyInlinedBody) {
155-
paramBody = (Map<String, Object>) parameters.get(ope.bodyParam.paramName);
156+
Object paramBodyObj = parameters.get(ope.bodyParam.paramName);
157+
if (paramBodyObj instanceof String) {
158+
// this is a verbatim paramater, we use it as is
159+
System.out.println(ope.operationId + " is a verbatim body " + paramBodyObj);
160+
actuallyHasOptional = !isBodyRequired;
161+
} else {
162+
paramBody = (Map<String, Object>) parameters.get(ope.bodyParam.paramName);
163+
}
156164
}
157165

158166
for (CodegenProperty prop : ope.bodyParam.getVars()) {
@@ -171,8 +179,6 @@ public static void setOptionalParameters(
171179
}
172180
}
173181

174-
boolean isBodyRequired = (ope.bodyParam != null && ope.bodyParam.required);
175-
176182
// I can't figure out the correct condition for this one so it's harcoded for now
177183
boolean isSFFV = ope.operationId.equals("searchForFacetValues") && "composition".equals(ope.tags.get(0).getName());
178184

@@ -182,7 +188,7 @@ public static void setOptionalParameters(
182188
test.put("hasInlineOptional", ((totalOptional == 1 || isSFFV) && actuallyHasOptional) || isBodyTooBig);
183189
if (isBodyTooBig) {
184190
boolean isBodySet = alreadyInlinedBody ? parameters.size() > 0 : parameters.containsKey(ope.bodyParam.paramName);
185-
System.out.println("isBodySet: " + isBodySet);
191+
System.out.println(ope.operationId + " isBodySet: " + isBodySet + " isBodyRequired: " + isBodyRequired);
186192
test.put("hasNilOptional", isBodyRequired ? totalOptional > 0 && !actuallyHasOptional : !isBodySet);
187193
} else {
188194
test.put("hasNilOptional", totalOptional > 0 && !actuallyHasOptional && !isHelper);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{#hasInlineOptional}}{{#parametersWithDataType}}{{^required}}{{^isFreeFormObject}}{{^isObject}}utils.ToPtr({{/isObject}}{{/isFreeFormObject}}{{> tests/generateParams}}{{^isFreeFormObject}}{{^isObject}}){{/isObject}}{{/isFreeFormObject}},{{/required}}{{/parametersWithDataType}}{{/hasInlineOptional}}
1+
{{#hasInlineOptional}}{{#parametersWithDataType}}{{^required}}{{^isFreeFormObject}}{{^isObject}}{{^isVerbatim}}utils.ToPtr({{/isVerbatim}}{{/isObject}}{{/isFreeFormObject}}{{> tests/generateParams}}{{^isFreeFormObject}}{{^isObject}}{{^isVerbatim}}){{/isVerbatim}}{{/isObject}}{{/isFreeFormObject}},{{/required}}{{/parametersWithDataType}}{{/hasInlineOptional}}

templates/go/tests/method.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
client.{{#lambda.titlecase}}{{method}}{{/lambda.titlecase}}({{> tests/requiredParams}}{{> tests/optionalWrapper}}{{> tests/nilWrapper}}{{> tests/inlineOptional}}{{> tests/requestOptions}})
1+
client.{{#lambda.titlecase}}{{method}}{{/lambda.titlecase}}({{> tests/requiredParams}}{{> tests/optionalWrapper}}{{> tests/nilWrapper}}{{> tests/inlineOptional}}{{> tests/requestOptions}})

templates/go/tests/requests/requests.mustache

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ func Test{{#lambda.titlecase}}{{clientPrefix}}{{/lambda.titlecase}}_{{#lambda.ti
4343

4444
{{#tests}}
4545
t.Run("{{{testName}}}", func(t *testing.T) {
46-
// hasOptionalWrapper {{hasOptionalWrapper}}
47-
// hasInlineOptional {{hasInlineOptional}}
48-
// hasNilOptional {{hasNilOptional}}
4946
{{#hasResponse}}_, {{/hasResponse}}err := {{> tests/method}}
5047
require.NoError(t, err)
5148

0 commit comments

Comments
 (0)