oazapfts / oazapfts

Generate TypeScript clients to tap into OpenAPI servers
493 stars 78 forks source link

feature request: support `multipart/form-data` responses #471

Open eric-carlsson opened 1 year ago

eric-carlsson commented 1 year ago

multipart/form-data is currently not supported as a response type, and operations that have this response type will instead default to blob. This can be converted to formData without data loss, but it's ugly:

  const res = await handle(getPet(petID), {
    200: (pet) => pet
  });

  const contentType = res.headers.get('Content-Type') as string;

  const r = new Response(res.data as unknown as FormData, {
    headers: { 'Content-Type': contentType }
  });

  const formData = await r.formData();

  const d = Object.fromEntries(formData.entries()) as unknown as Pet;

The Responses API supports directly parsing the body as FormData, so there's really no reason to not support it.

eric-carlsson commented 1 year ago

This should be fairly straight forward to implement, so I can give it a shot. Expect a PR shortly.

Xiphe commented 1 year ago

Cool! Looking forward to that 👍