1
+ /*
2
+ *
3
+ * *
4
+ * * *
5
+ * * * * Copyright 2019-2024 the original author or authors.
6
+ * * * *
7
+ * * * * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * * * * you may not use this file except in compliance with the License.
9
+ * * * * You may obtain a copy of the License at
10
+ * * * *
11
+ * * * * https://www.apache.org/licenses/LICENSE-2.0
12
+ * * * *
13
+ * * * * Unless required by applicable law or agreed to in writing, software
14
+ * * * * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * * * * See the License for the specific language governing permissions and
17
+ * * * * limitations under the License.
18
+ * * *
19
+ * *
20
+ *
21
+ */
22
+
23
+ package org .springdoc .core .configuration ;
24
+
25
+ import org .springdoc .core .converters .PageOpenAPIConverter ;
26
+ import org .springdoc .core .converters .SortOpenAPIConverter ;
27
+ import org .springdoc .core .converters .models .SortObject ;
28
+ import org .springdoc .core .customizers .DataRestDelegatingMethodParameterCustomizer ;
29
+ import org .springdoc .core .customizers .DelegatingMethodParameterCustomizer ;
30
+ import org .springdoc .core .providers .ObjectMapperProvider ;
31
+ import org .springdoc .core .providers .RepositoryRestConfigurationProvider ;
32
+ import org .springdoc .core .providers .SpringDataWebPropertiesProvider ;
33
+ import org .springframework .boot .autoconfigure .condition .*;
34
+ import org .springframework .context .annotation .Bean ;
35
+ import org .springframework .context .annotation .Configuration ;
36
+ import org .springframework .context .annotation .Lazy ;
37
+ import org .springframework .data .domain .Page ;
38
+ import org .springframework .data .domain .Sort ;
39
+ import org .springframework .data .web .PagedModel ;
40
+ import org .springframework .data .web .config .EnableSpringDataWebSupport ;
41
+ import org .springframework .data .web .config .SpringDataWebSettings ;
42
+
43
+ import java .util .Optional ;
44
+
45
+ import static org .springdoc .core .utils .Constants .SPRINGDOC_ENABLED ;
46
+ import static org .springdoc .core .utils .Constants .SPRINGDOC_SORT_CONVERTER_ENABLED ;
47
+ import static org .springdoc .core .utils .SpringDocUtils .getConfig ;
48
+
49
+ /**
50
+ * The type Spring doc page configuration.
51
+ *
52
+ * @author Claudio Nave
53
+ */
54
+ @ Lazy (false )
55
+ @ Configuration (proxyBeanMethods = false )
56
+ @ ConditionalOnProperty (name = SPRINGDOC_ENABLED , matchIfMissing = true )
57
+ @ ConditionalOnClass ({ Page .class , PagedModel .class })
58
+ @ ConditionalOnWebApplication
59
+ @ ConditionalOnBean (SpringDocConfiguration .class )
60
+ public class SpringDocPageConfiguration {
61
+
62
+ /**
63
+ * Page open api converter.
64
+ * @param objectMapperProvider the object mapper provider
65
+ * @return the page open api converter
66
+ */
67
+ @ Bean
68
+ @ ConditionalOnMissingBean
69
+ @ ConditionalOnBean (SpringDataWebSettings .class )
70
+ @ Lazy (false )
71
+ PageOpenAPIConverter pageOpenAPIConverter (SpringDataWebSettings settings ,
72
+ ObjectMapperProvider objectMapperProvider ) {
73
+ return new PageOpenAPIConverter (
74
+ settings .pageSerializationMode () == EnableSpringDataWebSupport .PageSerializationMode .VIA_DTO ,
75
+ objectMapperProvider );
76
+ }
77
+
78
+ /**
79
+ * Delegating method parameter customizer delegating method parameter customizer.
80
+ * @param optionalSpringDataWebPropertiesProvider the optional spring data web
81
+ * properties
82
+ * @param optionalRepositoryRestConfiguration the optional repository rest
83
+ * configuration
84
+ * @return the delegating method parameter customizer
85
+ */
86
+ @ Bean
87
+ @ ConditionalOnMissingBean
88
+ @ Lazy (false )
89
+ DelegatingMethodParameterCustomizer delegatingMethodParameterCustomizer (
90
+ Optional <SpringDataWebPropertiesProvider > optionalSpringDataWebPropertiesProvider ,
91
+ Optional <RepositoryRestConfigurationProvider > optionalRepositoryRestConfiguration ) {
92
+ return new DataRestDelegatingMethodParameterCustomizer (optionalSpringDataWebPropertiesProvider ,
93
+ optionalRepositoryRestConfiguration );
94
+ }
95
+
96
+ }
0 commit comments