Skip to content
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

Adds check to consider the required flag on multipart forms in the C# Code generator #5023

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/NSwag.CodeGeneration.CSharp.Tests/BinaryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public async Task When_multipart_with_ref_should_read_schema()
var code = codeGenerator.GenerateFile();

//// Assert
Assert.Contains("public virtual async System.Threading.Tasks.Task<CreateAddFileResponse> AddFileAsync(FileParameter file, Model? model, System.Threading.CancellationToken cancellationToken)", code);
Assert.Contains("public virtual async System.Threading.Tasks.Task<CreateAddFileResponse> AddFileAsync(FileParameter file, Model model, System.Threading.CancellationToken cancellationToken)", code);
Assert.Contains("var content_file_ = new System.Net.Http.StreamContent(file.Data);", code);
Assert.Contains("public partial class FileParameter", code);
}
Expand Down Expand Up @@ -504,7 +504,7 @@ public async Task When_multipart_inline_schema()
var code = codeGenerator.GenerateFile();

//// Assert
Assert.Contains("public virtual async System.Threading.Tasks.Task<CreateAddFileResponse> AddFileAsync(FileParameter file, Model? model, System.Threading.CancellationToken cancellationToken)", code);
Assert.Contains("public virtual async System.Threading.Tasks.Task<CreateAddFileResponse> AddFileAsync(FileParameter file, Model model, System.Threading.CancellationToken cancellationToken)", code);
Assert.Contains("var content_file_ = new System.Net.Http.StreamContent(file.Data);", code);
Assert.Contains("public partial class FileParameter", code);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
content_.Headers.Remove("Content-Type");
content_.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=" + boundary_);
{% for parameter in operation.FormParameters %}
{% if parameter.IsNullable -%}
{% if parameter.IsNullable or parameter.IsOptional -%}
if ({{ parameter.VariableName }} != null)
{% else -%}
if ({{ parameter.VariableName }} == null)
Expand Down
3 changes: 2 additions & 1 deletion src/NSwag.CodeGeneration/Models/OperationModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ protected IList<OpenApiParameter> GetActualParameters()
OpenApiParameterCollectionFormat.Multi : OpenApiParameterCollectionFormat.Undefined,
//Explode = p.Value.Type.HasFlag(JsonObjectType.Array) && p.Value.Item != null,
//Schema = p.Value.Type.HasFlag(JsonObjectType.Array) && p.Value.Item != null ? p.Value.Item : p.Value,
Position = parameters.Count + 100 + i
Position = parameters.Count + 100 + i,
IsRequired = p.Value.IsRequired
})).ToList();
}

Expand Down
Loading