Skip to content

Commit b7be72d

Browse files
committed
Changes report: fix: propagate JsonView context when resolving Page<T> schema #3226 Merged
1 parent 4f4c6bd commit b7be72d

6 files changed

Lines changed: 333 additions & 0 deletions

File tree

springdoc-openapi-starter-webmvc-api/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
<artifactId>spring-boot-health</artifactId>
5050
<scope>test</scope>
5151
</dependency>
52+
<!-- For Enhanced Pageable Support -->
53+
<dependency>
54+
<groupId>org.springframework.data</groupId>
55+
<artifactId>spring-data-commons</artifactId>
56+
<scope>test</scope>
57+
</dependency>
5258
</dependencies>
5359
<build>
5460
<plugins>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * * Copyright 2019-2025 the original author or authors.
7+
* * * * *
8+
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
9+
* * * * * you may not use this file except in compliance with the License.
10+
* * * * * You may obtain a copy of the License at
11+
* * * * *
12+
* * * * * https://www.apache.org/licenses/LICENSE-2.0
13+
* * * * *
14+
* * * * * Unless required by applicable law or agreed to in writing, software
15+
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
16+
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* * * * * See the License for the specific language governing permissions and
18+
* * * * * limitations under the License.
19+
* * * *
20+
* * *
21+
* *
22+
*
23+
*/
24+
package test.org.springdoc.api.v30.app246;
25+
26+
import java.util.List;
27+
28+
import com.fasterxml.jackson.annotation.JsonView;
29+
import org.springdoc.core.annotations.ParameterObject;
30+
31+
import org.springframework.data.domain.Page;
32+
import org.springframework.data.domain.PageImpl;
33+
import org.springframework.data.domain.Pageable;
34+
import org.springframework.http.ResponseEntity;
35+
import org.springframework.web.bind.annotation.GetMapping;
36+
import org.springframework.web.bind.annotation.RestController;
37+
38+
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
39+
40+
@RestController
41+
public class HelloController {
42+
43+
@JsonView(Views.Hello.class)
44+
@GetMapping(value = "/hello-paged", produces = APPLICATION_JSON_VALUE)
45+
public ResponseEntity<Page<HelloWorld>> getHelloWorldPaged(@ParameterObject Pageable pageable) {
46+
return ResponseEntity.ok(new PageImpl<>(List.of(new HelloWorld("hello", "world")), pageable, 1));
47+
}
48+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * * Copyright 2019-2025 the original author or authors.
7+
* * * * *
8+
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
9+
* * * * * you may not use this file except in compliance with the License.
10+
* * * * * You may obtain a copy of the License at
11+
* * * * *
12+
* * * * * https://www.apache.org/licenses/LICENSE-2.0
13+
* * * * *
14+
* * * * * Unless required by applicable law or agreed to in writing, software
15+
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
16+
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* * * * * See the License for the specific language governing permissions and
18+
* * * * * limitations under the License.
19+
* * * *
20+
* * *
21+
* *
22+
*
23+
*/
24+
package test.org.springdoc.api.v30.app246;
25+
26+
import com.fasterxml.jackson.annotation.JsonView;
27+
28+
public class HelloWorld {
29+
30+
@JsonView(Views.Hello.class)
31+
private String hello;
32+
33+
@JsonView(Views.World.class)
34+
private String world;
35+
36+
public HelloWorld(String hello, String world) {
37+
this.hello = hello;
38+
this.world = world;
39+
}
40+
41+
public String getHello() {
42+
return hello;
43+
}
44+
45+
public String getWorld() {
46+
return world;
47+
}
48+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * * Copyright 2019-2025 the original author or authors.
7+
* * * * *
8+
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
9+
* * * * * you may not use this file except in compliance with the License.
10+
* * * * * You may obtain a copy of the License at
11+
* * * * *
12+
* * * * * https://www.apache.org/licenses/LICENSE-2.0
13+
* * * * *
14+
* * * * * Unless required by applicable law or agreed to in writing, software
15+
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
16+
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* * * * * See the License for the specific language governing permissions and
18+
* * * * * limitations under the License.
19+
* * * *
20+
* * *
21+
* *
22+
*
23+
*/
24+
package test.org.springdoc.api.v30.app246;
25+
26+
import test.org.springdoc.api.v30.AbstractSpringDocV30Test;
27+
28+
import org.springframework.boot.autoconfigure.SpringBootApplication;
29+
30+
public class SpringDocApp246Test extends AbstractSpringDocV30Test {
31+
@SpringBootApplication
32+
static class SpringDocTestApp {}
33+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * * Copyright 2019-2025 the original author or authors.
7+
* * * * *
8+
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
9+
* * * * * you may not use this file except in compliance with the License.
10+
* * * * * You may obtain a copy of the License at
11+
* * * * *
12+
* * * * * https://www.apache.org/licenses/LICENSE-2.0
13+
* * * * *
14+
* * * * * Unless required by applicable law or agreed to in writing, software
15+
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
16+
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* * * * * See the License for the specific language governing permissions and
18+
* * * * * limitations under the License.
19+
* * * *
20+
* * *
21+
* *
22+
*
23+
*/
24+
package test.org.springdoc.api.v30.app246;
25+
26+
public class Views {
27+
public static class Hello {}
28+
public static class World {}
29+
}
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"paths": {
14+
"/hello-paged": {
15+
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "getHelloWorldPaged",
20+
"parameters": [
21+
{
22+
"name": "page",
23+
"in": "query",
24+
"description": "Zero-based page index (0..N)",
25+
"required": false,
26+
"schema": {
27+
"minimum": 0,
28+
"type": "integer",
29+
"default": 0
30+
}
31+
},
32+
{
33+
"name": "size",
34+
"in": "query",
35+
"description": "The size of the page to be returned",
36+
"required": false,
37+
"schema": {
38+
"minimum": 1,
39+
"type": "integer",
40+
"default": 20
41+
}
42+
},
43+
{
44+
"name": "sort",
45+
"in": "query",
46+
"description": "Sorting criteria in the format: property,(asc|desc). Default sort order is ascending. Multiple sort criteria are supported.",
47+
"required": false,
48+
"schema": {
49+
"type": "array",
50+
"items": {
51+
"type": "string"
52+
}
53+
}
54+
}
55+
],
56+
"responses": {
57+
"200": {
58+
"description": "OK",
59+
"content": {
60+
"application/json": {
61+
"schema": {
62+
"$ref": "#/components/schemas/PageHelloWorld_Hello"
63+
}
64+
}
65+
}
66+
}
67+
}
68+
}
69+
}
70+
},
71+
"components": {
72+
"schemas": {
73+
"HelloWorld_Hello": {
74+
"type": "object",
75+
"properties": {
76+
"hello": {
77+
"type": "string"
78+
}
79+
}
80+
},
81+
"PageHelloWorld_Hello": {
82+
"type": "object",
83+
"properties": {
84+
"totalElements": {
85+
"type": "integer",
86+
"format": "int64"
87+
},
88+
"totalPages": {
89+
"type": "integer",
90+
"format": "int32"
91+
},
92+
"first": {
93+
"type": "boolean"
94+
},
95+
"last": {
96+
"type": "boolean"
97+
},
98+
"size": {
99+
"type": "integer",
100+
"format": "int32"
101+
},
102+
"content": {
103+
"type": "array",
104+
"items": {
105+
"$ref": "#/components/schemas/HelloWorld_Hello"
106+
}
107+
},
108+
"number": {
109+
"type": "integer",
110+
"format": "int32"
111+
},
112+
"sort": {
113+
"$ref": "#/components/schemas/SortObject_Hello"
114+
},
115+
"numberOfElements": {
116+
"type": "integer",
117+
"format": "int32"
118+
},
119+
"pageable": {
120+
"$ref": "#/components/schemas/PageableObject_Hello"
121+
},
122+
"empty": {
123+
"type": "boolean"
124+
}
125+
}
126+
},
127+
"PageableObject_Hello": {
128+
"type": "object",
129+
"properties": {
130+
"offset": {
131+
"type": "integer",
132+
"format": "int64"
133+
},
134+
"sort": {
135+
"$ref": "#/components/schemas/SortObject_Hello"
136+
},
137+
"paged": {
138+
"type": "boolean"
139+
},
140+
"unpaged": {
141+
"type": "boolean"
142+
},
143+
"pageSize": {
144+
"type": "integer",
145+
"format": "int32"
146+
},
147+
"pageNumber": {
148+
"type": "integer",
149+
"format": "int32"
150+
}
151+
}
152+
},
153+
"SortObject_Hello": {
154+
"type": "object",
155+
"properties": {
156+
"empty": {
157+
"type": "boolean"
158+
},
159+
"sorted": {
160+
"type": "boolean"
161+
},
162+
"unsorted": {
163+
"type": "boolean"
164+
}
165+
}
166+
}
167+
}
168+
}
169+
}

0 commit comments

Comments
 (0)