Only attempt parameter resolution in a test method context
Previously, RestDocumenationExtension would attempt parameter resolution for any use RestDocumentationContextProvider. Due to the provider being method-scoped, this could lead to a NullPointerException when it was resolved in the context of a class. This commit updates RestDocumentationExtension so that it only supports parameter resolution for RestDocumentationContextProvider in the context of a test method. Closes gh-538
This commit is contained in:
@@ -47,8 +47,11 @@ public class RestDocumentationExtension
|
||||
@Override
|
||||
public boolean supportsParameter(ParameterContext parameterContext,
|
||||
ExtensionContext extensionContext) {
|
||||
return RestDocumentationContextProvider.class
|
||||
.isAssignableFrom(parameterContext.getParameter().getType());
|
||||
if (isTestMethodContext(extensionContext)) {
|
||||
return RestDocumentationContextProvider.class
|
||||
.isAssignableFrom(parameterContext.getParameter().getType());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,6 +61,10 @@ public class RestDocumentationExtension
|
||||
.beforeOperation();
|
||||
}
|
||||
|
||||
private boolean isTestMethodContext(ExtensionContext context) {
|
||||
return context.getTestClass().isPresent() && context.getTestMethod().isPresent();
|
||||
}
|
||||
|
||||
private ManualRestDocumentation getDelegate(ExtensionContext context) {
|
||||
Namespace namespace = Namespace.create(getClass(), context.getUniqueId());
|
||||
return context.getStore(namespace).getOrComputeIfAbsent(
|
||||
|
||||
Reference in New Issue
Block a user