Skip to content

Commit a73b4c3

Browse files
committed
refactor: Add SpecBinding record for per-spec server state
1 parent 901c783 commit a73b4c3

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.retailsvc.http.internal;
2+
3+
import com.retailsvc.http.RequestHandler;
4+
import com.retailsvc.http.SchemeValidator;
5+
import com.retailsvc.http.spec.Spec;
6+
import com.retailsvc.http.validate.DefaultValidator;
7+
import java.util.Map;
8+
9+
/**
10+
* Bundles everything the server needs to serve one OpenAPI spec: the spec itself, the handler map
11+
* keyed by {@code operationId}, the security-scheme validator map, and the derived {@link Router}
12+
* and {@link DefaultValidator}. One {@code SpecBinding} drives exactly one {@code HttpContext}.
13+
*/
14+
public record SpecBinding(
15+
Spec spec,
16+
Map<String, RequestHandler> handlers,
17+
Map<String, SchemeValidator> securityValidators,
18+
DefaultValidator validator,
19+
Router router) {
20+
21+
public SpecBinding {
22+
handlers = Map.copyOf(handlers);
23+
securityValidators = Map.copyOf(securityValidators);
24+
}
25+
26+
/** Builds a binding by deriving the {@link Router} and {@link DefaultValidator} from the spec. */
27+
public static SpecBinding of(
28+
Spec spec,
29+
Map<String, RequestHandler> handlers,
30+
Map<String, SchemeValidator> securityValidators) {
31+
return new SpecBinding(
32+
spec,
33+
handlers,
34+
securityValidators,
35+
new DefaultValidator(spec::resolveSchema),
36+
new Router(spec.operations()));
37+
}
38+
}

0 commit comments

Comments
 (0)