Skip to content

[http] Slightly stronger types for multipart resolution. #6949

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

Conversation

witemple-msft
Copy link
Member

This PR makes the types returned from @typespec/http for multipart payloads slightly more accurate by splitting the tuple and model forms of multipart bodies into separate types with their own multipartKind and stricter subtypes about what kinds of parts they can have inside them, whether or not they can be named, whether or not they are optional, etc.

The types of the parts are also split into two partKind types: tuple and model. The guarantees given are as follows:

For model-based multipart payloads:

  • type is guaranteed to be a Model.
  • parts are guaranteed to be only model-based parts.

For tuple-based multipart payloads:

  • type is guaranteed to be a Tuple.
  • parts are guaranteed to be only tuple-based parts.

For model-based parts:

  • name is required.
  • property is required and refers to the ModelProperty that defined the part (and we remember to set it -- we weren't doing this correctly).

For tuple-based parts:

  • name is optional.
  • property is guaranteed to be undefined.

Copy link
Contributor

All changed packages have been documented.

  • @typespec/http-client-js
  • @typespec/http
Show changes

@typespec/http - feature ✏️

Improved types for HTTP multipart payloads for more precise guarantees and additional information about the resolution of individual parts.

@typespec/http-client-js - internal ✏️

Changed MultipartTransform slightly to avoid a bizarre TypeScript type checking error.

@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@witemple-msft witemple-msft added this pull request to the merge queue Apr 10, 2025
Merged via the queue into microsoft:main with commit d8db5d7 Apr 10, 2025
22 checks passed
@witemple-msft witemple-msft deleted the witemple-msft/http-multipart-stronger branch April 10, 2025 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants