Skip to content

Commit 0e6c811

Browse files
committed
suppost verbatim
1 parent 7c3282d commit 0e6c811

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
@@ -147,7 +147,8 @@ public static void setOptionalParameters(
147147
int bodyPropsOptional = 0;
148148
boolean actuallyHasOptional = false;
149149
boolean isBodyTooBig = false;
150-
boolean alreadyInlinedBody = ope.allParams.size() == 1 && ope.bodyParam != null && ope.bodyParam.isModel;
150+
boolean isBodyRequired = (ope.bodyParam != null && ope.bodyParam.required);
151+
boolean alreadyInlinedBody = ope.allParams.size() == 1 && ope.bodyParam != null && !ope.bodyParam.isArray;
151152

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

162170
for (CodegenProperty prop : ope.bodyParam.getVars()) {
@@ -175,8 +183,6 @@ public static void setOptionalParameters(
175183
}
176184
}
177185

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

@@ -186,7 +192,7 @@ public static void setOptionalParameters(
186192
test.put("hasInlineOptional", ((totalOptional == 1 || isSFFV) && actuallyHasOptional) || isBodyTooBig);
187193
if (isBodyTooBig) {
188194
boolean isBodySet = alreadyInlinedBody ? parameters.size() > 0 : parameters.containsKey(ope.bodyParam.paramName);
189-
System.out.println("isBodySet: " + isBodySet);
195+
System.out.println(ope.operationId + " isBodySet: " + isBodySet + " isBodyRequired: " + isBodyRequired);
190196
test.put("hasNilOptional", isBodyRequired ? totalOptional > 0 && !actuallyHasOptional : !isBodySet);
191197
} else {
192198
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
@@ -40,9 +40,6 @@ func Test{{#lambda.titlecase}}{{clientPrefix}}{{/lambda.titlecase}}_{{#lambda.ti
4040

4141
{{#tests}}
4242
t.Run("{{{testName}}}", func(t *testing.T) {
43-
// hasOptionalWrapper {{hasOptionalWrapper}}
44-
// hasInlineOptional {{hasInlineOptional}}
45-
// hasNilOptional {{hasNilOptional}}
4643
{{#hasResponse}}_, {{/hasResponse}}err := {{> tests/method}}
4744
require.NoError(t, err)
4845

0 commit comments

Comments
 (0)