Skip to content

Commit 2860eb1

Browse files
committed
Enhance Pageable config. Fixes #1373.
1 parent 225e522 commit 2860eb1

File tree

8 files changed

+115
-44
lines changed

8 files changed

+115
-44
lines changed

springdoc-openapi-common/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
<artifactId>spring-boot-starter-actuator</artifactId>
4747
<optional>true</optional>
4848
</dependency>
49+
<!-- For Enhanced Pageable Support -->
50+
<dependency>
51+
<groupId>org.springframework.data</groupId>
52+
<artifactId>spring-data-commons</artifactId>
53+
<optional>true</optional>
54+
</dependency>
4955
</dependencies>
5056
<build>
5157
<plugins>

springdoc-openapi-common/src/main/java/org/springdoc/core/SpringDocConfigProperties.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,30 @@ public class SpringDocConfigProperties {
167167
*/
168168
private boolean disableI18n;
169169

170+
/**
171+
* The model Converters
172+
*/
173+
private ModelConverters modelConverters = new ModelConverters();
174+
175+
/**
176+
* Gets model converters.
177+
*
178+
* @return the model converters
179+
*/
180+
public ModelConverters getModelConverters() {
181+
return modelConverters;
182+
}
183+
184+
/**
185+
* Sets model converters.
186+
*
187+
* @param modelConverters the model converters
188+
*/
189+
public void setModelConverters(ModelConverters modelConverters) {
190+
this.modelConverters = modelConverters;
191+
}
192+
193+
170194
/**
171195
* Is use management port boolean.
172196
*

springdoc-openapi-common/src/main/java/org/springdoc/core/SpringDocConfiguration.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import org.springframework.context.annotation.Configuration;
7171
import org.springframework.context.annotation.Lazy;
7272
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
73+
import org.springframework.data.domain.Pageable;
7374
import org.springframework.http.HttpStatus;
7475
import org.springframework.http.ResponseEntity;
7576
import org.springframework.util.CollectionUtils;
@@ -176,19 +177,6 @@ SchemaPropertyDeprecatingConverter schemaPropertyDeprecatingConverter() {
176177
return new SchemaPropertyDeprecatingConverter();
177178
}
178179

179-
/**
180-
* Pageable open api converter pageable open api converter.
181-
*
182-
* @return the pageable open api converter
183-
*/
184-
@Bean
185-
@ConditionalOnMissingBean
186-
@ConditionalOnProperty(name = SPRINGDOC_PAGEABLE_CONVERTER_ENABLED)
187-
@Lazy(false)
188-
PageableOpenAPIConverter pageableOpenAPIConverter() {
189-
return new PageableOpenAPIConverter();
190-
}
191-
192180
/**
193181
* Polymorphic model converter polymorphic model converter.
194182
*
@@ -262,7 +250,7 @@ OperationService operationBuilder(GenericParameterService parameterBuilder, Requ
262250
*/
263251
@Bean
264252
PropertyResolverUtils propertyResolverUtils(ConfigurableBeanFactory factory, MessageSource messageSource, SpringDocConfigProperties springDocConfigProperties) {
265-
return new PropertyResolverUtils(factory, messageSource,springDocConfigProperties);
253+
return new PropertyResolverUtils(factory, messageSource, springDocConfigProperties);
266254
}
267255

268256
/**
@@ -450,4 +438,26 @@ WebConversionServiceProvider webConversionServiceProvider(Optional<WebConversion
450438
}
451439
}
452440

441+
/**
442+
* The type Spring doc pageable configuration.
443+
*/
444+
@ConditionalOnClass(Pageable.class)
445+
static class SpringDocPageableConfiguration {
446+
447+
/**
448+
* Pageable open api converter pageable open api converter.
449+
*
450+
* @return the pageable open api converter
451+
*/
452+
@Bean
453+
@ConditionalOnMissingBean
454+
@ConditionalOnProperty(name = SPRINGDOC_PAGEABLE_CONVERTER_ENABLED, matchIfMissing = true)
455+
@Lazy(false)
456+
PageableOpenAPIConverter pageableOpenAPIConverter() {
457+
getConfig().replaceParameterObjectWithClass(org.springframework.data.domain.Pageable.class, org.springdoc.core.converters.models.Pageable.class)
458+
.replaceParameterObjectWithClass(org.springframework.data.domain.PageRequest.class, org.springdoc.core.converters.models.Pageable.class);
459+
return new PageableOpenAPIConverter();
460+
}
461+
}
462+
453463
}

springdoc-openapi-data-rest/src/main/java/org/springdoc/data/rest/SpringDocDataRestConfiguration.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
import org.springdoc.core.OperationService;
3535
import org.springdoc.core.RequestBodyService;
3636
import org.springdoc.core.SpringDocConfigProperties;
37-
import org.springdoc.core.converters.PageableOpenAPIConverter;
3837
import org.springdoc.core.converters.models.DefaultPageable;
39-
import org.springdoc.core.converters.models.Pageable;
4038
import org.springdoc.core.customizers.DelegatingMethodParameterCustomizer;
4139
import org.springdoc.data.rest.core.DataRestOperationService;
4240
import org.springdoc.data.rest.core.DataRestRequestService;
@@ -73,7 +71,6 @@
7371
import org.springframework.hateoas.server.LinkRelationProvider;
7472

7573
import static org.springdoc.core.Constants.SPRINGDOC_ENABLED;
76-
import static org.springdoc.core.Constants.SPRINGDOC_PAGEABLE_CONVERTER_ENABLED;
7774
import static org.springdoc.core.SpringDocUtils.getConfig;
7875

7976
/**
@@ -85,24 +82,6 @@
8582
@ConditionalOnProperty(name = SPRINGDOC_ENABLED, matchIfMissing = true)
8683
public class SpringDocDataRestConfiguration {
8784

88-
static {
89-
getConfig().replaceParameterObjectWithClass(org.springframework.data.domain.Pageable.class, Pageable.class)
90-
.replaceParameterObjectWithClass(org.springframework.data.domain.PageRequest.class, Pageable.class);
91-
}
92-
93-
/**
94-
* Pageable open api converter pageable open api converter.
95-
*
96-
* @return the pageable open api converter
97-
*/
98-
@Bean
99-
@ConditionalOnMissingBean
100-
@ConditionalOnProperty(name = SPRINGDOC_PAGEABLE_CONVERTER_ENABLED, matchIfMissing = true)
101-
@Lazy(false)
102-
PageableOpenAPIConverter pageableOpenAPIConverter() {
103-
return new PageableOpenAPIConverter();
104-
}
105-
10685
/**
10786
* Delegating method parameter customizer delegating method parameter customizer.
10887
*

springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app14/SpringDocApp14Test.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import java.util.Optional;
2727

28-
import org.springdoc.core.converters.models.Pageable;
2928
import org.springdoc.core.customizers.DelegatingMethodParameterCustomizer;
3029
import org.springdoc.data.rest.SpringDocDataRestConfiguration;
3130
import org.springdoc.data.rest.customisers.DataRestDelegatingMethodParameterCustomizer;
@@ -41,8 +40,6 @@
4140
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
4241
import org.springframework.test.context.TestPropertySource;
4342

44-
import static org.springdoc.core.SpringDocUtils.getConfig;
45-
4643
@TestPropertySource(properties = { "spring.data.web.pageable.default-page-size=25",
4744
"spring.data.web.pageable.page-parameter=pages",
4845
"spring.data.web.pageable.size-parameter=sizes",
@@ -52,12 +49,6 @@
5249
})
5350
public class SpringDocApp14Test extends AbstractSpringDocTest {
5451

55-
static {
56-
getConfig().replaceParameterObjectWithClass(org.springframework.data.domain.Pageable.class, Pageable.class)
57-
.replaceParameterObjectWithClass(org.springframework.data.domain.PageRequest.class, Pageable.class);
58-
}
59-
60-
6152
@SpringBootApplication
6253
static class SpringDocTestApp {
6354
// We only need to test spring-web with Pageable, without the use of spring-data-rest-starter

springdoc-openapi-webmvc-core/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
<artifactId>tomcat-embed-core</artifactId>
4444
<scope>test</scope>
4545
</dependency>
46+
<!-- For Enhanced Pageable Support -->
47+
<dependency>
48+
<groupId>org.springframework.data</groupId>
49+
<artifactId>spring-data-commons</artifactId>
50+
<scope>test</scope>
51+
</dependency>
4652
</dependencies>
4753
<build>
4854
<plugins>

springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app125/HelloController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import javax.validation.constraints.NotNull;
44

5+
import org.springdoc.api.annotations.ParameterObject;
6+
7+
import org.springframework.data.domain.Pageable;
58
import org.springframework.web.bind.annotation.GetMapping;
69
import org.springframework.web.bind.annotation.RestController;
710

@@ -16,4 +19,7 @@ public DeprecatedEntity getAllPets(@NotNull String toto) {
1619
return null;
1720
}
1821

22+
@GetMapping(value = "/search2", produces = { "application/xml", "application/json" })
23+
public void getAllPets2(@ParameterObject Pageable pageable) {
24+
}
1925
}

springdoc-openapi-webmvc-core/src/test/resources/results/app125.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,55 @@
4545
}
4646
}
4747
}
48+
},
49+
"/search2": {
50+
"get": {
51+
"tags": [
52+
"hello-controller"
53+
],
54+
"operationId": "getAllPets2",
55+
"parameters": [
56+
{
57+
"name": "page",
58+
"in": "query",
59+
"description": "Zero-based page index (0..N)",
60+
"required": false,
61+
"schema": {
62+
"minimum": 0,
63+
"type": "integer",
64+
"default": 0
65+
}
66+
},
67+
{
68+
"name": "size",
69+
"in": "query",
70+
"description": "The size of the page to be returned",
71+
"required": false,
72+
"schema": {
73+
"minimum": 1,
74+
"type": "integer",
75+
"default": 20
76+
}
77+
},
78+
{
79+
"name": "sort",
80+
"in": "query",
81+
"description": "Sorting criteria in the format: property(,asc|desc). Default sort order is ascending. Multiple sort criteria are supported.",
82+
"required": false,
83+
"schema": {
84+
"type": "array",
85+
"items": {
86+
"type": "string"
87+
}
88+
}
89+
}
90+
],
91+
"responses": {
92+
"200": {
93+
"description": "OK"
94+
}
95+
}
96+
}
4897
}
4998
},
5099
"components": {

0 commit comments

Comments
 (0)