@@ -141,61 +141,61 @@ public static void setOptionalParameters(
141
141
Map <String , Object > parameters ,
142
142
boolean isHelper
143
143
) {
144
- if (!language .equals ("go" )) {
145
- return ;
146
- }
144
+ if (!"go" .equals (language )) return ;
145
+
146
+ boolean isBodyRequired = ope .bodyParam != null && ope .bodyParam .required ;
147
+ boolean alreadyInlinedBody = ope .allParams .size () == 1 && ope .bodyParam != null && !ope .bodyParam .isArray ;
148
+ // I can't figure out the correct condition for this one so it's harcoded for now
149
+ boolean isSFFV =
150
+ "searchForFacetValues" .equals (ope .operationId ) && !ope .tags .isEmpty () && "composition" .equals (ope .tags .get (0 ).getName ());
151
+
147
152
int bodyPropsOptional = 0 ;
148
- boolean actuallyHasOptional = false ;
149
153
boolean isBodyTooBig = false ;
150
- boolean isBodyRequired = (ope .bodyParam != null && ope .bodyParam .required );
151
- boolean alreadyInlinedBody = ope .allParams .size () == 1 && ope .bodyParam != null && !ope .bodyParam .isArray ;
154
+ boolean actuallyHasOptional = false ;
152
155
153
- if (AlgoliaGoGenerator .canFlattenBody (ope )) {
154
- bodyPropsOptional = (int ) ope .bodyParam .getVars ().stream ().filter (prop -> !prop .required ).count ();
155
- isBodyTooBig = ope .bodyParam .getVars ().size () == 0 ;
156
+ if (AlgoliaGoGenerator .canFlattenBody (ope ) && ope .bodyParam != null ) {
157
+ List <CodegenProperty > vars = ope .bodyParam .getVars ();
158
+ bodyPropsOptional = (int ) vars .stream ().filter (p -> !p .required ).count ();
159
+ isBodyTooBig = vars .isEmpty ();
156
160
157
- // edge case where the body is already flattened
158
- Map <String , Object > paramBody = paramBody = parameters ;
161
+ Map <String , Object > paramBody = parameters ;
159
162
if (!alreadyInlinedBody ) {
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 );
163
+ Object paramObj = parameters .get (ope .bodyParam .paramName );
164
+ if (paramObj instanceof String ) {
164
165
actuallyHasOptional = !isBodyRequired ;
165
- } else {
166
- paramBody = (Map <String , Object >) parameters . get ( ope . bodyParam . paramName ) ;
166
+ } else if ( paramObj instanceof Map ) {
167
+ paramBody = (Map <String , Object >) paramObj ;
167
168
}
168
169
}
169
170
170
- for (CodegenProperty prop : ope . bodyParam . getVars () ) {
171
+ for (CodegenProperty prop : vars ) {
171
172
if (!prop .required && paramBody != null && paramBody .containsKey (prop .baseName )) {
172
173
actuallyHasOptional = true ;
173
174
}
174
175
}
175
176
}
176
177
177
- int totalOptional = ope .optionalParams .size () + bodyPropsOptional ;
178
-
179
178
for (CodegenParameter param : ope .allParams ) {
180
179
if (!param .required && parameters .containsKey (param .baseName )) {
181
180
actuallyHasOptional = true ;
182
181
break ;
183
182
}
184
183
}
185
184
186
- // I can't figure out the correct condition for this one so it's harcoded for now
187
- boolean isSFFV = ope .operationId .equals ("searchForFacetValues" ) && "composition" .equals (ope .tags .get (0 ).getName ());
185
+ int totalOptional = ope .optionalParams .size () + bodyPropsOptional ;
188
186
189
187
// hasOptionalWrapper if there is more that one optional param, after the body has been
190
- // flattened, only relevant for go
191
- test .put ("hasOptionalWrapper" , totalOptional > 1 && actuallyHasOptional && !isSFFV );
192
- test .put ("hasInlineOptional" , ((totalOptional == 1 || isSFFV ) && actuallyHasOptional ) || isBodyTooBig );
193
- if (isBodyTooBig ) {
194
- boolean isBodySet = alreadyInlinedBody ? parameters .size () > 0 : parameters .containsKey (ope .bodyParam .paramName );
195
- System .out .println (ope .operationId + " isBodySet: " + isBodySet + " isBodyRequired: " + isBodyRequired );
196
- test .put ("hasNilOptional" , isBodyRequired ? totalOptional > 0 && !actuallyHasOptional : !isBodySet );
197
- } else {
198
- test .put ("hasNilOptional" , totalOptional > 0 && !actuallyHasOptional && !isHelper );
188
+ // flattened.
189
+ boolean hasOptionalWrapper = totalOptional > 1 && actuallyHasOptional && !isSFFV ;
190
+ boolean hasInlineOptional = ((totalOptional == 1 || isSFFV ) && actuallyHasOptional ) || isBodyTooBig ;
191
+ boolean hasNilOptional = totalOptional > 0 && !actuallyHasOptional && !isHelper ;
192
+ if (isBodyTooBig && !isBodyRequired ) {
193
+ boolean isBodySet = alreadyInlinedBody ? !parameters .isEmpty () : parameters .containsKey (ope .bodyParam .paramName );
194
+ hasNilOptional = !isBodySet ;
199
195
}
196
+
197
+ test .put ("hasOptionalWrapper" , hasOptionalWrapper );
198
+ test .put ("hasInlineOptional" , hasInlineOptional );
199
+ test .put ("hasNilOptional" , hasNilOptional );
200
200
}
201
201
}
0 commit comments