ts-rest / ts-rest

RPC-like client, contract, and server implementation for a pure REST API
https://ts-rest.com
MIT License
2.11k stars 91 forks source link

docs: clarify file upload openapi #586

Closed nightspite closed 2 months ago

nightspite commented 2 months ago

I have lost some time looking for a way to extend the schema to handle file upload properly - correct openapi representation was worth more for me than the typed input. In swagger this field is displayed as a file input

https://swagger.io/docs/specification/describing-request-body/file-upload/

CleanShot 2024-04-17 at 13 34 23@2x
changeset-bot[bot] commented 2 months ago

⚠️ No Changeset found

Latest commit: 3436269f8d2ee34687009a58a2f87c498393c183

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

vercel[bot] commented 2 months ago

@nightspite is attempting to deploy a commit to the ts-rest Team on Vercel.

A member of the Team first needs to authorize it.

sonarcloud[bot] commented 2 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Gabrola commented 2 months ago

Unfortunately, this would break the typing for both the client and server, and also fail validation on the server. Maybe this works for you in a specific use-case, but we cannot include this in the official docs.

nightspite commented 2 months ago

How will that fail a validation on the server? Current version in the docs specifies type only, no validation there.

contentType: 'multipart/form-data', // <- Only difference
body: c.type<{ thumbnail: File }>(), // <- Use File type in here

And as far as I remember the multipart content type is not respected in openapi schema.