8383import static org .springdoc .core .Constants .QUERY_PARAM ;
8484import static org .springdoc .core .converters .SchemaPropertyDeprecatingConverter .containsDeprecatedAnnotation ;
8585
86+ /**
87+ * The type Abstract request builder.
88+ * @author bnasslahsen
89+ */
8690public abstract class AbstractRequestBuilder {
8791
92+ /**
93+ * The constant PARAM_TYPES_TO_IGNORE.
94+ */
8895 private static final List <Class <?>> PARAM_TYPES_TO_IGNORE = new ArrayList <>();
8996
90- // using string litterals to support both validation-api v1 and v2
97+ /**
98+ * The constant ANNOTATIONS_FOR_REQUIRED.
99+ */
100+ // using string litterals to support both validation-api v1 and v2
91101 private static final String [] ANNOTATIONS_FOR_REQUIRED = { NotNull .class .getName (), "javax.validation.constraints.NotBlank" , "javax.validation.constraints.NotEmpty" };
92102
103+ /**
104+ * The constant POSITIVE_OR_ZERO.
105+ */
93106 private static final String POSITIVE_OR_ZERO = "javax.validation.constraints.PositiveOrZero" ;
94107
108+ /**
109+ * The constant NEGATIVE_OR_ZERO.
110+ */
95111 private static final String NEGATIVE_OR_ZERO = "javax.validation.constraints.NegativeOrZero" ;
96112
97113 static {
@@ -116,16 +132,40 @@ public abstract class AbstractRequestBuilder {
116132 PARAM_TYPES_TO_IGNORE .add (RequestAttribute .class );
117133 }
118134
135+ /**
136+ * The Parameter builder.
137+ */
119138 private final GenericParameterBuilder parameterBuilder ;
120139
140+ /**
141+ * The Request body builder.
142+ */
121143 private final RequestBodyBuilder requestBodyBuilder ;
122144
145+ /**
146+ * The Operation builder.
147+ */
123148 private final OperationBuilder operationBuilder ;
124149
150+ /**
151+ * The Local spring doc parameter name discoverer.
152+ */
125153 private final LocalVariableTableParameterNameDiscoverer localSpringDocParameterNameDiscoverer ;
126154
155+ /**
156+ * The Parameter customizers.
157+ */
127158 private final Optional <List <ParameterCustomizer >> parameterCustomizers ;
128159
160+ /**
161+ * Instantiates a new Abstract request builder.
162+ *
163+ * @param parameterBuilder the parameter builder
164+ * @param requestBodyBuilder the request body builder
165+ * @param operationBuilder the operation builder
166+ * @param parameterCustomizers the parameter customizers
167+ * @param localSpringDocParameterNameDiscoverer the local spring doc parameter name discoverer
168+ */
129169 protected AbstractRequestBuilder (GenericParameterBuilder parameterBuilder , RequestBodyBuilder requestBodyBuilder ,
130170 OperationBuilder operationBuilder , Optional <List <ParameterCustomizer >> parameterCustomizers ,
131171 LocalVariableTableParameterNameDiscoverer localSpringDocParameterNameDiscoverer ) {
@@ -139,20 +179,46 @@ protected AbstractRequestBuilder(GenericParameterBuilder parameterBuilder, Reque
139179 this .localSpringDocParameterNameDiscoverer = localSpringDocParameterNameDiscoverer ;
140180 }
141181
182+ /**
183+ * Add request wrapper to ignore.
184+ *
185+ * @param classes the classes
186+ */
142187 public static void addRequestWrapperToIgnore (Class <?>... classes ) {
143188 PARAM_TYPES_TO_IGNORE .addAll (Arrays .asList (classes ));
144189 }
145190
191+ /**
192+ * Remove request wrapper to ignore.
193+ *
194+ * @param classes the classes
195+ */
146196 public static void removeRequestWrapperToIgnore (Class <?>... classes ) {
147197 List <Class <?>> classesToIgnore = Arrays .asList (classes );
148198 if (PARAM_TYPES_TO_IGNORE .containsAll (classesToIgnore ))
149199 PARAM_TYPES_TO_IGNORE .removeAll (Arrays .asList (classes ));
150200 }
151201
202+ /**
203+ * Is request type to ignore boolean.
204+ *
205+ * @param rawClass the raw class
206+ * @return the boolean
207+ */
152208 public static boolean isRequestTypeToIgnore (Class <?> rawClass ) {
153209 return PARAM_TYPES_TO_IGNORE .stream ().anyMatch (clazz -> clazz .isAssignableFrom (rawClass ));
154210 }
155211
212+ /**
213+ * Build operation.
214+ *
215+ * @param handlerMethod the handler method
216+ * @param requestMethod the request method
217+ * @param operation the operation
218+ * @param methodAttributes the method attributes
219+ * @param openAPI the open api
220+ * @return the operation
221+ */
156222 public Operation build (HandlerMethod handlerMethod , RequestMethod requestMethod ,
157223 Operation operation , MethodAttributes methodAttributes , OpenAPI openAPI ) {
158224 // Documentation
@@ -214,6 +280,15 @@ else if (!RequestMethod.GET.equals(requestMethod)) {
214280 return operation ;
215281 }
216282
283+ /**
284+ * Gets parameter linked hash map.
285+ *
286+ * @param components the components
287+ * @param methodAttributes the method attributes
288+ * @param operationParameters the operation parameters
289+ * @param parametersDocMap the parameters doc map
290+ * @return the parameter linked hash map
291+ */
217292 private LinkedHashMap <String , Parameter > getParameterLinkedHashMap (Components components , MethodAttributes methodAttributes , List <Parameter > operationParameters , Map <String , io .swagger .v3 .oas .annotations .Parameter > parametersDocMap ) {
218293 LinkedHashMap <String , Parameter > map = operationParameters .stream ()
219294 .collect (Collectors .toMap (
@@ -238,6 +313,13 @@ private LinkedHashMap<String, Parameter> getParameterLinkedHashMap(Components co
238313 return map ;
239314 }
240315
316+ /**
317+ * Gets headers.
318+ *
319+ * @param methodAttributes the method attributes
320+ * @param map the map
321+ * @return the headers
322+ */
241323 public static Collection <Parameter > getHeaders (MethodAttributes methodAttributes , Map <String , Parameter > map ) {
242324 for (Map .Entry <String , String > entry : methodAttributes .getHeaders ().entrySet ()) {
243325 Parameter parameter = new Parameter ().in (ParameterIn .HEADER .toString ()).name (entry .getKey ()).schema (new StringSchema ().addEnumItem (entry .getValue ()));
@@ -251,11 +333,24 @@ public static Collection<Parameter> getHeaders(MethodAttributes methodAttributes
251333 return map .values ();
252334 }
253335
336+ /**
337+ * Customise parameter parameter.
338+ *
339+ * @param parameter the parameter
340+ * @param parameterInfo the parameter info
341+ * @return the parameter
342+ */
254343 protected Parameter customiseParameter (Parameter parameter , ParameterInfo parameterInfo ) {
255344 parameterCustomizers .ifPresent (customizers -> customizers .forEach (customizer -> customizer .customize (parameter , parameterInfo .getMethodParameter ())));
256345 return parameter ;
257346 }
258347
348+ /**
349+ * Is param to ignore boolean.
350+ *
351+ * @param parameter the parameter
352+ * @return the boolean
353+ */
259354 public boolean isParamToIgnore (MethodParameter parameter ) {
260355 if (parameterBuilder .isAnnotationToIgnore (parameter ))
261356 return true ;
@@ -266,17 +361,39 @@ public boolean isParamToIgnore(MethodParameter parameter) {
266361 return isRequestTypeToIgnore (parameter .getParameterType ());
267362 }
268363
364+ /**
365+ * Sets params.
366+ *
367+ * @param operation the operation
368+ * @param operationParameters the operation parameters
369+ * @param requestBodyInfo the request body info
370+ */
269371 private void setParams (Operation operation , List <Parameter > operationParameters , RequestBodyInfo requestBodyInfo ) {
270372 if (!CollectionUtils .isEmpty (operationParameters ))
271373 operation .setParameters (operationParameters );
272374 if (requestBodyInfo .getRequestBody () != null )
273375 operation .setRequestBody (requestBodyInfo .getRequestBody ());
274376 }
275377
378+ /**
379+ * Is valid parameter boolean.
380+ *
381+ * @param parameter the parameter
382+ * @return the boolean
383+ */
276384 public boolean isValidParameter (Parameter parameter ) {
277385 return parameter != null && (parameter .getName () != null || parameter .get$ref () != null );
278386 }
279387
388+ /**
389+ * Build params parameter.
390+ *
391+ * @param parameterInfo the parameter info
392+ * @param components the components
393+ * @param requestMethod the request method
394+ * @param jsonView the json view
395+ * @return the parameter
396+ */
280397 public Parameter buildParams (ParameterInfo parameterInfo , Components components ,
281398 RequestMethod requestMethod , JsonView jsonView ) {
282399 MethodParameter methodParameter = parameterInfo .getMethodParameter ();
@@ -317,6 +434,15 @@ else if (cookieValue != null) {
317434 return null ;
318435 }
319436
437+ /**
438+ * Build param parameter.
439+ *
440+ * @param parameterInfo the parameter info
441+ * @param components the components
442+ * @param requestInfo the request info
443+ * @param jsonView the json view
444+ * @return the parameter
445+ */
320446 private Parameter buildParam (ParameterInfo parameterInfo , Components components , RequestInfo requestInfo ,
321447 JsonView jsonView ) {
322448 Parameter parameter ;
@@ -333,6 +459,17 @@ private Parameter buildParam(ParameterInfo parameterInfo, Components components,
333459 return parameter ;
334460 }
335461
462+ /**
463+ * Build param parameter.
464+ *
465+ * @param in the in
466+ * @param components the components
467+ * @param parameterInfo the parameter info
468+ * @param required the required
469+ * @param defaultValue the default value
470+ * @param jsonView the json view
471+ * @return the parameter
472+ */
336473 private Parameter buildParam (String in , Components components , ParameterInfo parameterInfo , Boolean required ,
337474 String defaultValue , JsonView jsonView ) {
338475 Parameter parameter = parameterInfo .getParameterModel ();
@@ -365,6 +502,12 @@ private Parameter buildParam(String in, Components components, ParameterInfo par
365502 return parameter ;
366503 }
367504
505+ /**
506+ * Apply bean validator annotations.
507+ *
508+ * @param parameter the parameter
509+ * @param annotations the annotations
510+ */
368511 public void applyBeanValidatorAnnotations (final Parameter parameter , final List <Annotation > annotations ) {
369512 Map <String , Annotation > annos = new HashMap <>();
370513 if (annotations != null )
@@ -376,6 +519,13 @@ public void applyBeanValidatorAnnotations(final Parameter parameter, final List<
376519 applyValidationsToSchema (annos , schema );
377520 }
378521
522+ /**
523+ * Apply bean validator annotations.
524+ *
525+ * @param requestBody the request body
526+ * @param annotations the annotations
527+ * @param isOptional the is optional
528+ */
379529 public void applyBeanValidatorAnnotations (final RequestBody requestBody , final List <Annotation > annotations , boolean isOptional ) {
380530 Map <String , Annotation > annos = new HashMap <>();
381531 boolean requestBodyRequired = false ;
@@ -396,6 +546,12 @@ public void applyBeanValidatorAnnotations(final RequestBody requestBody, final L
396546 }
397547 }
398548
549+ /**
550+ * Calculate size.
551+ *
552+ * @param annos the annos
553+ * @param schema the schema
554+ */
399555 private void calculateSize (Map <String , Annotation > annos , Schema <?> schema ) {
400556 if (annos .containsKey (Size .class .getName ())) {
401557 Size size = (Size ) annos .get (Size .class .getName ());
@@ -410,10 +566,21 @@ else if (OPENAPI_STRING_TYPE.equals(schema.getType())) {
410566 }
411567 }
412568
569+ /**
570+ * Gets request body builder.
571+ *
572+ * @return the request body builder
573+ */
413574 public RequestBodyBuilder getRequestBodyBuilder () {
414575 return requestBodyBuilder ;
415576 }
416577
578+ /**
579+ * Gets api parameters.
580+ *
581+ * @param method the method
582+ * @return the api parameters
583+ */
417584 private Map <String , io .swagger .v3 .oas .annotations .Parameter > getApiParameters (Method method ) {
418585 Class <?> declaringClass = method .getDeclaringClass ();
419586
@@ -447,6 +614,12 @@ private Map<String, io.swagger.v3.oas.annotations.Parameter> getApiParameters(Me
447614 return apiParametersMap ;
448615 }
449616
617+ /**
618+ * Apply validations to schema.
619+ *
620+ * @param annos the annos
621+ * @param schema the schema
622+ */
450623 private void applyValidationsToSchema (Map <String , Annotation > annos , Schema <?> schema ) {
451624 if (annos .containsKey (Min .class .getName ())) {
452625 Min min = (Min ) annos .get (Min .class .getName ());
0 commit comments