@@ -142,13 +142,16 @@ public static void setOptionalParameters(
142
142
) {
143
143
int bodyPropsOptional = 0 ;
144
144
boolean actuallyHasOptional = false ;
145
+ boolean isBodyTooBig = false ;
146
+ boolean alreadyInlinedBody = ope .allParams .size () == 1 && ope .bodyParam != null && ope .bodyParam .isModel ;
145
147
146
148
if (AlgoliaGoGenerator .canFlattenBody (ope )) {
147
149
bodyPropsOptional = (int ) ope .bodyParam .getVars ().stream ().filter (prop -> !prop .required ).count ();
150
+ isBodyTooBig = ope .bodyParam .getVars ().size () == 0 ;
148
151
149
152
// edge case where the body is already flattened
150
153
Map <String , Object > paramBody = paramBody = parameters ;
151
- if (ope . allParams . size () > 1 ) {
154
+ if (! alreadyInlinedBody ) {
152
155
paramBody = (Map <String , Object >) parameters .get (ope .bodyParam .paramName );
153
156
}
154
157
@@ -168,29 +171,21 @@ public static void setOptionalParameters(
168
171
}
169
172
}
170
173
174
+ boolean isBodyRequired = (ope .bodyParam != null && ope .bodyParam .required );
175
+
171
176
// I can't figure out the correct condition for this one so it's harcoded for now
172
177
boolean isSFFV = ope .operationId .equals ("searchForFacetValues" ) && "composition" .equals (ope .tags .get (0 ).getName ());
173
178
174
179
// hasOptionalWrapper if there is more that one optional param, after the body has been
175
180
// flattened, only relevant for go
176
181
test .put ("hasOptionalWrapper" , totalOptional > 1 && actuallyHasOptional && !isSFFV );
177
- test .put ("hasInlineOptional" , (totalOptional == 1 || isSFFV ) && actuallyHasOptional );
178
- test .put ("hasNilOptional" , totalOptional > 0 && !actuallyHasOptional && !isHelper );
179
-
180
- System .out .println (
181
- ope .operationId +
182
- " hasOptionalWrapper: " +
183
- test .get ("hasOptionalWrapper" ) +
184
- " hasNilOptional: " +
185
- test .get ("hasNilOptional" ) +
186
- " hasInlineOptional: " +
187
- test .get ("hasInlineOptional" ) +
188
- " totalOptional: " +
189
- totalOptional +
190
- " actuallyHasOptional: " +
191
- actuallyHasOptional +
192
- " bodyPropsOptional: " +
193
- bodyPropsOptional
194
- );
182
+ test .put ("hasInlineOptional" , ((totalOptional == 1 || isSFFV ) && actuallyHasOptional ) || isBodyTooBig );
183
+ if (isBodyTooBig ) {
184
+ boolean isBodySet = alreadyInlinedBody ? parameters .size () > 0 : parameters .containsKey (ope .bodyParam .paramName );
185
+ System .out .println ("isBodySet: " + isBodySet );
186
+ test .put ("hasNilOptional" , isBodyRequired ? totalOptional > 0 && !actuallyHasOptional : !isBodySet );
187
+ } else {
188
+ test .put ("hasNilOptional" , totalOptional > 0 && !actuallyHasOptional && !isHelper );
189
+ }
195
190
}
196
191
}
0 commit comments