Improve union support of SchemaMappingInspector
If the union controller method returns Object, as a fallback try the package of the controller. See gh-960
This commit is contained in:
@@ -49,6 +49,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.ReactiveAdapter;
|
||||
import org.springframework.core.ReactiveAdapterRegistry;
|
||||
import org.springframework.core.ResolvableType;
|
||||
@@ -522,6 +523,13 @@ public final class SchemaMappingInspector {
|
||||
int index = clazz.getName().indexOf(clazz.getSimpleName());
|
||||
resolver.addClassPrefix(outputTypeName, clazz.getName().substring(0, index));
|
||||
}
|
||||
else if (fieldEntry.getValue() instanceof SelfDescribingDataFetcher<?> sddf) {
|
||||
if (sddf.getReturnType().getSource() instanceof MethodParameter param) {
|
||||
clazz = param.getDeclaringClass();
|
||||
int index = clazz.getName().indexOf(clazz.getSimpleName());
|
||||
resolver.addClassPrefix(outputTypeName, clazz.getName().substring(0, index));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class SchemaMappingInspectorUnionTests extends SchemaMappingInspectorTest
|
||||
class InterfaceFieldsNotOnJavaInterface {
|
||||
|
||||
@Test
|
||||
void reportUnmappedFields() {
|
||||
void reportUnmappedFieldsByCheckingReturnTypePackage() {
|
||||
SchemaReport report = inspectSchema(schema, SearchController.class);
|
||||
assertThatReport(report)
|
||||
.hasSkippedTypeCount(0)
|
||||
@@ -60,6 +60,16 @@ public class SchemaMappingInspectorUnionTests extends SchemaMappingInspectorTest
|
||||
.containsUnmappedFields("Video", "title");
|
||||
}
|
||||
|
||||
@Test
|
||||
void reportUnmappedFieldsByCheckingControllerTypePackage() {
|
||||
SchemaReport report = inspectSchema(schema, ObjectSearchController.class);
|
||||
assertThatReport(report)
|
||||
.hasSkippedTypeCount(0)
|
||||
.hasUnmappedFieldCount(3)
|
||||
.containsUnmappedFields("Photo", "height", "width")
|
||||
.containsUnmappedFields("Video", "title");
|
||||
}
|
||||
|
||||
|
||||
sealed interface ResultItem permits Photo, Video { }
|
||||
record Photo() implements ResultItem { }
|
||||
@@ -73,6 +83,16 @@ public class SchemaMappingInspectorUnionTests extends SchemaMappingInspectorTest
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Controller
|
||||
static class ObjectSearchController {
|
||||
|
||||
@QueryMapping
|
||||
List<Object> search() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user