C
C#ā€¢7mo ago
ruski

Empty DTO list from swagger

For some reason whatever list of sizes I input, it always tells me in the debugger that the list of ProductCreateSizeRequests is empty.
public class CreateProductRequest
{
public string Name { get; set; }
public double Price { get; set; }
public string Category { get; set; }
public string Subcategory { get; set; }
public string Color { get; set; }
public int? ThumbnailIndex { get; set; }
public List<ProductCreateSizeRequest> Sizes { get; set; }
public List<IFormFile> Images { get; set; }
}
public class CreateProductRequest
{
public string Name { get; set; }
public double Price { get; set; }
public string Category { get; set; }
public string Subcategory { get; set; }
public string Color { get; set; }
public int? ThumbnailIndex { get; set; }
public List<ProductCreateSizeRequest> Sizes { get; set; }
public List<IFormFile> Images { get; set; }
}
public override async Task<ActionResult<Product>> CreateProduct(CreateProductRequest request)
{
_logger.LogInformation("POST Rest Request: Create product.");

try
{
Product product = await _productCommandService.CreateProduct(request);

foreach (IFormFile imageFile in request.Images)
{
string? response = await CreateImageForProductCreation(product.Id, imageFile);

if (response != null)
{
_logger.LogInformation($"Image Creation Response: " + response);
}
}

foreach (ProductCreateSizeRequest size in request.Sizes)
{
_logger.LogInformation("AICI E PROBLEMA");
string? response = await CreateSizeForProductCreation(product.Id, size);

if (response != null)
{
_logger.LogInformation($"Size Creation Response: " + response);
}
}

return Created(GenerateUriForProduct(product.Id), product);
}
catch (InvalidValue exception)
{
_logger.LogInformation("400 Rest Response: " + exception.Message);
return BadRequest(exception.Message);
}
}
public override async Task<ActionResult<Product>> CreateProduct(CreateProductRequest request)
{
_logger.LogInformation("POST Rest Request: Create product.");

try
{
Product product = await _productCommandService.CreateProduct(request);

foreach (IFormFile imageFile in request.Images)
{
string? response = await CreateImageForProductCreation(product.Id, imageFile);

if (response != null)
{
_logger.LogInformation($"Image Creation Response: " + response);
}
}

foreach (ProductCreateSizeRequest size in request.Sizes)
{
_logger.LogInformation("AICI E PROBLEMA");
string? response = await CreateSizeForProductCreation(product.Id, size);

if (response != null)
{
_logger.LogInformation($"Size Creation Response: " + response);
}
}

return Created(GenerateUriForProduct(product.Id), product);
}
catch (InvalidValue exception)
{
_logger.LogInformation("400 Rest Response: " + exception.Message);
return BadRequest(exception.Message);
}
}
,
No description
No description
No description
16 Replies
ruski
ruskiā€¢7mo ago
No description
ruski
ruskiā€¢7mo ago
it sees every image from the images list, but no sizes
mtreit
mtreitā€¢7mo ago
What does ProductCreateSizeRequest look like?
ruski
ruskiā€¢7mo ago
public class ProductCreateSizeRequest { public string Name { get; set; } public int Count { get; set; } }
mtreit
mtreitā€¢7mo ago
Does it work if your Json uses Name and Count instead of name and count ?
ruski
ruskiā€¢7mo ago
nope
mtreit
mtreitā€¢7mo ago
Oh wait You need square brackets for a List
ruski
ruskiā€¢7mo ago
yeah but shouldn't the swagger already consider it as an array? it works for images " -F 'Images=@pexels-photo-991679 (1).jpeg;type=image/jpeg' \ -F 'Images=@pexels-photo-991679 (1).jpeg;type=image/jpeg' \ -F 'Images=@pexels-photo-991679 (1).jpeg;type=image/jpeg'" it should work for dto's "-F 'Sizes={ "Name": "da", "Count": 0 }' \ -F 'Sizes={ "name": "string", "count": 0 }' "
mtreit
mtreitā€¢7mo ago
No description
ruski
ruskiā€¢7mo ago
i tried like this
ruski
ruskiā€¢7mo ago
No description
ruski
ruskiā€¢7mo ago
No description
ruski
ruskiā€¢7mo ago
still nothing
mtreit
mtreitā€¢7mo ago
You specified it twice?
mtreit
mtreitā€¢7mo ago
No description
ruski
ruskiā€¢7mo ago
the other one's empty let me try only once dont think itll make a difference tho yeah no differenc i dont think thats the problem i suppose i'll just make a different endpoint to add the sizes and not do it in the same one if u find a solution DM me please šŸ˜— anyone knows how to fix this?
Want results from more Discord servers?
Add your server