Skip to content

Commit 3b82de6

Browse files
committed
huge refactoring to add context-path "/api-impl-demo" instead of "/".
1 parent 4416176 commit 3b82de6

File tree

10 files changed

+48
-33
lines changed

10 files changed

+48
-33
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>fr.fxjavadevblog</groupId>
66
<artifactId>api-impl-demo</artifactId>
7-
<version>0.0.7-SNAPSHOT</version>
7+
<version>0.0.8-SNAPSHOT</version>
88
<name>API Implementation Demo</name>
99

1010
<properties>
@@ -15,7 +15,7 @@
1515

1616
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
1717
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
18-
<quarkus.platform.version>1.12.1.Final</quarkus.platform.version>
18+
<quarkus.platform.version>1.12.2.Final</quarkus.platform.version>
1919
<quarkus-plugin.version>${quarkus.platform.version}</quarkus-plugin.version>
2020
<lombok.version>1.18.14</lombok.version>
2121
<commons-lang.version>3.11</commons-lang.version>

src/main/java/fr/fxjavadevblog/aid/api/videogame/VideoGameResource.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@
6262

6363
// JAX-RS + OpenAPI annotations
6464

65-
@Path("/video-games")
65+
66+
@Path(VideoGameResource.PATH)
6667
@Tag(name="Videogames", description = "Videogame collection")
6768
@Produces({MediaType.APPLICATION_JSON, SpecificMediaType.APPLICATION_YAML})
6869
@Slf4j
6970
public class VideoGameResource
7071
{
72+
public static final String PATH = "/video-games";
7173
private static final String VIDEOGAME_ARG = "videogame";
7274
@Inject
7375
VideoGameRepository videoGameRepository;

src/main/java/fr/fxjavadevblog/aid/health/ApplicationHealthCheck.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ public HealthCheck firstApiCheck()
3030
return () -> HealthCheckResponse.named(ApplicationConfig.APP_NAME + " health check")
3131
.up()
3232
.withData("app_name", ApplicationConfig.APP_NAME)
33+
.withData("app_tile", ApplicationConfig.APP_TITLE)
3334
.withData("app_version", ApplicationConfig.APP_VERSION)
3435
.withData("api_version", ApplicationConfig.API_VERSION)
35-
.withData("api_base_uri", ApplicationConfig.API_VERSIONED_BASE_PATH)
36+
.withData("api_full_path", ApplicationConfig.API_FULL_PATH)
3637
.withData("started_at", ISO_8601_EXTENDED_DATETIME_FORMAT.format(chrono.getStartTime()))
3738
.withData("uptime", chrono.toString())
3839
.build();

src/main/java/fr/fxjavadevblog/aid/metadata/ApplicationConfig.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
// this definition is merged with resources/META-INF/openapi.yml
2020

2121
@OpenAPIDefinition (
22-
info = @Info(title = ApplicationConfig.APP_NAME, version = ApplicationConfig.APP_VERSION),
23-
servers = @Server(url = ApplicationConfig.APPLICATION_ROOT_VERSIONED ),
22+
info = @Info(title = ApplicationConfig.APP_TITLE, version = ApplicationConfig.APP_VERSION),
23+
servers = @Server(url = ApplicationConfig.API_FULL_PATH ),
2424
components = @Components(
2525
responses = {
2626
@APIResponse(name = ApplicationConfig.RESPONSE_API_ERROR,
@@ -38,22 +38,23 @@
3838
)
3939

4040

41-
@ApplicationPath(ApplicationConfig.API_VERSIONED_BASE_PATH)
41+
@ApplicationPath(ApplicationConfig.API_VERSIONED_PATH)
4242

4343
public class ApplicationConfig extends Application {
4444

4545
// these constants are used by OpenApi definition and by the response of /health
4646

47-
public static final String PATH_DELIM = "/";
4847

49-
public static final String APP_NAME = "API for Atari ST Floppy Catalog";
50-
public static final String APP_VERSION = "0.0.7";
51-
public static final String API_BASE_PATH = "api";
52-
public static final String API_VERSION = "v1";
53-
public static final String API_VERSIONED_BASE_PATH = PATH_DELIM + API_VERSION + PATH_DELIM + API_BASE_PATH ;
48+
public static final String APP_NAME = "api-impl-demo";
49+
public static final String APP_TITLE = "API for Atari ST Floppy Catalog";
50+
public static final String APP_VERSION = "0.0.8";
5451

55-
public static final String APPLICATION_ROOT_VERSIONED = PATH_DELIM + API_VERSION;
52+
public static final String ROOT_PATH = "/" + APP_NAME;
5653

54+
public static final String API_VERSION = "v1";
55+
public static final String API_ENDPOINT_BASEPATH = "api";
56+
public static final String API_VERSIONED_PATH = "/" + API_VERSION + "/" + API_ENDPOINT_BASEPATH;
57+
public static final String API_FULL_PATH = ROOT_PATH + API_VERSIONED_PATH;
5758

5859

5960
// aliases for OpenApi references via "ref=" annotation attribute.

src/main/java/fr/fxjavadevblog/aid/utils/openapi/OpenApiFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void filterOpenAPI(OpenAPI openAPI) {
3737
for(Entry <String, PathItem> entry : map.entrySet())
3838
{
3939
String jaxRsPath = entry.getKey();
40-
String openApiPath = StringUtils.remove(jaxRsPath, ApplicationConfig.APPLICATION_ROOT_VERSIONED);
40+
String openApiPath = StringUtils.remove(jaxRsPath,ApplicationConfig.API_FULL_PATH);
4141
log.info("JAX-RS Path : {} converted to OpenAPI Path : {}", jaxRsPath, openApiPath);
4242
newMap.put(openApiPath, entry.getValue());
4343
}

src/main/resources/META-INF/openapi.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ tags:
2020

2121
paths:
2222
/health:
23+
servers:
24+
- url: /api-impl-demo/v1
25+
description: Override base path for all operations with the /health path
2326
get:
2427
tags:
2528
- Health and Metrics
@@ -38,6 +41,9 @@ paths:
3841
description: There is no monitored API at this address.
3942

4043
/metrics:
44+
servers:
45+
- url: /api-impl-demo/v1
46+
description: Override base path for all operations with the /metrics path
4147
get:
4248
tags:
4349
- Health and Metrics

src/main/resources/META-INF/resources/index.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
<style>
77
@font-face {
88
font-family: 'atari';
9-
src: url('/fonts/atari-st.eot');
10-
src: url('/fonts/atari-st.eot?#iefix') format('embedded-opentype'),
11-
url('/fonts/atari-st.woff2') format('woff2'),
12-
url('/fonts/atari-st.woff') format('woff'), url('/fonts/atari-st.ttf')
13-
format('truetype');
9+
src: url('./fonts/atari-st.eot');
10+
src: url('./fonts/atari-st.eot?#iefix') format('embedded-opentype'),
11+
url('./fonts/atari-st.woff2') format('woff2'),
12+
url('./fonts/atari-st.woff') format('woff'),
13+
url('./fonts/atari-st.ttf') format('truetype');
1414
font-weight: normal;
1515
font-style: normal;
1616
}
@@ -23,18 +23,18 @@
2323
</head>
2424
<body>
2525
<h1>API for Atari ST Floppy Catalog</h1>
26-
<img src="/images/floppy-resized.png" alt="floppy disk 3'1/2" />
26+
<img src="./images/floppy-resized.png" alt="floppy disk 3'1/2" />
2727
<p>Welcome to the landing page of the demo API.</p>
2828
<p>The goal of this application is to demonstrate REST API best pratices.</p>
2929
<p>This project runs thanks to Quarkus framework and the source code is hosted here : <a href="https://github.com/fxrobin/api-impl-demo">https://github.com/fxrobin/api-impl-demo</a>.</p>
3030
<hr />
3131
<p>Just go these links :
3232
<ul>
33-
<li>OpenAPI UI : <a href="/openapi-ui">/openapi-ui</a>, direct link to the <a href="/v1/openapi">yaml file</a></li>
34-
<li>Watch the <a href="/health-ui">/health</a> or get the <a href="/v1/health">JSON response</a>. </li>
35-
<li>Look at the <a href="/v1/metrics">/metrics</a> of the API.</li>
33+
<li>OpenAPI UI : <a href="./openapi-ui">/openapi-ui</a>, direct link to the <a href="./v1/openapi">yaml file</a></li>
34+
<li>Watch the <a href="./health-ui">/health</a> or get the <a href="./v1/health">JSON response</a>. </li>
35+
<li>Look at the <a href="./v1/metrics">/metrics</a> of the API.</li>
3636
</ul>
3737
<p><strong>Enjoy.</strong></p>
38-
<img src="/images/busy-bee.png" alt="Atari ST busy bee" />
38+
<img src="./images/busy-bee.png" alt="Atari ST busy bee" />
3939
</body>
4040
</html>

src/main/resources/application.properties

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ quarkus.banner.path=banner.txt
33

44
#listening on all interfaces
55
quarkus.http.host=0.0.0.0
6+
quarkus.http.root-path=/api-impl-demo
7+
quarkus.http.non-application-root-path=/api-impl-demo
68

79
# CDI
810
quarkus.arc.remove-unused-beans=false
@@ -14,14 +16,14 @@ quarkus.log.category."fr.fxjavadevblog.qjg".level=INFO
1416

1517

1618
# health & metrics
17-
quarkus.smallrye-health.root-path=/v1/health
18-
quarkus.smallrye-metrics.path=/v1/metrics
19+
quarkus.smallrye-health.root-path=v1/health
20+
quarkus.smallrye-metrics.path=v1/metrics
1921
quarkus.smallrye-health.ui.always-include=true
2022

2123

2224
# OpenAPI
23-
quarkus.smallrye-openapi.path=/v1/openapi
24-
quarkus.swagger-ui.path=/openapi-ui
25+
quarkus.smallrye-openapi.path=v1/openapi
26+
quarkus.swagger-ui.path=openapi-ui
2527
quarkus.swagger-ui.always-include=true
2628
quarkus.swagger-ui.operations-sorter=function (a, b) { var order = { "get": "0", "post": "1", "put": "2", "delete": "3" }; return order[a.method].localeCompare(order[b.method]); }
2729
quarkus.swagger-ui.validator-url=none

src/test/java/fr/fxjavadevblog/aid/api/videogame/VideoGameHttpTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.junit.jupiter.api.Test;
99

1010
import fr.fxjavadevblog.aid.global.TestApplicationConfig;
11+
import fr.fxjavadevblog.aid.metadata.ApplicationConfig;
1112
import io.quarkus.test.common.http.TestHTTPEndpoint;
1213
import io.quarkus.test.junit.QuarkusTest;
1314
import io.restassured.specification.RequestSpecification;
@@ -20,14 +21,16 @@
2021
*/
2122

2223
@QuarkusTest
23-
@TestHTTPEndpoint(VideoGameResource.class)
24+
25+
2426
class VideoGameHttpTest
2527
{
2628

2729
private RequestSpecification prepareTest()
2830
{
2931
return given()
30-
.baseUri(TestApplicationConfig.REST_ASSURED_FULL_BASE_URI)
32+
.baseUri(TestApplicationConfig.REST_ASSURED_HTTP_BASE)
33+
.basePath(ApplicationConfig.API_FULL_PATH + VideoGameResource.PATH)
3134
.log().uri()
3235
.when();
3336
}

src/test/java/fr/fxjavadevblog/aid/global/TestApplicationConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public class TestApplicationConfig {
1717
public static final String REST_ASSURED_HTTP_BASE = "http://localhost:8081";
1818

1919
/**
20-
* full URL to baseApi. Ex: http://localhost:8081/api/v1
20+
* full URL to baseApi. Ex: http://localhost:8081/api-impl-demo/v1/api
2121
*/
22-
public static final String REST_ASSURED_FULL_BASE_URI = REST_ASSURED_HTTP_BASE + ApplicationConfig.API_VERSIONED_BASE_PATH;
22+
public static final String REST_ASSURED_FULL_BASE_URI = REST_ASSURED_HTTP_BASE + ApplicationConfig.API_FULL_PATH;
2323

2424
}

0 commit comments

Comments
 (0)