Skip to content

MPFD Generated Proposal#6415

Draft
jorgerangel-msft wants to merge 19 commits intomicrosoft:mainfrom
jorgerangel-msft:mpfd-pet-design-doc
Draft

MPFD Generated Proposal#6415
jorgerangel-msft wants to merge 19 commits intomicrosoft:mainfrom
jorgerangel-msft:mpfd-pet-design-doc

Conversation

@jorgerangel-msft
Copy link
Copy Markdown
Contributor

No description provided.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Mar 12, 2025
@github-actions
Copy link
Copy Markdown
Contributor

No changes needing a change description found.

@jorgerangel-msft jorgerangel-msft changed the title [WIP]: MPFD Design MPFD Generated Proposal Mar 17, 2025
Comment thread packages/http-client-csharp/generator/docs/mpfd-design.md Outdated
Comment thread packages/http-client-csharp/generator/docs/mpfd-design.md
@microsoft-github-policy-service microsoft-github-policy-service Bot added the stale Mark a PR that hasn't been recently updated and will be closed. label May 1, 2025
@jorgerangel-msft jorgerangel-msft removed the stale Mark a PR that hasn't been recently updated and will be closed. label May 9, 2025
Comment thread packages/http-client-csharp/generator/docs/mpfd-design.md Outdated
Comment thread packages/http-client-csharp/generator/docs/mpfd-design.md Outdated
Comment thread packages/http-client-csharp/generator/docs/mpfd-design.md
Comment thread packages/http-client-csharp/generator/docs/mpfd-design.md Outdated
Comment thread packages/http-client-csharp/generator/docs/mpfd-design.md Outdated
{
public MultiPartFormDataBinaryContent() { }
public MultiPartFormDataBinaryContent(string boundary) { }
public void Add(string name, System.BinaryData content, string? mediaType = null) { }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if there is a conflict between the BinaryData.MediaType property and the mediaType parameter?

Copy link
Copy Markdown
Contributor Author

@jorgerangel-msft jorgerangel-msft Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point that I didn't consider. We could just default to the mediaType of the BinaryData content, unless it's explicitly overwritten by the mediaType parameter in this method.

edit: actually, since the overload that takes in FileBinaryContent doesn't specify mediaType as a parameter I'm leaning towards just removing mediaType from this method as well and have the mediaType parsed from the BinaryData instance.

Comment thread packages/http-client-csharp/generator/docs/mpfd-design.md Outdated
Comment thread packages/http-client-csharp/generator/docs/mpfd-design.md Outdated
Comment thread packages/http-client-csharp/generator/docs/mpfd-design.md Outdated
Comment thread packages/http-client-csharp/generator/docs/mpfd-design.md Outdated
public MultiPartFormContent() { }
public MultiPartFormContent(string boundary) { }
public void Add(string name, System.BinaryData content) { }
public void Add(string name, bool content, string? mediaType = "text/plain") { }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is text/plain the right default for bools? should all the default media types be JSON? except for the byte[] one

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KrzysztofCwalina hmm, the rfc guidelines recommend defaulting to text/plain and both swagger and typespec follow this default handling for the parts. With that being said, could you help me understand why we should default to JSON? It makes sense to me for complex values.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does it mean to write bool as text? what do we write? the english word "true"/"false", 0 or 1? Same with numbers and other data types? what is the text representation of double 1000.29? is it "1,000.29" or "1000,29"? these are both textual representations of the number in different locales.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KrzysztofCwalina - ah I see what you're saying. I think the missing implementation detail here is that with the exception of byte[] and BinaryData parts, StringContent is being used to serialize the part. So a "bool" part is being serialized as "true" / "false". The implementation is very similar to the one used in OAI which I used as a baseline.

With that being said, if you think we should always default to json, I can look into how that implementation would look.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jorgerangel-msft, can you point me to code showing how StringContent is used to "serialize" bools and numbers. I dont think StringCOntent has any APIs to serialize bools/numbers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KrzysztofCwalina - no you're right it doesn't. In the implementation for this type, bools + numbers are converted to a string and then StringContent is used similar to https://github.com/openai/openai-dotnet/blob/main/src/Generated/Internal/MultiPartFormDataBinaryContent.cs#L100

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, mydecimal.ToString("G", CultureInfo.InvariantCulture) is unlikely to be the right thing. Sending numbers in some .NET specific format (e.g. "G") over the wire is probably not very useful as the server would have to know about this unwritten "protocol".

BTW, do we really have scenarios where the part content is just one number or boolean? If yes, what are those?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KrzysztofCwalina - I see. I will default to json for the parts then and look into changing the implementation.

I haven't ran into scenarios where a part is a single bool / number. It's supported by tsp, so I added it as an overload since this will be consumed by the generator. Though I'm also fine with removing them from this type for now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Let's go with JSON and separately you might want to chat with the typespec team about the scenarios. I really wonder if there are any for sending a single bool, int, etc. as a form part

@microsoft-github-policy-service microsoft-github-policy-service Bot added the stale Mark a PR that hasn't been recently updated and will be closed. label Sep 1, 2025
@jorgerangel-msft jorgerangel-msft removed the stale Mark a PR that hasn't been recently updated and will be closed. label Sep 2, 2025
@microsoft-github-policy-service microsoft-github-policy-service Bot added the stale Mark a PR that hasn't been recently updated and will be closed. label Oct 3, 2025
@jorgerangel-msft jorgerangel-msft removed the stale Mark a PR that hasn't been recently updated and will be closed. label Oct 3, 2025
@microsoft-github-policy-service microsoft-github-policy-service Bot added the stale Mark a PR that hasn't been recently updated and will be closed. label Nov 2, 2025
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 5, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@6415

commit: 28b8c5c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp stale Mark a PR that hasn't been recently updated and will be closed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants