Skip to content

Support Optional Request Body & Optional Content Type #10078

@jorgerangel-msft

Description

@jorgerangel-msft

Consider the following spec : link

Here the request body and the content type header are optional. The content type header should only be added to the request if the request body is not empty. Currently, we generate invalid code that will always add the content type parameter:

if ("application/xml" != null)
{
    request.Headers.SetValue("Content-Type", "application/xml");
}

Instead, we should check if the request content is null, and if not, apply the content type:

if (content != null)
{
    request.Headers.SetValue("Content-Type", "application/xml");
    request.Content = content;
}

Metadata

Metadata

Labels

emitter:client:csharpIssue for the C# client emitter: @typespec/http-client-csharp

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions