Skip to content

return more accurate type information for non-json requests #2094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task
hesxenon opened this issue Jan 8, 2025 · 1 comment
Closed
1 task

return more accurate type information for non-json requests #2094

hesxenon opened this issue Jan 8, 2025 · 1 comment
Assignees
Labels
enhancement New feature or request openapi-ts Relevant to the openapi-typescript library

Comments

@hesxenon
Copy link

hesxenon commented Jan 8, 2025

Description

Similar to #1123 - which has been closed because of the ability to handle this in openapi-fetch as I read it? - I'd like to be able to actually have the request typed properly.

Proposal

E.g. for

requestBody:
  content:
    multipart/form-data:
      schema:
        type: object
        properties:
          image_file:
            type: string
            format: binary

I'd like a generated type like

{image_file: File}

Sorry if I missed a point from the mentioned issue that explains why this would not be preferable in openapi-typescript itself. From my POV it seems like the issue has been closed prematurely as afaik it's not possible to have the correct types without openapi-fetch?

Extra

@hesxenon hesxenon added enhancement New feature or request openapi-ts Relevant to the openapi-typescript library labels Jan 8, 2025
@drwpow drwpow self-assigned this Jan 25, 2025
@drwpow
Copy link
Contributor

drwpow commented Jan 25, 2025

So yeah there are 2 parts here: for openapi-fetch and #1123 we’re limited in what we can do because of the design goal / design curse we originally had of using only generics. So that means openapi-fetch really has no clue what any of your schema is at runtime. We can try and guess based on request, etc., but even if your type was File that wouldn’t change openapi-fetch’s handling of requests unless you overrode it.

We’re looking to revisit a lot of these papercuts in 1.0, because they’re all valid! And we’re hearing a lot of great input (yours included) that people would like a little runtime awareness in openapi-fetch. At least a little more than exists currently.

But for your question about openapi-typescript, we do have the transformer API that’s meant expressly for your usecase. We don’t want to assume you want File because some may want Buffer, some may want Blob, etc. Also depending on whether you’re generating types for the client or server you’ll want different things as well. We’re not open to changing the default behavior at this time.

Note that we’re considering adding a config file in an upcoming, because using the transform API requires you run it in a Node.js script, which can be a bit of a hassle. But regardless, that’s exactly what you need!

@drwpow drwpow closed this as completed Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request openapi-ts Relevant to the openapi-typescript library
Projects
None yet
Development

No branches or pull requests

2 participants