Closed davidhemphill closed 5 months ago
Upon looking further, if I wanted to switch payload
to be named body
, I would run into this problem again.
I understand it's probably an esoteric problem due to my project's nature, but maybe not?
Hey @davidhemphill I hope you are well!
I think you may just be a little unlucky in this scenario where you have run into property names that are already being used by Saloon behind the scenes. You would need to change the names of the properties in your constructor for it to work, Sadly. Sorry!
For headers
you could have:
bodyHeaders
_headers
? Although I don't like this one as muchOr you could use a DTO to pass in the fields?
public function __construct(public CreateRequestData $data)
{
}
public function defaultBody(): array
{
return [
'name' => $this->data->name,
'headers' => $this->data->headers,
'payload' => $this->data->payload,
];
}
With the DTO approach, you could have the same names!
Hey @davidhemphill I hope you're doing well. Did my last response help resolve the issue you were having?
Hi @Sammyjo20, I wound up resolving this by using a DTO. Thanks!
Hi! I'm using Saloon to create an SDK for a project. I have a request class I would like to have this API:
I'm not able to use this as it causes a type error since
headers
is already defined onRequest
viaHasHeaders
using a different type.I would love to find a way around this since it makes most sense for my users to be able to use the
header
parameter name.Thank you!