File tree Expand file tree Collapse file tree
main/java/com/retailsvc/http
test/java/com/retailsvc/http Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -364,8 +364,8 @@ to OpenAPI parameter / body validation.
364364var server = OpenApiServer . builder()
365365 .spec(spec)
366366 .handlers(handlers)
367- .addHandler (" /alive" , Handlers . aliveHandler())
368- .addHandler (" /schemas/v1/openapi.yaml" ,
367+ .extraRoute (" /alive" , Handlers . aliveHandler())
368+ .extraRoute (" /schemas/v1/openapi.yaml" ,
369369 Handlers . specHandler(" /schemas/v1/openapi.yaml" ))
370370 .build();
371371```
Original file line number Diff line number Diff line change @@ -197,11 +197,17 @@ public Builder shutdownTimeoutSeconds(int shutdownTimeoutSeconds) {
197197 return this ;
198198 }
199199
200- public Builder addHandler (String path , HttpHandler handler ) {
200+ /**
201+ * Registers an extra HTTP route at {@code path} that bypasses OpenAPI validation and routing.
202+ * Use for side concerns like {@code /alive}, {@code /health}, or serving the spec itself —
203+ * anything that isn't an OpenAPI {@code operationId}. For OpenAPI-described operations use
204+ * {@link #handlers(Map)}.
205+ */
206+ public Builder extraRoute (String path , HttpHandler handler ) {
201207 requireNonNull (path , "path must not be null" );
202208 requireNonNull (handler , "handler must not be null" );
203209 if (extras .containsKey (path )) {
204- throw new IllegalStateException ("duplicate extra handler path: " + path );
210+ throw new IllegalStateException ("duplicate extra route path: " + path );
205211 }
206212 extras .put (path , handler );
207213 return this ;
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ void aliveExtraReturns204AndBypassesValidation() throws Exception {
1919 .handlers (Map .of ())
2020 .exceptionHandler (defaultExceptionHandler ())
2121 .port (0 )
22- .addHandler ("/alive" , Handlers .aliveHandler ())
22+ .extraRoute ("/alive" , Handlers .aliveHandler ())
2323 .build ();
2424 var client = httpClient ()) {
2525
@@ -43,7 +43,7 @@ void specHandlerServesClasspathResource() throws Exception {
4343 .handlers (Map .of ())
4444 .exceptionHandler (defaultExceptionHandler ())
4545 .port (0 )
46- .addHandler ("/openapi.yaml" , Handlers .specHandler ("/openapi.yaml" ))
46+ .extraRoute ("/openapi.yaml" , Handlers .specHandler ("/openapi.yaml" ))
4747 .build ();
4848 var client = httpClient ()) {
4949
@@ -73,7 +73,7 @@ void extraHandlerExceptionFlowsThroughExceptionHandler() throws Exception {
7373 .handlers (Map .of ())
7474 .exceptionHandler (defaultExceptionHandler ())
7575 .port (0 )
76- .addHandler ("/boom" , boom )
76+ .extraRoute ("/boom" , boom )
7777 .build ();
7878 var client = httpClient ()) {
7979
Original file line number Diff line number Diff line change @@ -28,9 +28,9 @@ void buildsWithRequiredFieldsOnly() {
2828 void rejectsDuplicateExtraPathOnSecondAddHandler () {
2929 HttpHandler duplicate = Handlers .aliveHandler ();
3030 OpenApiServer .Builder b =
31- OpenApiServer .builder ().spec (spec ).handlers (emptyMap ()).addHandler ("/alive" , duplicate );
31+ OpenApiServer .builder ().spec (spec ).handlers (emptyMap ()).extraRoute ("/alive" , duplicate );
3232
33- assertThatThrownBy (() -> b .addHandler ("/alive" , duplicate ))
33+ assertThatThrownBy (() -> b .extraRoute ("/alive" , duplicate ))
3434 .isInstanceOf (IllegalStateException .class )
3535 .hasMessageContaining ("/alive" );
3636 }
@@ -42,7 +42,7 @@ void rejectsExtraPathEqualToSpecBasePathAtBuildTime() {
4242 OpenApiServer .builder ()
4343 .spec (spec )
4444 .handlers (emptyMap ())
45- .addHandler ("/api" , Handlers .aliveHandler ())
45+ .extraRoute ("/api" , Handlers .aliveHandler ())
4646 .port (0 );
4747
4848 assertThatThrownBy (b ::build )
You can’t perform that action at this time.
0 commit comments