Skip to content

Commit 6fae772

Browse files
committed
docs: Builder and extra-handlers usage in README
1 parent 6f29b49 commit 6fae772

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ public class YourServerLauncher {
8383
handlers.put("get-data", new GetDataHandler());
8484
handlers.put("post-data", new PostDataHandler());
8585

86-
new OpenApiServer(spec, mapper, handlers, Handlers.defaultExceptionHandler());
86+
var server = OpenApiServer.builder()
87+
.spec(spec)
88+
.jsonMapper(mapper)
89+
.handlers(handlers)
90+
.exceptionHandler(Handlers.defaultExceptionHandler())
91+
.build();
8792
}
8893
}
8994
```
@@ -95,6 +100,35 @@ Map<String, Object> raw = new Yaml().load(Files.newInputStream(Path.of("openapi.
95100
```
96101
The rest is identical.
97102

103+
### Extra (non-OpenAPI) handlers
104+
105+
Mount handlers at arbitrary paths outside the OpenAPI spec — useful for liveness probes,
106+
serving the spec document itself, or any other operational endpoint that should not be subject
107+
to OpenAPI parameter / body validation.
108+
109+
``` java
110+
var server = OpenApiServer.builder()
111+
.spec(spec)
112+
.jsonMapper(mapper)
113+
.handlers(handlers)
114+
.addHandler("/alive", Handlers.aliveHandler())
115+
.addHandler("/schemas/v1/openapi.yaml",
116+
Handlers.specHandler("/schemas/v1/openapi.yaml"))
117+
.build();
118+
```
119+
120+
Extra handlers bypass OpenAPI validation but are still wrapped in the configured
121+
`ExceptionHandler`, so any uncaught exception is rendered using the same error envelope as
122+
API routes.
123+
124+
Built-in helpers:
125+
- `Handlers.aliveHandler()` — 204 No Content on `GET`/`HEAD`, 405 otherwise.
126+
- `Handlers.specHandler(classpathResource)` — serves a classpath resource (content-type
127+
inferred from extension). Throws `IllegalArgumentException` at construction if the resource
128+
is missing.
129+
130+
The original public constructors remain available for back-compat.
131+
98132
## Features
99133
- OpenAPI specification support
100134
- Automatic request body parsing for JSON arrays and objects

0 commit comments

Comments
 (0)