Replace placeholders in snippet name as well as the operation name
Previously, StandardWriterResolver only replaced placeholders in the operation name. This meant that the name and location of generated snippets was unnecessarily limited. This commit makes things more flexible by updating StandardWriterResolver to replace placeholders in the snippet name as well. Closes gh-403
This commit is contained in:
@@ -82,11 +82,12 @@ public final class StandardWriterResolver implements WriterResolver {
|
||||
@Override
|
||||
public Writer resolve(String operationName, String snippetName,
|
||||
RestDocumentationContext context) throws IOException {
|
||||
File outputFile = resolveFile(
|
||||
this.propertyPlaceholderHelper.replacePlaceholders(operationName,
|
||||
this.placeholderResolverFactory.create(context)),
|
||||
snippetName + "." + this.templateFormat.getFileExtension(), context);
|
||||
|
||||
PlaceholderResolver placeholderResolver = this.placeholderResolverFactory
|
||||
.create(context);
|
||||
String outputDirectory = replacePlaceholders(placeholderResolver, operationName);
|
||||
String fileName = replacePlaceholders(placeholderResolver, snippetName) + "."
|
||||
+ this.templateFormat.getFileExtension();
|
||||
File outputFile = resolveFile(outputDirectory, fileName, context);
|
||||
if (outputFile != null) {
|
||||
createDirectoriesIfNecessary(outputFile);
|
||||
return new OutputStreamWriter(new FileOutputStream(outputFile),
|
||||
@@ -103,6 +104,10 @@ public final class StandardWriterResolver implements WriterResolver {
|
||||
this.encoding = encoding;
|
||||
}
|
||||
|
||||
private String replacePlaceholders(PlaceholderResolver resolver, String input) {
|
||||
return this.propertyPlaceholderHelper.replacePlaceholders(input, resolver);
|
||||
}
|
||||
|
||||
File resolveFile(String outputDirectory, String fileName,
|
||||
RestDocumentationContext context) {
|
||||
File outputFile = new File(outputDirectory, fileName);
|
||||
|
||||
Reference in New Issue
Block a user