Skip to content

Commit

Permalink
#107: Include version number in filename for file based reportings
Browse files Browse the repository at this point in the history
  • Loading branch information
galovics committed Sep 29, 2023
1 parent f10f0b6 commit b8a190d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public void report(Collection<BreakingChange> breakingChanges, Options options,
String json = toFileContent(breakingChanges, apiInfo);
try {
directoryCreator.create(options.getOutputFilePath());
String filePath = options.getOutputFilePath() + File.separator + getFilename();
String filePath = options.getOutputFilePath() + File.separator + getFilename(apiInfo);
fileWriter.write(filePath, json);
log.info("Report can be found at {}", filePath);
} catch (Exception e) {
throw new RuntimeException("An exception occurred while writing the report file", e);
}
}

protected abstract String getFilename();
protected abstract String getFilename(ApiInfo apiInfo);

protected abstract String toFileContent(Collection<BreakingChange> breakingChanges, ApiInfo apiInfo);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.redskap.swagger.brake.report;

import static org.apache.commons.lang3.StringUtils.isNotBlank;

import io.redskap.swagger.brake.core.ApiInfo;
import io.redskap.swagger.brake.core.BreakingChange;
import io.redskap.swagger.brake.report.file.DirectoryCreator;
Expand All @@ -21,7 +23,8 @@
@Component
@Slf4j
class HtmlReporter extends AbstractFileReporter implements CheckableReporter {
private static final String FILENAME = "swagger-brake.html";
private static final String DEFAULT_FILENAME = "swagger-brake.html";
private static final String VERSIONED_FILENAME_TEMPLATE = "swagger-brake-%s.html";
private final JsonConverter jsonConverter;
private final MustacheContentResolver mustacheContentResolver;

Expand All @@ -32,8 +35,12 @@ public HtmlReporter(FileWriter fileWriter, DirectoryCreator directoryCreator, Js
}

@Override
protected String getFilename() {
return FILENAME;
protected String getFilename(ApiInfo apiInfo) {
String result = DEFAULT_FILENAME;
if (apiInfo != null && isNotBlank(apiInfo.getVersion())) {
result = VERSIONED_FILENAME_TEMPLATE.formatted(apiInfo.getVersion());
}
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.redskap.swagger.brake.report;

import static java.util.stream.Collectors.groupingBy;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

import io.redskap.swagger.brake.core.ApiInfo;
import io.redskap.swagger.brake.core.BreakingChange;
Expand All @@ -19,7 +20,8 @@
@Slf4j
@Component
class JsonReporter extends AbstractFileReporter implements CheckableReporter {
private static final String FILENAME = "swagger-brake.json";
private static final String DEFAULT_FILENAME = "swagger-brake.json";
private static final String VERSIONED_FILENAME_TEMPLATE = "swagger-brake-%s.json";
private final JsonConverter jsonConverter;

public JsonReporter(FileWriter fileWriter, DirectoryCreator directoryCreator, JsonConverter jsonConverter) {
Expand All @@ -28,8 +30,12 @@ public JsonReporter(FileWriter fileWriter, DirectoryCreator directoryCreator, Js
}

@Override
protected String getFilename() {
return FILENAME;
protected String getFilename(ApiInfo apiInfo) {
String result = DEFAULT_FILENAME;
if (apiInfo != null && isNotBlank(apiInfo.getVersion())) {
result = VERSIONED_FILENAME_TEMPLATE.formatted(apiInfo.getVersion());
}
return result;
}

@Override
Expand Down

0 comments on commit b8a190d

Please sign in to comment.