Skip to content

Commit cf8152d

Browse files
committed
refactor: Strengthen multi-spec validation messages and tests
1 parent 243c578 commit cf8152d

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

src/main/java/com/retailsvc/http/OpenApiServer.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ public Builder extraRoute(String path, RequestHandler handler) {
384384
}
385385

386386
public OpenApiServer build() throws IOException {
387-
boolean usedLegacy = spec != null || handlers != null;
387+
boolean usedLegacy = spec != null || handlers != null || !securityValidators.isEmpty();
388388
boolean usedAddSpec = !bindings.isEmpty();
389389
if (usedLegacy && usedAddSpec) {
390390
throw new IllegalStateException(
@@ -425,7 +425,11 @@ public OpenApiServer build() throws IOException {
425425
for (String path : extras.keySet()) {
426426
if (seenBasePaths.containsKey(path)) {
427427
throw new IllegalStateException(
428-
"extra handler path " + path + " conflicts with spec basePath " + path);
428+
"extra handler path '"
429+
+ path
430+
+ "' conflicts with basePath of spec '"
431+
+ seenBasePaths.get(path)
432+
+ "'");
429433
}
430434
}
431435

src/test/java/com/retailsvc/http/MultiSpecServerTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ void servesTwoBindingsOnDistinctBasePaths() throws Exception {
3232
.build()) {
3333

3434
int port = server.listenPort();
35-
assertThat(get("http://localhost:" + port + "/api/v1/data").statusCode()).isEqualTo(HTTP_OK);
36-
assertThat(get("http://localhost:" + port + "/api/v2/data").statusCode()).isEqualTo(HTTP_OK);
35+
HttpResponse<String> v1Resp = get("http://localhost:" + port + "/api/v1/data");
36+
HttpResponse<String> v2Resp = get("http://localhost:" + port + "/api/v2/data");
37+
assertThat(v1Resp.statusCode()).isEqualTo(HTTP_OK);
38+
assertThat(v1Resp.body()).contains("v1");
39+
assertThat(v2Resp.statusCode()).isEqualTo(HTTP_OK);
40+
assertThat(v2Resp.body()).contains("v2");
3741
}
3842
}
3943

0 commit comments

Comments
 (0)