@@ -3,6 +3,8 @@ import { compact, flatten } from "es-toolkit/array";
3
3
import {
4
4
FormDataField ,
5
5
HttpRequestBodyShape ,
6
+ Protocol ,
7
+ wrapOpenRPCRequest ,
6
8
} from "@fern-api/fdr-sdk/api-definition" ;
7
9
import { assertNever , isNonNullish } from "@fern-api/ui-core-utils" ;
8
10
@@ -14,18 +16,32 @@ import {
14
16
SerializableFormDataEntryValue ,
15
17
} from "../types" ;
16
18
17
- export async function serializeFormStateBody (
18
- shape : HttpRequestBodyShape | undefined ,
19
- body : PlaygroundFormStateBody | undefined ,
20
- usesApplicationJsonInFormDataValue : boolean
21
- ) : Promise < ProxyRequest . SerializableBody | undefined > {
19
+ export const serializeFormStateBody = async ( {
20
+ shape,
21
+ body,
22
+ usesApplicationJsonInFormDataValue,
23
+ protocol,
24
+ } : {
25
+ shape : HttpRequestBodyShape | undefined ;
26
+ body : PlaygroundFormStateBody | undefined ;
27
+ usesApplicationJsonInFormDataValue : boolean ;
28
+ protocol ?: Protocol ;
29
+ } ) : Promise < ProxyRequest . SerializableBody | undefined > => {
22
30
if ( shape == null || body == null ) {
23
31
return undefined ;
24
32
}
25
33
26
34
switch ( body . type ) {
27
- case "json" :
35
+ case "json" : {
36
+ if ( protocol ?. type === "openrpc" ) {
37
+ // Wrap the request body in OpenRPC format
38
+ return {
39
+ type : "json" ,
40
+ value : wrapOpenRPCRequest ( body . value , protocol . methodName ) ,
41
+ } ;
42
+ }
28
43
return { type : "json" , value : body . value } ;
44
+ }
29
45
case "form-data" : {
30
46
const formDataValue : Record < string , SerializableFormDataEntryValue > = { } ;
31
47
for ( const [ key , value ] of Object . entries ( body . value ) ) {
@@ -109,7 +125,7 @@ export async function serializeFormStateBody(
109
125
default :
110
126
assertNever ( body ) ;
111
127
}
112
- }
128
+ } ;
113
129
114
130
async function serializeFile (
115
131
file : File | undefined
0 commit comments