Skip to content

Commit

Permalink
fix: revert revert of fileforge hack
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity committed May 9, 2024
1 parent 06c61b7 commit 7a4ac22
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/ui/app/src/api-playground/PlaygroundEndpoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export const PlaygroundEndpoint: FC<PlaygroundEndpointProps> = ({
resetWithoutExample,
types,
}): ReactElement => {
const { basePath } = useDocsContext();
const { basePath, domain } = useDocsContext();
const [response, setResponse] = useState<Loadable<PlaygroundResponse>>(notStartedLoading());
// const [, startTransition] = useTransition();

Expand All @@ -192,7 +192,7 @@ export const PlaygroundEndpoint: FC<PlaygroundEndpointProps> = ({
url: buildEndpointUrl(endpoint, formState),
method: endpoint.method,
headers: buildUnredactedHeaders(endpoint, formState),
body: await serializeFormStateBody(endpoint.requestBody[0]?.shape, formState.body, basePath),
body: await serializeFormStateBody(endpoint.requestBody[0]?.shape, formState.body, basePath, domain),
};
if (endpoint.responseBody?.shape.type === "stream") {
const [res, stream] = await executeProxyStream(req, basePath);
Expand Down Expand Up @@ -289,6 +289,7 @@ async function serializeFormStateBody(
shape: ResolvedHttpRequestBodyShape | undefined,
body: PlaygroundFormStateBody | undefined,
basePath: string | undefined,
domain: string,
): Promise<ProxyRequest.SerializableBody | undefined> {
if (shape == null || body == null || shape.type !== "formData") {
return undefined;
Expand Down Expand Up @@ -335,7 +336,10 @@ async function serializeFormStateBody(
assertNever(value);
}
}
return { type: "form-data", value: formDataValue };
// this is a hack to allow the API Playground to send JSON blobs in form data
// revert this once we have a better solution
const isJsonBlob = domain.includes("fileforge");
return { type: "form-data", value: formDataValue, isJsonBlob };
}
case "octet-stream":
return { type: "octet-stream", value: await serializeFile(body.value, basePath) };
Expand Down
1 change: 1 addition & 0 deletions packages/ui/app/src/api-playground/types/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export declare namespace ProxyRequest {
export interface SerializableFormData {
type: "form-data";
value: Record<string, SerializableFormDataEntryValue>;
isJsonBlob?: boolean; // this is a hack to allow the API Playground to send JSON blobs in form data
}

export interface SerializableOctetStream {
Expand Down
5 changes: 5 additions & 0 deletions packages/ui/docs-bundle/src/pages/api/fern-docs/proxy/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ export async function buildRequestBody(body: ProxyRequest.SerializableBody | und
{ type: value.contentType },
),
] as const;
} else if (body.isJsonBlob) {
return [
key,
new Blob([JSON.stringify(value.value)], { type: value.contentType }),
] as const;
}
return [key, JSON.stringify(value.value)] as const;
}
Expand Down

0 comments on commit 7a4ac22

Please sign in to comment.