Skip to content

Commit fddc802

Browse files
committed
QuerydslBinderCustomizer alias being removed when using excludeUnlistedProperties. Fixes #1075
1 parent ab907e1 commit fddc802

File tree

7 files changed

+301
-1
lines changed

7 files changed

+301
-1
lines changed

springdoc-openapi-data-rest/src/main/java/org/springdoc/data/rest/customisers/QuerydslPredicateOperationCustomizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public Operation customize(Operation operation, HandlerMethod handlerMethod) {
118118

119119
// if only listed properties should be included, remove all other fields from fieldsToAdd
120120
if (getFieldValueOfBoolean(bindings, "excludeUnlistedProperties")) {
121-
fieldsToAdd.removeIf(s -> !whiteList.contains(s));
121+
fieldsToAdd.removeIf(s -> !whiteList.contains(s) && !aliases.contains(s) );
122122
}
123123

124124
for (String fieldName : fieldsToAdd) {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package test.org.springdoc.api.app24;
2+
3+
import javax.annotation.Generated;
4+
5+
import com.querydsl.core.types.Path;
6+
import com.querydsl.core.types.PathMetadata;
7+
import com.querydsl.core.types.dsl.EntityPathBase;
8+
import com.querydsl.core.types.dsl.NumberPath;
9+
import com.querydsl.core.types.dsl.StringPath;
10+
11+
import static com.querydsl.core.types.PathMetadataFactory.forVariable;
12+
13+
14+
/**
15+
* QUser is a Querydsl query type for User
16+
*/
17+
@Generated("com.querydsl.codegen.EntitySerializer")
18+
public class QUser extends EntityPathBase<User> {
19+
20+
private static final long serialVersionUID = 222331676L;
21+
22+
public static final QUser user = new QUser("user");
23+
24+
public final StringPath email = createString("email");
25+
26+
public final StringPath firstName = createString("firstName");
27+
28+
public final NumberPath<Long> id = createNumber("id", Long.class);
29+
30+
public final StringPath lastName = createString("lastName");
31+
32+
public QUser(String variable) {
33+
super(User.class, forVariable(variable));
34+
}
35+
36+
public QUser(Path<? extends User> path) {
37+
super(path.getType(), path.getMetadata());
38+
}
39+
40+
public QUser(PathMetadata metadata) {
41+
super(User.class, metadata);
42+
}
43+
44+
}
45+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * * Copyright 2019-2020 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+
24+
package test.org.springdoc.api.app24;
25+
26+
import test.org.springdoc.api.AbstractSpringDocTest;
27+
28+
import org.springframework.boot.autoconfigure.SpringBootApplication;
29+
30+
public class SpringDocApp24Test extends AbstractSpringDocTest {
31+
32+
@SpringBootApplication
33+
static class SpringDocTestApp {}
34+
35+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package test.org.springdoc.api.app24;
2+
3+
import com.querydsl.core.types.Predicate;
4+
import lombok.AllArgsConstructor;
5+
6+
import org.springframework.data.domain.Page;
7+
import org.springframework.data.domain.Pageable;
8+
import org.springframework.data.querydsl.binding.QuerydslPredicate;
9+
import org.springframework.web.bind.annotation.GetMapping;
10+
import org.springframework.web.bind.annotation.RestController;
11+
12+
13+
@RestController
14+
@AllArgsConstructor
15+
public class TesteResource {
16+
17+
@GetMapping("/")
18+
public Page<User> testeQueryDslAndSpringDoc(@QuerydslPredicate(root = User.class, bindings = UserPredicate.class) Predicate predicate, Pageable pageable) {
19+
return null;
20+
}
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package test.org.springdoc.api.app24;
2+
3+
import javax.persistence.Entity;
4+
import javax.persistence.GeneratedValue;
5+
import javax.persistence.GenerationType;
6+
import javax.persistence.Id;
7+
8+
import lombok.Getter;
9+
import lombok.Setter;
10+
11+
@Entity
12+
@Getter
13+
@Setter
14+
public class User {
15+
@Id
16+
@GeneratedValue(strategy = GenerationType.IDENTITY)
17+
private Long id;
18+
private String firstName;
19+
private String lastName;
20+
private String email;
21+
}
22+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package test.org.springdoc.api.app24;
2+
3+
import org.springframework.data.querydsl.binding.QuerydslBinderCustomizer;
4+
import org.springframework.data.querydsl.binding.QuerydslBindings;
5+
6+
public class UserPredicate implements QuerydslBinderCustomizer<QUser> {
7+
8+
9+
@Override
10+
public void customize(QuerydslBindings bindings, QUser user) {
11+
bindings.excludeUnlistedProperties(true);
12+
bindings.including(user.email);
13+
bindings.bind(user.firstName).as("name").withDefaultBinding();
14+
}
15+
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
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+
"/": {
15+
"get": {
16+
"tags": [
17+
"teste-resource"
18+
],
19+
"operationId": "testeQueryDslAndSpringDoc",
20+
"parameters": [
21+
{
22+
"name": "pageable",
23+
"in": "query",
24+
"required": true,
25+
"schema": {
26+
"$ref": "#/components/schemas/Pageable"
27+
}
28+
},
29+
{
30+
"name": "name",
31+
"in": "query",
32+
"schema": {
33+
"type": "string"
34+
}
35+
},
36+
{
37+
"name": "email",
38+
"in": "query",
39+
"schema": {
40+
"type": "string"
41+
}
42+
}
43+
],
44+
"responses": {
45+
"200": {
46+
"description": "OK",
47+
"content": {
48+
"application/hal+json": {
49+
"schema": {
50+
"$ref": "#/components/schemas/PageUser"
51+
}
52+
}
53+
}
54+
}
55+
}
56+
}
57+
}
58+
},
59+
"components": {
60+
"schemas": {
61+
"Pageable": {
62+
"type": "object",
63+
"properties": {
64+
"page": {
65+
"minimum": 0,
66+
"type": "integer",
67+
"format": "int32"
68+
},
69+
"size": {
70+
"minimum": 1,
71+
"type": "integer",
72+
"format": "int32"
73+
},
74+
"sort": {
75+
"type": "array",
76+
"items": {
77+
"type": "string"
78+
}
79+
}
80+
}
81+
},
82+
"PageUser": {
83+
"type": "object",
84+
"properties": {
85+
"totalPages": {
86+
"type": "integer",
87+
"format": "int32"
88+
},
89+
"totalElements": {
90+
"type": "integer",
91+
"format": "int64"
92+
},
93+
"numberOfElements": {
94+
"type": "integer",
95+
"format": "int32"
96+
},
97+
"pageable": {
98+
"$ref": "#/components/schemas/Pageable"
99+
},
100+
"size": {
101+
"type": "integer",
102+
"format": "int32"
103+
},
104+
"content": {
105+
"type": "array",
106+
"items": {
107+
"$ref": "#/components/schemas/User"
108+
}
109+
},
110+
"number": {
111+
"type": "integer",
112+
"format": "int32"
113+
},
114+
"sort": {
115+
"$ref": "#/components/schemas/Sort"
116+
},
117+
"first": {
118+
"type": "boolean"
119+
},
120+
"last": {
121+
"type": "boolean"
122+
},
123+
"empty": {
124+
"type": "boolean"
125+
}
126+
}
127+
},
128+
"Sort": {
129+
"type": "object",
130+
"properties": {
131+
"sorted": {
132+
"type": "boolean"
133+
},
134+
"unsorted": {
135+
"type": "boolean"
136+
},
137+
"empty": {
138+
"type": "boolean"
139+
}
140+
}
141+
},
142+
"User": {
143+
"type": "object",
144+
"properties": {
145+
"id": {
146+
"type": "integer",
147+
"format": "int64"
148+
},
149+
"firstName": {
150+
"type": "string"
151+
},
152+
"lastName": {
153+
"type": "string"
154+
},
155+
"email": {
156+
"type": "string"
157+
}
158+
}
159+
}
160+
}
161+
}
162+
}

0 commit comments

Comments
 (0)