-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#17 Add ability to allow removal of deprecated APIs: added parameter …
…to switch deprecated API handling
- Loading branch information
Showing
18 changed files
with
270 additions
and
9 deletions.
There are no files selected for viewing
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
27 changes: 27 additions & 0 deletions
27
...ava/io/redskap/swagger/brake/cli/options/handler/DeprecatedApiDeletionAllowedHandler.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,27 @@ | ||
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.BooleanUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class DeprecatedApiDeletionAllowedHandler implements CliOptionHandler { | ||
@Override | ||
public void handle(String propertyValue, Options options) { | ||
if (StringUtils.isNotBlank(propertyValue)) { | ||
options.setDeprecatedApiDeletionAllowed(BooleanUtils.toBooleanObject(propertyValue)); | ||
} | ||
} | ||
|
||
@Override | ||
public String getHandledPropertyName() { | ||
return CliOptions.DEPRECATED_API_DELETION_ALLOWED; | ||
} | ||
|
||
@Override | ||
public String getHelpMessage() { | ||
return "Whether to allow the deletion of deprecated APIs. Defaults to true."; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...io/redskap/swagger/brake/cli/options/handler/DeprecatedApiDeletionAllowedHandlerTest.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,65 @@ | ||
package io.redskap.swagger.brake.cli.options.handler; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.redskap.swagger.brake.runner.Options; | ||
import org.junit.Test; | ||
|
||
public class DeprecatedApiDeletionAllowedHandlerTest { | ||
private DeprecatedApiDeletionAllowedHandler underTest = new DeprecatedApiDeletionAllowedHandler(); | ||
|
||
@Test | ||
public void testHandleShouldGiveTrueValueForTheOptionWhenNullValueGiven() { | ||
// given | ||
Options options = new Options(); | ||
|
||
// when | ||
underTest.handle(null, options); | ||
// then | ||
assertThat(options.getDeprecatedApiDeletionAllowed()).isNull(); | ||
} | ||
|
||
@Test | ||
public void testHandleShouldGiveTrueValueForTheOptionWhenEmptyValueGiven() { | ||
// given | ||
Options options = new Options(); | ||
|
||
// when | ||
underTest.handle("", options); | ||
// then | ||
assertThat(options.getDeprecatedApiDeletionAllowed()).isNull(); | ||
} | ||
|
||
@Test | ||
public void testHandleShouldGiveTrueValueForTheOptionWhenTrueValueGiven() { | ||
// given | ||
Options options = new Options(); | ||
|
||
// when | ||
underTest.handle("true", options); | ||
// then | ||
assertThat(options.getDeprecatedApiDeletionAllowed()).isTrue(); | ||
} | ||
|
||
@Test | ||
public void testHandleShouldGiveTrueValueForTheOptionWhenRandomValueGiven() { | ||
// given | ||
Options options = new Options(); | ||
|
||
// when | ||
underTest.handle("asd", options); | ||
// then | ||
assertThat(options.getDeprecatedApiDeletionAllowed()).isNull(); | ||
} | ||
|
||
@Test | ||
public void testHandleShouldGiveFalseValueForTheOptionWhenFalseValueGiven() { | ||
// given | ||
Options options = new Options(); | ||
|
||
// when | ||
underTest.handle("false", options); | ||
// then | ||
assertThat(options.getDeprecatedApiDeletionAllowed()).isFalse(); | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
swagger-brake/src/main/java/io/redskap/swagger/brake/core/CheckerOptions.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,8 @@ | ||
package io.redskap.swagger.brake.core; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class CheckerOptions { | ||
private boolean deprecatedApiDeletionAllowed = true; | ||
} |
24 changes: 24 additions & 0 deletions
24
swagger-brake/src/main/java/io/redskap/swagger/brake/core/CheckerOptionsProvider.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,24 @@ | ||
package io.redskap.swagger.brake.core; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class CheckerOptionsProvider { | ||
private CheckerOptions checkerOptions; | ||
|
||
void set(CheckerOptions options) { | ||
if (options == null) { | ||
throw new IllegalArgumentException("options cannot be null"); | ||
} | ||
checkerOptions = options; | ||
} | ||
|
||
|
||
public CheckerOptions get() { | ||
if (checkerOptions == null) { | ||
throw new RuntimeException("CheckerOptions has not been set up yet."); | ||
} | ||
return checkerOptions; | ||
} | ||
|
||
} |
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
18 changes: 18 additions & 0 deletions
18
swagger-brake/src/main/java/io/redskap/swagger/brake/runner/CheckerOptionsFactory.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,18 @@ | ||
package io.redskap.swagger.brake.runner; | ||
|
||
import io.redskap.swagger.brake.core.CheckerOptions; | ||
import org.apache.commons.lang3.BooleanUtils; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class CheckerOptionsFactory { | ||
public CheckerOptions create(Options options) { | ||
CheckerOptions checkerOptions = new CheckerOptions(); | ||
checkerOptions.setDeprecatedApiDeletionAllowed(isDeprecatedApiDeletionAllowed(options)); | ||
return checkerOptions; | ||
} | ||
|
||
private boolean isDeprecatedApiDeletionAllowed(Options options) { | ||
return BooleanUtils.toBooleanDefaultIfNull(options.getDeprecatedApiDeletionAllowed(), true); | ||
} | ||
} |
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
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
Oops, something went wrong.