1- package org .springdoc .data . rest . customisers ;
1+ package org .springdoc .core . customizers ;
22
33import java .lang .annotation .Annotation ;
44import java .lang .reflect .Field ;
2424import org .slf4j .Logger ;
2525import org .slf4j .LoggerFactory ;
2626import org .springdoc .core .DelegatingMethodParameter ;
27- import org .springdoc .core .customizers .DelegatingMethodParameterCustomizer ;
27+ import org .springdoc .core .providers .RepositoryRestConfigurationProvider ;
28+ import org .springdoc .core .providers .SpringDataWebPropertiesProvider ;
2829
29- import org .springframework .boot .autoconfigure .data .web .SpringDataWebProperties ;
3030import org .springframework .core .MethodParameter ;
31- import org .springframework .data .rest .core .config .RepositoryRestConfiguration ;
3231import org .springframework .data .web .PageableDefault ;
3332
3433/**
@@ -41,39 +40,42 @@ public class DataRestDelegatingMethodParameterCustomizer implements DelegatingMe
4140 */
4241 private static final Logger LOGGER = LoggerFactory .getLogger (DataRestDelegatingMethodParameterCustomizer .class );
4342
43+
4444 /**
45- * The Optional spring data web properties.
45+ * The Optional spring data web properties provider .
4646 */
47- private final Optional <SpringDataWebProperties > optionalSpringDataWebProperties ;
47+ private final Optional <SpringDataWebPropertiesProvider > optionalSpringDataWebPropertiesProvider ;
48+
4849
4950 /**
50- * The Optional repository rest configuration.
51+ * The Optional repository rest configuration provider .
5152 */
52- private final Optional <RepositoryRestConfiguration > optionalRepositoryRestConfiguration ;
53+ private final Optional <RepositoryRestConfigurationProvider > optionalRepositoryRestConfigurationProvider ;
54+
5355
5456 /**
5557 * Instantiates a new Data rest delegating method parameter customizer.
5658 *
57- * @param optionalSpringDataWebProperties the optional spring data web properties
58- * @param optionalRepositoryRestConfiguration the optional repository rest configuration
59+ * @param optionalSpringDataWebPropertiesProvider the optional spring data web properties provider
60+ * @param optionalRepositoryRestConfigurationProvider the optional repository rest configuration provider
5961 */
60- public DataRestDelegatingMethodParameterCustomizer (Optional <SpringDataWebProperties > optionalSpringDataWebProperties , Optional <RepositoryRestConfiguration > optionalRepositoryRestConfiguration ) {
61- this .optionalSpringDataWebProperties = optionalSpringDataWebProperties ;
62- this .optionalRepositoryRestConfiguration = optionalRepositoryRestConfiguration ;
62+ public DataRestDelegatingMethodParameterCustomizer (Optional <SpringDataWebPropertiesProvider > optionalSpringDataWebPropertiesProvider , Optional <RepositoryRestConfigurationProvider > optionalRepositoryRestConfigurationProvider ) {
63+ this .optionalSpringDataWebPropertiesProvider = optionalSpringDataWebPropertiesProvider ;
64+ this .optionalRepositoryRestConfigurationProvider = optionalRepositoryRestConfigurationProvider ;
6365 }
6466
6567 @ Override
6668 public void customize (MethodParameter originalParameter , MethodParameter methodParameter ) {
6769 PageableDefault pageableDefault = originalParameter .getParameterAnnotation (PageableDefault .class );
68- if (pageableDefault != null || (org .springframework .data .domain .Pageable .class .isAssignableFrom (originalParameter .getParameterType ()) && (optionalSpringDataWebProperties . isPresent () || optionalRepositoryRestConfiguration . isPresent ()))) {
70+ if (pageableDefault != null || (org .springframework .data .domain .Pageable .class .isAssignableFrom (originalParameter .getParameterType ()) && (isSpringDataWebPropertiesPresent () || isRepositoryRestConfigurationPresent ()))) {
6971 Field field = FieldUtils .getDeclaredField (DelegatingMethodParameter .class , "additionalParameterAnnotations" , true );
7072 try {
7173 Annotation [] parameterAnnotations = (Annotation []) field .get (methodParameter );
7274 if (ArrayUtils .isNotEmpty (parameterAnnotations ))
7375 for (int i = 0 ; i < parameterAnnotations .length ; i ++) {
74- if (Parameter .class .equals (parameterAnnotations [i ].annotationType ())){
75- Optional <Annotation > annotationForField = getNewParameterAnnotationForField (methodParameter , pageableDefault );
76- if (annotationForField .isPresent ())
76+ if (Parameter .class .equals (parameterAnnotations [i ].annotationType ())) {
77+ Optional <Annotation > annotationForField = getNewParameterAnnotationForField (methodParameter , pageableDefault );
78+ if (annotationForField .isPresent ())
7779 parameterAnnotations [i ] = annotationForField .get ();
7880 }
7981 }
@@ -637,26 +639,26 @@ private String getName(String parameterName, String originalName) {
637639 String name = null ;
638640 switch (parameterName ) {
639641 case "size" :
640- if (optionalRepositoryRestConfiguration . isPresent ())
641- name = optionalRepositoryRestConfiguration .get ().getLimitParamName ();
642- else if (optionalSpringDataWebProperties . isPresent ())
643- name = optionalSpringDataWebProperties .get ().getPageable ().getSizeParameter ();
642+ if (isRepositoryRestConfigurationPresent ())
643+ name = optionalRepositoryRestConfigurationProvider .get (). getRepositoryRestConfiguration ().getLimitParamName ();
644+ else if (isSpringDataWebPropertiesPresent ())
645+ name = optionalSpringDataWebPropertiesProvider .get (). getSpringDataWebProperties ().getPageable ().getSizeParameter ();
644646 else
645647 name = originalName ;
646648 break ;
647649 case "sort" :
648- if (optionalRepositoryRestConfiguration . isPresent ())
649- name = optionalRepositoryRestConfiguration .get ().getSortParamName ();
650- else if (optionalSpringDataWebProperties . isPresent ())
651- name = optionalSpringDataWebProperties .get ().getSort ().getSortParameter ();
650+ if (isRepositoryRestConfigurationPresent ())
651+ name = optionalRepositoryRestConfigurationProvider .get (). getRepositoryRestConfiguration ().getSortParamName ();
652+ else if (isSpringDataWebPropertiesPresent ())
653+ name = optionalSpringDataWebPropertiesProvider .get (). getSpringDataWebProperties ().getSort ().getSortParameter ();
652654 else
653655 name = originalName ;
654656 break ;
655657 case "page" :
656- if (optionalRepositoryRestConfiguration . isPresent ())
657- name = optionalRepositoryRestConfiguration .get ().getPageParamName ();
658- else if (optionalSpringDataWebProperties . isPresent ())
659- name = optionalSpringDataWebProperties .get ().getPageable ().getPageParameter ();
658+ if (isRepositoryRestConfigurationPresent ())
659+ name = optionalRepositoryRestConfigurationProvider .get (). getRepositoryRestConfiguration ().getPageParamName ();
660+ else if (isSpringDataWebPropertiesPresent ())
661+ name = optionalSpringDataWebPropertiesProvider .get (). getSpringDataWebProperties ().getPageable ().getPageParameter ();
660662 else
661663 name = originalName ;
662664 break ;
@@ -684,10 +686,10 @@ private String getDefaultValue(String parameterName, PageableDefault pageableDef
684686 case "size" :
685687 if (pageableDefault != null )
686688 defaultValue = String .valueOf (pageableDefault .size ());
687- else if (optionalRepositoryRestConfiguration . isPresent ())
688- defaultValue = String .valueOf (optionalRepositoryRestConfiguration .get ().getDefaultPageSize ());
689- else if (optionalSpringDataWebProperties . isPresent ())
690- defaultValue = String .valueOf (optionalSpringDataWebProperties .get ().getPageable ().getDefaultPageSize ());
689+ else if (isRepositoryRestConfigurationPresent ())
690+ defaultValue = String .valueOf (optionalRepositoryRestConfigurationProvider .get (). getRepositoryRestConfiguration ().getDefaultPageSize ());
691+ else if (isSpringDataWebPropertiesPresent ())
692+ defaultValue = String .valueOf (optionalSpringDataWebPropertiesProvider .get (). getSpringDataWebProperties ().getPageable ().getDefaultPageSize ());
691693 else
692694 defaultValue = defaultSchemaVal ;
693695 break ;
@@ -730,4 +732,21 @@ private String getArrayDefaultValue(String parameterName, PageableDefault pageab
730732 return defaultValue ;
731733 }
732734
735+ /**
736+ * Spring data web properties is present boolean.
737+ *
738+ * @return the boolean
739+ */
740+ private boolean isSpringDataWebPropertiesPresent () {
741+ return optionalSpringDataWebPropertiesProvider .isPresent () && optionalSpringDataWebPropertiesProvider .get ().isSpringDataWebPropertiesPresent ();
742+ }
743+
744+ /**
745+ * Repository rest configuration is present boolean.
746+ *
747+ * @return the boolean
748+ */
749+ private boolean isRepositoryRestConfigurationPresent () {
750+ return optionalRepositoryRestConfigurationProvider .isPresent () && optionalRepositoryRestConfigurationProvider .get ().isRepositoryRestConfigurationPresent ();
751+ }
733752}
0 commit comments