You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pass nil to every single parameter, which doesn't work for the API I'm consuming (and I guess it wouldn't work for a lot of APIs either);
Create several functions with the same path so I wouldn't have to use nil (which is a very horrible approach);
Modify the @API macro so it adds default values for every parameter with an optional type.
I have a fork that implements the third option. However, I also had to modify the request builder so nil values aren't added to the request body, which may not be a very good idea if you have to explicitly set some value as nil.
If you have any other ideas, I'd be happy to implement them and open a PR. Maybe adding another macro, something like @AddDefaultValues?
Thanks!
The text was updated successfully, but these errors were encountered:
Hey @lyricalsoul! Thanks for the issue and for looking into this - lack of default values is a major pain point. Is the modified @API macro you made adding default values to the protocol in an extension or to the generated concrete type?
i.e. would the default values apply only to direct usages of the struct MessageSenderAPI from above? Or any use of the protocol MessageSender (assuming your example function is in a protocol called MessageSender).
Ideally it would be the protocol so that mocked interfaces could have the same default value API, perhaps via an extension?
HI there!
It would be nice if Papyrus added default values when generating API implementations. Personally, I have a lot of functions that look like this:
Currently, I have to either:
nil
to every single parameter, which doesn't work for the API I'm consuming (and I guess it wouldn't work for a lot of APIs either);nil
(which is a very horrible approach);@API
macro so it adds default values for every parameter with an optional type.I have a fork that implements the third option. However, I also had to modify the request builder so
nil
values aren't added to the request body, which may not be a very good idea if you have to explicitly set some value asnil
.If you have any other ideas, I'd be happy to implement them and open a PR. Maybe adding another macro, something like
@AddDefaultValues
?Thanks!
The text was updated successfully, but these errors were encountered: