68
68
import org .springdoc .core .customizers .ParameterCustomizer ;
69
69
import org .springdoc .core .extractor .DelegatingMethodParameter ;
70
70
import org .springdoc .core .models .MethodAttributes ;
71
+ import org .springdoc .core .models .ParameterId ;
71
72
import org .springdoc .core .models .ParameterInfo ;
72
73
import org .springdoc .core .models .RequestBodyInfo ;
73
74
import org .springdoc .core .providers .JavadocProvider ;
@@ -328,24 +329,24 @@ else if (!RequestMethod.GET.equals(requestMethod)) {
328
329
}
329
330
}
330
331
331
- LinkedHashMap <String , Parameter > map = getParameterLinkedHashMap (components , methodAttributes , operationParameters , parametersDocMap );
332
+ LinkedHashMap <ParameterId , Parameter > map = getParameterLinkedHashMap (components , methodAttributes , operationParameters , parametersDocMap );
332
333
RequestBody requestBody = requestBodyInfo .getRequestBody ();
333
334
// support form-data
334
335
if (defaultSupportFormData && requestBody != null
335
336
&& requestBody .getContent () != null
336
337
&& requestBody .getContent ().containsKey (org .springframework .http .MediaType .MULTIPART_FORM_DATA_VALUE )) {
337
- Iterator <Entry <String , Parameter >> it = map .entrySet ().iterator ();
338
+ Iterator <Entry <ParameterId , Parameter >> it = map .entrySet ().iterator ();
338
339
while (it .hasNext ()) {
339
- Entry <String , Parameter > entry = it .next ();
340
+ Entry <ParameterId , Parameter > entry = it .next ();
340
341
Parameter parameter = entry .getValue ();
341
342
if (!ParameterIn .PATH .toString ().equals (parameter .getIn ())) {
342
- io .swagger .v3 .oas .models .media .Schema <?> itemSchema = new io .swagger .v3 .oas .models .media .Schema () ;
343
- itemSchema .setName (entry .getKey ());
343
+ io .swagger .v3 .oas .models .media .Schema <?> itemSchema = new io .swagger .v3 .oas .models .media .Schema <>() ;
344
+ itemSchema .setName (entry .getKey (). getpName () );
344
345
itemSchema .setDescription (parameter .getDescription ());
345
346
itemSchema .setDeprecated (parameter .getDeprecated ());
346
347
if (parameter .getExample () != null )
347
348
itemSchema .setExample (parameter .getExample ());
348
- requestBodyInfo .addProperties (entry .getKey (), itemSchema );
349
+ requestBodyInfo .addProperties (entry .getKey (). getpName () , itemSchema );
349
350
it .remove ();
350
351
}
351
352
}
@@ -363,27 +364,32 @@ else if (!RequestMethod.GET.equals(requestMethod)) {
363
364
* @param parametersDocMap the parameters doc map
364
365
* @return the parameter linked hash map
365
366
*/
366
- private LinkedHashMap <String , Parameter > getParameterLinkedHashMap (Components components , MethodAttributes methodAttributes , List <Parameter > operationParameters , Map <String , io .swagger .v3 .oas .annotations .Parameter > parametersDocMap ) {
367
- LinkedHashMap <String , Parameter > map = operationParameters .stream ()
367
+ private LinkedHashMap <ParameterId , Parameter > getParameterLinkedHashMap (Components components , MethodAttributes methodAttributes , List <Parameter > operationParameters , Map <String , io .swagger .v3 .oas .annotations .Parameter > parametersDocMap ) {
368
+ LinkedHashMap <ParameterId , Parameter > map = operationParameters .stream ()
368
369
.collect (Collectors .toMap (
369
- parameter -> parameter . getName () != null ? parameter . getName () : Integer . toString ( parameter . hashCode ()) ,
370
- parameter -> parameter ,
370
+ ParameterId :: new ,
371
+ parameter -> parameter ,
371
372
(u , v ) -> {
372
373
throw new IllegalStateException (String .format ("Duplicate key %s" , u ));
373
374
},
374
375
LinkedHashMap ::new
375
376
));
376
377
377
378
for (Map .Entry <String , io .swagger .v3 .oas .annotations .Parameter > entry : parametersDocMap .entrySet ()) {
378
- if (entry .getKey () != null && !map .containsKey (entry .getKey ()) && !entry .getValue ().hidden ()) {
379
+ ParameterId parameterId = new ParameterId (entry .getValue ());
380
+ if (entry .getKey () != null && !map .containsKey (parameterId ) && !entry .getValue ().hidden ()) {
379
381
//Convert
380
382
Parameter parameter = parameterBuilder .buildParameterFromDoc (entry .getValue (), components ,
381
383
methodAttributes .getJsonViewAnnotation (), methodAttributes .getLocale ());
382
- map .put (entry . getKey () , parameter );
384
+ map .put (parameterId , parameter );
383
385
}
384
386
}
385
387
386
388
getHeaders (methodAttributes , map );
389
+ map .forEach ((parameterId , parameter ) -> {
390
+ if (StringUtils .isBlank (parameter .getIn ()) && StringUtils .isBlank (parameter .get$ref ()))
391
+ parameter .setIn (ParameterIn .QUERY .toString ());
392
+ });
387
393
return map ;
388
394
}
389
395
@@ -395,22 +401,23 @@ private LinkedHashMap<String, Parameter> getParameterLinkedHashMap(Components co
395
401
* @return the headers
396
402
*/
397
403
@ SuppressWarnings ("unchecked" )
398
- public static Collection <Parameter > getHeaders (MethodAttributes methodAttributes , Map <String , Parameter > map ) {
404
+ public static Collection <Parameter > getHeaders (MethodAttributes methodAttributes , Map <ParameterId , Parameter > map ) {
399
405
for (Map .Entry <String , String > entry : methodAttributes .getHeaders ().entrySet ()) {
400
406
StringSchema schema = new StringSchema ();
401
407
if (StringUtils .isNotEmpty (entry .getValue ()))
402
408
schema .addEnumItem (entry .getValue ());
403
409
Parameter parameter = new Parameter ().in (ParameterIn .HEADER .toString ()).name (entry .getKey ()).schema (schema );
404
- if (map .containsKey (entry .getKey ())) {
405
- parameter = map .get (entry .getKey ());
410
+ ParameterId parameterId = new ParameterId (parameter );
411
+ if (map .containsKey (parameterId )) {
412
+ parameter = map .get (parameterId );
406
413
List existingEnum = null ;
407
414
if (parameter .getSchema () != null && !CollectionUtils .isEmpty (parameter .getSchema ().getEnum ()))
408
415
existingEnum = parameter .getSchema ().getEnum ();
409
- if (StringUtils .isNotEmpty (entry .getValue ()) && (existingEnum == null || !existingEnum .contains (entry .getValue ())))
416
+ if (StringUtils .isNotEmpty (entry .getValue ()) && (existingEnum == null || !existingEnum .contains (entry .getValue ())))
410
417
parameter .getSchema ().addEnumItemObject (entry .getValue ());
411
418
parameter .setSchema (parameter .getSchema ());
412
419
}
413
- map .put (entry . getKey () , parameter );
420
+ map .put (parameterId , parameter );
414
421
}
415
422
return map .values ();
416
423
}
@@ -508,7 +515,7 @@ public Parameter buildParams(ParameterInfo parameterInfo, Components components,
508
515
// By default
509
516
if (!isRequestBodyParam (requestMethod , parameterInfo )) {
510
517
parameterInfo .setRequired (!((DelegatingMethodParameter ) methodParameter ).isNotRequired () && !methodParameter .isOptional ());
511
- parameterInfo .setParamType (QUERY_PARAM );
518
+ // parameterInfo.setParamType(QUERY_PARAM);
512
519
parameterInfo .setDefaultValue (null );
513
520
return this .buildParam (parameterInfo , components , jsonView );
514
521
}
0 commit comments