Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
d5a3e31
docs: Design spec for multiple OpenAPI specs per server
thced May 22, 2026
901c783
docs: Implementation plan for multiple OpenAPI specs per server
thced May 22, 2026
a73b4c3
refactor: Add SpecBinding record for per-spec server state
thced May 22, 2026
2bbf9be
docs: Check off Task 1 completion in plan
thced May 22, 2026
edce6b0
refactor: Drive OpenApiServer from a list of SpecBinding
thced May 22, 2026
e1a5790
style: Use imported List name in OpenApiServer constructor
thced May 22, 2026
c789467
test: Add SpecFixtures helper to derive multiple specs from one fixture
thced May 22, 2026
b6ad61c
style: Drop unneeded SuppressWarnings on deepClone
thced May 22, 2026
cdd7b0d
docs: Mark Task 3 steps complete in plan
thced May 22, 2026
243c578
feat: Add addSpec() builder method for multi-spec servers
thced May 22, 2026
cf8152d
refactor: Strengthen multi-spec validation messages and tests
thced May 22, 2026
6ef0d94
test: Cover multi-spec namespacing, conflicts, and mixed builder forms
thced May 22, 2026
9bda1a6
test: Integration test for multi-spec server under real HttpServer
thced May 22, 2026
0a0e2c7
docs: Document addSpec() for multi-spec servers
thced May 22, 2026
10251a8
chore: Check off Task 11 in multi-spec plan
thced May 22, 2026
fd83072
test: Prove multi-spec loading from directory and JAR classpath
thced May 22, 2026
8b29ab0
refactor: Extract helpers in OpenApiServer to reduce cognitive comple…
thced May 22, 2026
966827e
refactor: Hoist builder setup out of assertThatThrownBy lambdas
thced May 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ endpoints declared in an OpenAPI 3.1.x specification. Handlers are pure function
- [Highlights](#highlights)
- [Maven artifact](#maven-artifact)
- [Quick start](#quick-start)
- [Multiple specs](#multiple-specs)
- [Spec loading](#spec-loading)
- [JSON mapping](#json-mapping)
- [Body parsers and response writers](#body-parsers-and-response-writers)
Expand Down Expand Up @@ -160,6 +161,46 @@ public class YourServerLauncher {
}
```

### Multiple specs

A single server instance can host more than one OpenAPI spec — useful for running a v1/v2 API
side-by-side, or a public and an internal admin surface in the same process. Each `addSpec()` call
registers one spec and its handlers as an independent binding. The JDK `HttpServer` routes
incoming requests to the binding whose `basePath` (the path component of `servers[0].url`) best
matches the request URI.

`operationId`s and security-scheme names only need to be unique _within_ a single spec — two
specs can each declare a `getCustomer` operation without conflict.

``` java
OpenApiServer server = OpenApiServer.builder()
.port(8080)
.addSpec(v1Spec, Map.of(
"getCustomer", new V1GetCustomer(),
"listCustomers", new V1ListCustomers()))
.addSpec(v2Spec, Map.of(
"getCustomer", new V2GetCustomer(),
"listCustomers", new V2ListCustomers(),
"createCustomer", new V2CreateCustomer()))
.build();
```

Each spec that declares `securitySchemes` gets its own validator map via the three-argument
overload:

``` java
OpenApiServer.builder()
.port(8080)
.addSpec(v1Spec, v1Handlers, Map.of(
"bearerAuth", (req, cred) -> jwt.verify(((BearerCredential) cred).token())))
.addSpec(v2Spec, v2Handlers, Map.of(
"apiKeyAuth", (req, cred) -> apiKeyStore.lookup(((ApiKeyCredential) cred).value())))
.build();
```

Mixing `addSpec()` with the legacy `spec()`/`handlers()`/`securityValidator()` methods in the
same builder call is rejected at build time with `IllegalStateException`.

## Spec loading

`Spec.fromClasspath(Class<?>, String)` is the recommended way to load a spec packaged with your
Expand Down
Loading
Loading