@@ -138,13 +138,16 @@ public static void setOptionalParameters(
138138 ) {
139139 int bodyPropsOptional = 0 ;
140140 boolean actuallyHasOptional = false ;
141+ boolean isBodyTooBig = false ;
142+ boolean alreadyInlinedBody = ope .allParams .size () == 1 && ope .bodyParam != null && ope .bodyParam .isModel ;
141143
142144 if (AlgoliaGoGenerator .canFlattenBody (ope )) {
143145 bodyPropsOptional = (int ) ope .bodyParam .getVars ().stream ().filter (prop -> !prop .required ).count ();
146+ isBodyTooBig = ope .bodyParam .getVars ().size () == 0 ;
144147
145148 // edge case where the body is already flattened
146149 Map <String , Object > paramBody = paramBody = parameters ;
147- if (ope . allParams . size () > 1 ) {
150+ if (! alreadyInlinedBody ) {
148151 paramBody = (Map <String , Object >) parameters .get (ope .bodyParam .paramName );
149152 }
150153
@@ -164,29 +167,21 @@ public static void setOptionalParameters(
164167 }
165168 }
166169
170+ boolean isBodyRequired = (ope .bodyParam != null && ope .bodyParam .required );
171+
167172 // I can't figure out the correct condition for this one so it's harcoded for now
168173 boolean isSFFV = ope .operationId .equals ("searchForFacetValues" ) && "composition" .equals (ope .tags .get (0 ).getName ());
169174
170175 // hasOptionalWrapper if there is more that one optional param, after the body has been
171176 // flattened, only relevant for go
172177 test .put ("hasOptionalWrapper" , totalOptional > 1 && actuallyHasOptional && !isSFFV );
173- test .put ("hasInlineOptional" , (totalOptional == 1 || isSFFV ) && actuallyHasOptional );
174- test .put ("hasNilOptional" , totalOptional > 0 && !actuallyHasOptional && !isHelper );
175-
176- System .out .println (
177- ope .operationId +
178- " hasOptionalWrapper: " +
179- test .get ("hasOptionalWrapper" ) +
180- " hasNilOptional: " +
181- test .get ("hasNilOptional" ) +
182- " hasInlineOptional: " +
183- test .get ("hasInlineOptional" ) +
184- " totalOptional: " +
185- totalOptional +
186- " actuallyHasOptional: " +
187- actuallyHasOptional +
188- " bodyPropsOptional: " +
189- bodyPropsOptional
190- );
178+ test .put ("hasInlineOptional" , ((totalOptional == 1 || isSFFV ) && actuallyHasOptional ) || isBodyTooBig );
179+ if (isBodyTooBig ) {
180+ boolean isBodySet = alreadyInlinedBody ? parameters .size () > 0 : parameters .containsKey (ope .bodyParam .paramName );
181+ System .out .println ("isBodySet: " + isBodySet );
182+ test .put ("hasNilOptional" , isBodyRequired ? totalOptional > 0 && !actuallyHasOptional : !isBodySet );
183+ } else {
184+ test .put ("hasNilOptional" , totalOptional > 0 && !actuallyHasOptional && !isHelper );
185+ }
191186 }
192187}
0 commit comments