-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40812 from pcheucle/hide-lra-swagger
Make LRA proxy endpoints optional in OpenAPI
- Loading branch information
Showing
6 changed files
with
156 additions
and
0 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
18 changes: 18 additions & 0 deletions
18
...eployment/src/main/java/io/quarkus/narayana/lra/deployment/LRABuildTimeConfiguration.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.quarkus.narayana.lra.deployment; | ||
|
||
import io.quarkus.runtime.annotations.ConfigItem; | ||
import io.quarkus.runtime.annotations.ConfigPhase; | ||
import io.quarkus.runtime.annotations.ConfigRoot; | ||
|
||
/** | ||
* LRA build time configuration properties | ||
*/ | ||
@ConfigRoot(phase = ConfigPhase.BUILD_TIME) | ||
public final class LRABuildTimeConfiguration { | ||
|
||
/** | ||
* Whether to include LRA proxy endpoints in the generated OpenAPI document | ||
*/ | ||
@ConfigItem(name = "openapi.included", defaultValue = "false") | ||
public boolean openapiIncluded; | ||
} |
48 changes: 48 additions & 0 deletions
48
...deployment/src/main/java/io/quarkus/narayana/lra/deployment/NarayanaLRAOpenAPIFilter.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,48 @@ | ||
package io.quarkus.narayana.lra.deployment; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.eclipse.microprofile.openapi.OASFilter; | ||
import org.eclipse.microprofile.openapi.models.OpenAPI; | ||
import org.eclipse.microprofile.openapi.models.Paths; | ||
|
||
public class NarayanaLRAOpenAPIFilter implements OASFilter { | ||
|
||
final static String LRA_PROXY_PATH = "/lraproxy"; | ||
final static String LRA_PARTICIAPANT_PROXY_PATH = "/lra-participant-proxy"; | ||
final static String LRA_STATUS_SCHEMA = "LRAStatus"; | ||
|
||
boolean openapiIncluded; | ||
|
||
public NarayanaLRAOpenAPIFilter(boolean openapiIncluded) { | ||
this.openapiIncluded = openapiIncluded; | ||
} | ||
|
||
@Override | ||
public void filterOpenAPI(OpenAPI openAPI) { | ||
|
||
Paths paths = openAPI.getPaths(); | ||
|
||
if (!openapiIncluded) { | ||
|
||
Set<String> lraProxyPaths = new HashSet<>(); | ||
|
||
for (String path : paths.getPathItems().keySet()) { | ||
if (path.startsWith(LRA_PROXY_PATH) || path.startsWith(LRA_PARTICIAPANT_PROXY_PATH)) { | ||
lraProxyPaths.add(path); | ||
} | ||
} | ||
|
||
// remove LRA proxy paths from OpenAPI | ||
for (String path : lraProxyPaths) { | ||
paths.removePathItem(path); | ||
} | ||
|
||
// remove LRA schema from OpenAPI | ||
openAPI.getComponents().removeSchema(LRA_STATUS_SCHEMA); | ||
} | ||
|
||
} | ||
|
||
} |
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
...ana-lra/deployment/src/test/java/io/quarkus/narayana/lra/test/LRAOpenAPIExcludedTest.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.quarkus.narayana.lra.test; | ||
|
||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.CoreMatchers.not; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class LRAOpenAPIExcludedTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest().withApplicationRoot((jar) -> jar | ||
.addAsResource(new StringAsset("quarkus.lra.openapi.included=false"), | ||
"application.properties")); | ||
|
||
@Test | ||
public void testLRAExcluded() { | ||
RestAssured.when().get("/q/openapi").then() | ||
.body(not(containsString("lraproxy")), not(containsString("lra-participant-proxy")), | ||
not(containsString("LRAStatus"))); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...ana-lra/deployment/src/test/java/io/quarkus/narayana/lra/test/LRAOpenAPIIncludedTest.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.quarkus.narayana.lra.test; | ||
|
||
import static org.hamcrest.CoreMatchers.containsString; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class LRAOpenAPIIncludedTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest().withApplicationRoot((jar) -> jar | ||
.addAsResource(new StringAsset("quarkus.lra.openapi.included=true"), | ||
"application.properties")); | ||
|
||
@Test | ||
public void testLRAIncluded() { | ||
RestAssured.when().get("/q/openapi").then() | ||
.body(containsString("lraproxy"), containsString("lra-participant-proxy"), containsString("LRAStatus")); | ||
} | ||
} |