Skip to content

Commit 6fb52dc

Browse files
committed
2 parents 77bb755 + 11a343a commit 6fb52dc

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

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

+8-6
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,13 @@ public Operation customize(Operation operation, HandlerMethod handlerMethod) {
116116
fieldsToAdd.addAll(aliases);
117117
fieldsToAdd.addAll(whiteList);
118118

119-
boolean excludeUnlistedProperties = getFieldValueOfBoolean(bindings, "excludeUnlistedProperties");
119+
// if only listed properties should be included, remove all other fields from fieldsToAdd
120+
if (getFieldValueOfBoolean(bindings, "excludeUnlistedProperties")) {
121+
fieldsToAdd.removeIf(s -> !whiteList.contains(s));
122+
}
120123

121124
for (String fieldName : fieldsToAdd) {
122-
Type type = getFieldType(fieldName, pathSpecMap, predicate.root(), excludeUnlistedProperties);
125+
Type type = getFieldType(fieldName, pathSpecMap, predicate.root());
123126
if (type != null) {
124127
Parameter newParameter = buildParam(type, fieldName);
125128
parametersToAddToOperation.add(newParameter);
@@ -232,19 +235,18 @@ private Optional<Path<?>> getPathFromPathSpec(Object instance) {
232235
* Tries to figure out the Type of the field. It first checks the Qdsl pathSpecMap before checking the root class. Defaults to String.class
233236
* @param fieldName The name of the field used as reference to get the type
234237
* @param pathSpecMap The Qdsl path specifications as defined in the resolved bindings
235-
* @param root The root type where the paths are gotten
236-
* @param excludeUnlistedProperties the exclude unlisted properties
238+
* @param root The root type where the paths are gotten
237239
* @return The type of the field. Returns
238240
*/
239-
private Type getFieldType(String fieldName, Map<String, Object> pathSpecMap, Class<?> root, boolean excludeUnlistedProperties) {
241+
private Type getFieldType(String fieldName, Map<String, Object> pathSpecMap, Class<?> root) {
240242
Type genericType = null;
241243
try {
242244
Object pathAndBinding = pathSpecMap.get(fieldName);
243245
Optional<Path<?>> path = getPathFromPathSpec(pathAndBinding);
244246
Field declaredField;
245247
if (path.isPresent()) {
246248
genericType = path.get().getType();
247-
} else if (!excludeUnlistedProperties) {
249+
} else {
248250
declaredField = root.getDeclaredField(fieldName);
249251
genericType = declaredField.getGenericType();
250252
}

springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app19/ApplicationPredicate.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public class ApplicationPredicate implements QuerydslBinderCustomizer<QApplicati
1111
public void customize(QuerydslBindings bindings, QApplication root) {
1212
bindings.excludeUnlistedProperties(true);
1313
bindings.bind(root.name).first(StringExpression::containsIgnoreCase);
14+
bindings.including(root.icon);
15+
bindings.including(root.name);
1416
}
1517

16-
}
18+
}

springdoc-openapi-data-rest/src/test/resources/results/app19.json

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
"schema": {
3333
"type": "string"
3434
}
35+
},
36+
{
37+
"name": "icon",
38+
"in": "query",
39+
"schema": {
40+
"type": "string"
41+
}
3542
}
3643
],
3744
"responses": {

0 commit comments

Comments
 (0)