-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#18 Allow configuring the filename scanned from the maven artifact
- Loading branch information
Showing
17 changed files
with
315 additions
and
18 deletions.
There are no files selected for viewing
2 changes: 0 additions & 2 deletions
2
swagger-brake-cli/src/main/java/io/redskap/swagger/brake/cli/SwaggerBrakeMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...ke-cli/src/main/java/io/redskap/swagger/brake/cli/options/handler/ApiFilenameHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.redskap.swagger.brake.cli.options.handler; | ||
|
||
import io.redskap.swagger.brake.cli.options.CliOptions; | ||
import io.redskap.swagger.brake.runner.Options; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ApiFilenameHandler implements CliOptionHandler { | ||
@Override | ||
public void handle(String propertyValue, Options options) { | ||
if (StringUtils.isNotBlank(propertyValue)) { | ||
options.setApiFilename(propertyValue); | ||
} | ||
} | ||
|
||
@Override | ||
public String getHandledPropertyName() { | ||
return CliOptions.API_FILENAME; | ||
} | ||
|
||
@Override | ||
public String getHelpMessage() { | ||
return "Specifies the API filename Swagger Brake is going to search for"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
swagger-brake/src/main/java/io/redskap/swagger/brake/maven/jar/ApiFileResolverParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.redskap.swagger.brake.maven.jar; | ||
|
||
import java.io.File; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
@EqualsAndHashCode | ||
public class ApiFileResolverParameter { | ||
private final File apiJar; | ||
private final String configuredApiFilename; | ||
} |
7 changes: 7 additions & 0 deletions
7
...r-brake/src/main/java/io/redskap/swagger/brake/maven/jar/filename/ApiFileNameChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.redskap.swagger.brake.maven.jar.filename; | ||
|
||
import org.springframework.core.Ordered; | ||
|
||
public interface ApiFileNameChecker extends Ordered { | ||
boolean isApiFile(String fileName); | ||
} |
25 changes: 25 additions & 0 deletions
25
...ke/src/main/java/io/redskap/swagger/brake/maven/jar/filename/ApiFileNameCheckerChain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.redskap.swagger.brake.maven.jar.filename; | ||
|
||
import java.util.Collection; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
class ApiFileNameCheckerChain implements ApiFileNameChecker { | ||
private final Collection<ApiFileNameChecker> checkers; | ||
|
||
@Override | ||
public boolean isApiFile(String fileName) { | ||
for (ApiFileNameChecker checker : checkers) { | ||
if (checker.isApiFile(fileName)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int getOrder() { | ||
return 0; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
.../src/main/java/io/redskap/swagger/brake/maven/jar/filename/ApiFilenameCheckerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.redskap.swagger.brake.maven.jar.filename; | ||
|
||
import java.util.Collection; | ||
import java.util.TreeSet; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.core.OrderComparator; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ApiFilenameCheckerFactory { | ||
public ApiFileNameChecker create(String configuredApiFilename) { | ||
Collection<ApiFileNameChecker> checkers = new TreeSet<>(OrderComparator.INSTANCE); | ||
checkers.add(new SwaggerApiFileNameChecker()); | ||
if (StringUtils.isNotBlank(configuredApiFilename)) { | ||
checkers.add(new ConfigurableApiFileNameChecker(configuredApiFilename)); | ||
} | ||
return new ApiFileNameCheckerChain(checkers); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...main/java/io/redskap/swagger/brake/maven/jar/filename/ConfigurableApiFileNameChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.redskap.swagger.brake.maven.jar.filename; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.core.Ordered; | ||
|
||
class ConfigurableApiFileNameChecker implements ApiFileNameChecker { | ||
private final String apiFilename; | ||
|
||
public ConfigurableApiFileNameChecker(String apiFilename) { | ||
if (StringUtils.isBlank(apiFilename)) { | ||
throw new IllegalArgumentException("apiFilename must not be empty"); | ||
} | ||
this.apiFilename = apiFilename; | ||
} | ||
|
||
@Override | ||
public boolean isApiFile(String fileName) { | ||
return fileName.endsWith(apiFilename) | ||
|| fileName.endsWith(apiFilename + ".yaml") | ||
|| fileName.endsWith(apiFilename + ".yml") | ||
|| fileName.endsWith(apiFilename + ".json"); | ||
} | ||
|
||
@Override | ||
public int getOrder() { | ||
return Ordered.HIGHEST_PRECEDENCE; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
.../src/main/java/io/redskap/swagger/brake/maven/jar/filename/SwaggerApiFileNameChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.redskap.swagger.brake.maven.jar.filename; | ||
|
||
import org.springframework.core.Ordered; | ||
|
||
class SwaggerApiFileNameChecker implements ApiFileNameChecker { | ||
@Override | ||
public boolean isApiFile(String fileName) { | ||
return fileName.endsWith("swagger.json") | ||
|| fileName.endsWith("swagger.yml") | ||
|| fileName.endsWith("swagger.yaml"); | ||
} | ||
|
||
@Override | ||
public int getOrder() { | ||
return Ordered.LOWEST_PRECEDENCE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
.../java/io/redskap/swagger/brake/maven/jar/filename/ConfigurableApiFileNameCheckerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package io.redskap.swagger.brake.maven.jar.filename; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.Test; | ||
|
||
public class ConfigurableApiFileNameCheckerTest { | ||
@Test(expected = IllegalArgumentException.class) | ||
public void testConstructorShouldThrowExceptionIfNullParameterIsGiven() { | ||
// given | ||
// when | ||
new ConfigurableApiFileNameChecker(null); | ||
// then exception thrown | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testConstructorShouldThrowExceptionIfEmptyStringParameterIsGiven() { | ||
// given | ||
// when | ||
new ConfigurableApiFileNameChecker(" "); | ||
// then exception thrown | ||
} | ||
|
||
@Test | ||
public void testIsApiShouldReturnFalseWhenDoesntMatch() { | ||
// given | ||
ConfigurableApiFileNameChecker underTest = new ConfigurableApiFileNameChecker("openapi"); | ||
// when | ||
boolean result = underTest.isApiFile("c:/api/swagger.yaml"); | ||
// then | ||
assertThat(result).isFalse(); | ||
} | ||
|
||
@Test | ||
public void testIsApiShouldReturnTrueWhenYamlMatchesFullPath() { | ||
// given | ||
ConfigurableApiFileNameChecker underTest = new ConfigurableApiFileNameChecker("openapi"); | ||
// when | ||
boolean result = underTest.isApiFile("c:/api/openapi.yaml"); | ||
// then | ||
assertThat(result).isTrue(); | ||
} | ||
|
||
@Test | ||
public void testIsApiShouldReturnTrueWhenYamlMatches() { | ||
// given | ||
ConfigurableApiFileNameChecker underTest = new ConfigurableApiFileNameChecker("openapi"); | ||
// when | ||
boolean result = underTest.isApiFile("openapi.yaml"); | ||
// then | ||
assertThat(result).isTrue(); | ||
} | ||
|
||
@Test | ||
public void testIsApiShouldReturnTrueWhenYmlMatches() { | ||
// given | ||
ConfigurableApiFileNameChecker underTest = new ConfigurableApiFileNameChecker("openapi"); | ||
// when | ||
boolean result = underTest.isApiFile("openapi.yml"); | ||
// then | ||
assertThat(result).isTrue(); | ||
} | ||
|
||
@Test | ||
public void testIsApiShouldReturnTrueWhenJsonMatches() { | ||
// given | ||
ConfigurableApiFileNameChecker underTest = new ConfigurableApiFileNameChecker("openapi"); | ||
// when | ||
boolean result = underTest.isApiFile("openapi.json"); | ||
// then | ||
assertThat(result).isTrue(); | ||
} | ||
|
||
@Test | ||
public void testIsApiShouldReturnTrueWhenExtensionIsProvidedAndMatches() { | ||
// given | ||
ConfigurableApiFileNameChecker underTest = new ConfigurableApiFileNameChecker("openapi.txt"); | ||
// when | ||
boolean result = underTest.isApiFile("openapi.txt"); | ||
// then | ||
assertThat(result).isTrue(); | ||
} | ||
} |
Oops, something went wrong.