Skip to content

[Bug Bounty] Fix a bug related to binary response in csharp-netcore client #8524

@DeniskaAbr

Description

@DeniskaAbr

I am generate APIClient With "-g csharp-netcore --additional-properties=targetFramework=netstandard2.1,netCoreProjectFile=true" parameters.

OpenApi specification contains
"responses": { "200": { "description": "Success", "content": { "image/jpeg": { "schema": { "type": "string", "format": "binary" } } } },

In backend server endpoint:

public async Task<IActionResult> GetAvatar() { var result = await _service.GetAvatar(); if (result == null) return NoContent(); var (content, contentType) = result.Value; return File(content, contentType); }

public async Task<(byte[], string)?> GetAvatar() { var user = await _userManager.GetUserAsync(_claims); var profile = user.Profile; var avatar = profile.Avatar; var content = Convert.FromBase64String(avatar.File.Content); var contentType = avatar.File.ContentType; return (content, contentType); }

After fetch data from server with _apiService.ProfileApi.ApiProfileGetAvatarGet() in request no Data. In Client request is transformed as
изображение
изображение

How to use generator? Need byte[] or Stream byte[] in request. And uploading for upload binary files in multipart/form-data? In 91 row in generator is contains code for checking datatype https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/csharp-netcore/ApiClient.mustache

Why is there an attempt to deserialize what am I doing wrong?

My sponsorship for this request is 50$

UPDATED: Also not work fetch multiple type data from response. Generator supported ASP.NET Core ProblemDetails?

Example (see StatusCodes.Status400BadRequest):

HttpPatch]
[Route("[action]")]
[Authorize(Roles = "User,Admin")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(IdentityProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(LanguageUsageProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(LanguageNotFoundProblemDetails), StatusCodes.Status404NotFound)]
public async Task<OkResult> UpdateProfile(UpdateProfileModel model)
{
await _service.UpdateProfile(model);

return Ok();
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions