diff --git a/README.md b/README.md index 13c3475..72fbea4 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ To stop all liberty servers, issue the command: - Config (auth-service, game-service, player-service) - JWT (auth-service, game-service, player-service) - [Rest Client](#microprofile-rest-client) (game-service) + - [OpenAPI](#microprofile-openapi) (auth-service, game-service, player-service) - Angular 6 (frontend) - Gradle build - [Liberty Gradle Plugin](#liberty-gradle-plugin) @@ -149,6 +150,14 @@ liberty { } ``` +## Microprofile OpenAPI + +Especially while developing new Rest APIs locally, it is useful to inspect the exposed APIs and test them out manually. Simply by enabling the `mpOpenAPI-1.0` feature in server.xml (no application changes needed), all JAX-RS endpoints will be exposed in an interactive web UI. + +Here is a snapshot of what the player-service view looks like: + +![Image of MP OpenAPI web ui](https://user-images.githubusercontent.com/5427967/47033512-a87ef100-d13a-11e8-827d-375e0f1c4cae.png) + ## EE Concurrency Executors from Java SE are very easy to use, and the "Managed" equivalent Executors in EE Concurrency lets you use all of the SE functionality with the added benefit of running the work on threads that are A) managed by the application server and B) have the proper thread context metadata to perform "EE type" operations such as CDI injections and JNDI lookups. diff --git a/auth-service/build.gradle b/auth-service/build.gradle index 7fa5809..dc42b0e 100644 --- a/auth-service/build.gradle +++ b/auth-service/build.gradle @@ -1,7 +1,7 @@ ext { httpPort = 8082 httpsPort = 8482 - appUrl = "http://localhost:${httpPort}/${war.baseName}" + appUrl = "http://localhost:${httpPort}/openapi/ui" } liberty { @@ -19,14 +19,3 @@ dependencies { compile group: 'com.google.api-client', name: 'google-api-client', version: '1.23.0' compile group: 'org.twitter4j', name: 'twitter4j-core', version: '4.0.+' } - - -libertyStart.doLast { - println "Application available at: ${appUrl}" -} - -task open { - doLast { - java.awt.Desktop.desktop.browse "${appUrl}/token".toURI() - } -} diff --git a/auth-service/src/main/java/org/libertybikes/auth/service/github/GitHubOAuthAPI.java b/auth-service/src/main/java/org/libertybikes/auth/service/github/GitHubOAuthAPI.java index a941c2e..a6ea4ed 100644 --- a/auth-service/src/main/java/org/libertybikes/auth/service/github/GitHubOAuthAPI.java +++ b/auth-service/src/main/java/org/libertybikes/auth/service/github/GitHubOAuthAPI.java @@ -8,6 +8,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import org.eclipse.microprofile.openapi.annotations.Operation; import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; @RegisterRestClient @@ -15,14 +16,13 @@ import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; public interface GitHubOAuthAPI { public static class GithubTokenResponse { - @NotNull public String access_token; } @GET @Path("/access_token") @Produces(MediaType.APPLICATION_JSON) - @Valid // TODO: beanval isn't being honored here when used with MP Rest client + @Operation(hidden = true) // hide operation from OpenAPI public GithubTokenResponse accessToken(@QueryParam("client_id") String key, @QueryParam("client_secret") String secret, @QueryParam("code") String code, diff --git a/auth-service/src/main/java/org/libertybikes/auth/service/github/GitHubUserAPI.java b/auth-service/src/main/java/org/libertybikes/auth/service/github/GitHubUserAPI.java index 96fae34..b4bd128 100644 --- a/auth-service/src/main/java/org/libertybikes/auth/service/github/GitHubUserAPI.java +++ b/auth-service/src/main/java/org/libertybikes/auth/service/github/GitHubUserAPI.java @@ -8,6 +8,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import org.eclipse.microprofile.openapi.annotations.Operation; import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; @RegisterRestClient @@ -15,7 +16,6 @@ import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; public interface GitHubUserAPI { public static class EmailData { - @Email public String email; public boolean primary; } @@ -23,7 +23,7 @@ public interface GitHubUserAPI { @GET @Path("/emails") @Produces(MediaType.APPLICATION_JSON) - @Valid // TODO: beanval isn't being called here when rest client instance is injected + @Operation(hidden = true) // hide operation from OpenAPI public EmailData[] getEmail(@QueryParam("access_token") String accessToken); } diff --git a/auth-service/src/main/liberty/config/server.xml b/auth-service/src/main/liberty/config/server.xml index 489637e..8412ca6 100644 --- a/auth-service/src/main/liberty/config/server.xml +++ b/auth-service/src/main/liberty/config/server.xml @@ -9,6 +9,7 @@ mpConfig-1.2 mpJwt-1.0 mpRestClient-1.0 + mpOpenAPI-1.0 diff --git a/build.gradle b/build.gradle index 73e6c5d..4ae53b0 100644 --- a/build.gradle +++ b/build.gradle @@ -67,4 +67,14 @@ subprojects { task debug { dependsOn 'libertyDebug' } task start { dependsOn 'libertyStart' } task stop { dependsOn 'libertyStop' } + + libertyStart.doLast { + println "Application available at: ${appUrl}" + } + + task open { + doLast { + java.awt.Desktop.desktop.browse "${appUrl}".toURI() + } + } } diff --git a/frontend/build.gradle b/frontend/build.gradle index 51603cf..fff4672 100644 --- a/frontend/build.gradle +++ b/frontend/build.gradle @@ -19,6 +19,7 @@ ext { httpPort = 12000 httpsPort = 12005 applicationName = "${war.archiveName}" + appUrl = "http://localhost:${httpPort}/" } war { @@ -85,13 +86,3 @@ liberty { configDirectory = file('src/main/liberty/config') } } - -libertyStart.doLast { - println "Application available at: http://localhost:${httpPort}/" -} - -task open { - doLast { - java.awt.Desktop.desktop.browse "http://localhost:${httpPort}/".toURI() - } -} diff --git a/game-service/build.gradle b/game-service/build.gradle index 2866f4c..a8103cd 100644 --- a/game-service/build.gradle +++ b/game-service/build.gradle @@ -6,6 +6,7 @@ dependencies { ext { httpPort = 8080 httpsPort = 8443 + appUrl = "http://localhost:${httpPort}/openapi/ui" } liberty { @@ -18,8 +19,3 @@ liberty { '-DsingleParty=' + System.getProperty('singleParty', 'false')] } } - - -libertyStart.doLast { - println "Application available at: http://localhost:${httpPort}/" -} diff --git a/game-service/src/main/java/org/libertybikes/restclient/PlayerService.java b/game-service/src/main/java/org/libertybikes/restclient/PlayerService.java index 3f8035d..8a49ef1 100644 --- a/game-service/src/main/java/org/libertybikes/restclient/PlayerService.java +++ b/game-service/src/main/java/org/libertybikes/restclient/PlayerService.java @@ -10,6 +10,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import org.eclipse.microprofile.openapi.annotations.Operation; import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; @Dependent @@ -20,10 +21,12 @@ public interface PlayerService { @GET @Path("/player/{playerId}") @Produces(MediaType.APPLICATION_JSON) + @Operation(hidden = true) // hide operation from OpenAPI public Player getPlayerById(@PathParam("playerId") String id); @POST @Path("/rank/{playerId}/recordGame") + @Operation(hidden = true) // hide operation from OpenAPI public void recordGame(@PathParam("playerId") String id, @QueryParam("place") int place, @HeaderParam("Authorization") String token); } diff --git a/game-service/src/main/liberty/config/server.xml b/game-service/src/main/liberty/config/server.xml index ab26b90..cd6e0f0 100644 --- a/game-service/src/main/liberty/config/server.xml +++ b/game-service/src/main/liberty/config/server.xml @@ -9,6 +9,7 @@ mpConfig-1.2 mpRestClient-1.0 mpJwt-1.0 + mpOpenAPI-1.0 websocket-1.1 diff --git a/player-service/build.gradle b/player-service/build.gradle index ecef51a..1b9a8f2 100644 --- a/player-service/build.gradle +++ b/player-service/build.gradle @@ -1,6 +1,7 @@ ext { httpPort = 8081 httpsPort = 8444 + appUrl = "http://localhost:${httpPort}/openapi/ui" } liberty { @@ -12,15 +13,6 @@ liberty { } } -libertyStart.doLast { - println "Application available at: http://localhost:${httpPort}/${project.name}" -} dependencies { compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.0' } - -task open { - doLast { - java.awt.Desktop.desktop.browse "http://localhost:${httpPort}/${project.name}".toURI() - } -} diff --git a/player-service/src/main/liberty/config/server.xml b/player-service/src/main/liberty/config/server.xml index 089d608..dec1d02 100644 --- a/player-service/src/main/liberty/config/server.xml +++ b/player-service/src/main/liberty/config/server.xml @@ -8,6 +8,7 @@ jsonb-1.0 mpConfig-1.2 mpJwt-1.0 + mpOpenAPI-1.0