@@ -119,15 +119,17 @@ const OPENAPI_CONN_TOKEN = z.string().openapi({
119119 description : "Connection token" ,
120120} ) ;
121121
122- function buildOpenApiResponses < T > ( schema : T ) {
122+ function buildOpenApiResponses < T > ( schema : T , validateBody : boolean ) {
123123 return {
124124 200 : {
125125 description : "Success" ,
126- content : {
127- "application/json" : {
128- schema,
129- } ,
130- } ,
126+ content : validateBody
127+ ? {
128+ "application/json" : {
129+ schema,
130+ } ,
131+ }
132+ : { } ,
131133 } ,
132134 400 : {
133135 description : "User error" ,
@@ -138,11 +140,19 @@ function buildOpenApiResponses<T>(schema: T) {
138140 } ;
139141}
140142
143+ /**
144+ * Only use `validateBody` to `true` if you need to export OpenAPI JSON.
145+ *
146+ * If left enabled for production, this will cause errors. We disable JSON validation since:
147+ * - It prevents us from proxying requests, since validating the body requires consuming the body so we can't forward the body
148+ * - We validate all types at the actor router layer since most requests are proxied
149+ */
141150export function createManagerRouter (
142151 registryConfig : RegistryConfig ,
143152 runConfig : RunConfig ,
144153 inlineClientDriver : ClientDriver ,
145154 managerDriver : ManagerDriver ,
155+ validateBody : boolean ,
146156) : { router : Hono ; openapi : OpenAPIHono } {
147157 const router = new OpenAPIHono ( { strict : false } ) . basePath (
148158 runConfig . basePath ,
@@ -259,17 +269,19 @@ export function createManagerRouter(
259269 path : "/actors/resolve" ,
260270 request : {
261271 body : {
262- content : {
263- "application/json" : {
264- schema : ResolveQuerySchema ,
265- } ,
266- } ,
272+ content : validateBody
273+ ? {
274+ "application/json" : {
275+ schema : ResolveQuerySchema ,
276+ } ,
277+ }
278+ : { } ,
267279 } ,
268280 headers : z . object ( {
269281 [ HEADER_ACTOR_QUERY ] : OPENAPI_ACTOR_QUERY ,
270282 } ) ,
271283 } ,
272- responses : buildOpenApiResponses ( ResolveResponseSchema ) ,
284+ responses : buildOpenApiResponses ( ResolveResponseSchema , validateBody ) ,
273285 } ) ;
274286
275287 router . openapi ( resolveRoute , ( c ) =>
@@ -374,18 +386,20 @@ export function createManagerRouter(
374386 request : {
375387 params : ActionParamsSchema ,
376388 body : {
377- content : {
378- "application/json" : {
379- schema : ActionRequestSchema ,
380- } ,
381- } ,
389+ content : validateBody
390+ ? {
391+ "application/json" : {
392+ schema : ActionRequestSchema ,
393+ } ,
394+ }
395+ : { } ,
382396 } ,
383397 headers : z . object ( {
384398 [ HEADER_ENCODING ] : OPENAPI_ENCODING ,
385399 [ HEADER_CONN_PARAMS ] : OPENAPI_CONN_PARAMS . optional ( ) ,
386400 } ) ,
387401 } ,
388- responses : buildOpenApiResponses ( ActionResponseSchema ) ,
402+ responses : buildOpenApiResponses ( ActionResponseSchema , validateBody ) ,
389403 } ) ;
390404
391405 router . openapi ( actionRoute , ( c ) =>
@@ -412,11 +426,13 @@ export function createManagerRouter(
412426 path : "/actors/message" ,
413427 request : {
414428 body : {
415- content : {
416- "application/json" : {
417- schema : ConnectionMessageRequestSchema ,
418- } ,
419- } ,
429+ content : validateBody
430+ ? {
431+ "application/json" : {
432+ schema : ConnectionMessageRequestSchema ,
433+ } ,
434+ }
435+ : { } ,
420436 } ,
421437 headers : z . object ( {
422438 [ HEADER_ACTOR_ID ] : OPENAPI_ACTOR_ID ,
@@ -425,7 +441,10 @@ export function createManagerRouter(
425441 [ HEADER_CONN_TOKEN ] : OPENAPI_CONN_TOKEN ,
426442 } ) ,
427443 } ,
428- responses : buildOpenApiResponses ( ConnectionMessageResponseSchema ) ,
444+ responses : buildOpenApiResponses (
445+ ConnectionMessageResponseSchema ,
446+ validateBody ,
447+ ) ,
429448 } ) ;
430449
431450 router . openapi ( messageRoute , ( c ) =>
@@ -768,20 +787,11 @@ export function createManagerRouter(
768787 } ) ;
769788 }
770789
771- router . doc ( "/openapi.json" , {
772- openapi : "3.0.0" ,
773- info : {
774- version : VERSION ,
775- title : "RivetKit API" ,
776- } ,
777- } ) ;
778-
779790 managerDriver . modifyManagerRouter ?.(
780791 registryConfig ,
781792 router as unknown as Hono ,
782793 ) ;
783794
784-
785795 // Mount on both / and /registry
786796 //
787797 // We do this because the default requests are to `/registry/*`.
0 commit comments