|
32 | 32 | */
|
33 | 33 | public class RestDocumentationExtension implements BeforeEachCallback, AfterEachCallback, ParameterResolver {
|
34 | 34 |
|
| 35 | + private final String outputDirectory; |
| 36 | + |
| 37 | + /** |
| 38 | + * Creates a new {@code RestDocumentationExtension} that will use the default output |
| 39 | + * directory. |
| 40 | + */ |
| 41 | + public RestDocumentationExtension() { |
| 42 | + this(null); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Creates a new {@code RestDocumentationExtension} that will use the given |
| 47 | + * {@code outputDirectory}. |
| 48 | + * @param outputDirectory snippet output directory |
| 49 | + * @since 2.0.4 |
| 50 | + */ |
| 51 | + public RestDocumentationExtension(String outputDirectory) { |
| 52 | + this.outputDirectory = outputDirectory; |
| 53 | + } |
| 54 | + |
35 | 55 | @Override
|
36 | 56 | public void beforeEach(ExtensionContext context) throws Exception {
|
37 | 57 | this.getDelegate(context).beforeTest(context.getRequiredTestClass(), context.getRequiredTestMethod().getName());
|
@@ -62,7 +82,16 @@ private boolean isTestMethodContext(ExtensionContext context) {
|
62 | 82 | private ManualRestDocumentation getDelegate(ExtensionContext context) {
|
63 | 83 | Namespace namespace = Namespace.create(getClass(), context.getUniqueId());
|
64 | 84 | return context.getStore(namespace).getOrComputeIfAbsent(ManualRestDocumentation.class,
|
65 |
| - (key) -> new ManualRestDocumentation(), ManualRestDocumentation.class); |
| 85 | + this::createManualRestDocumentation, ManualRestDocumentation.class); |
| 86 | + } |
| 87 | + |
| 88 | + private ManualRestDocumentation createManualRestDocumentation(Class<ManualRestDocumentation> key) { |
| 89 | + if (this.outputDirectory != null) { |
| 90 | + return new ManualRestDocumentation(this.outputDirectory); |
| 91 | + } |
| 92 | + else { |
| 93 | + return new ManualRestDocumentation(); |
| 94 | + } |
66 | 95 | }
|
67 | 96 |
|
68 | 97 | }
|
0 commit comments