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

Dispatcher / transformer supporting SerializerInterface out of the box #158

Closed
northys opened this issue May 30, 2021 · 5 comments
Closed

Comments

@northys
Copy link

northys commented May 30, 2021

I noticed that https://github.com/contributte/apitte-skeleton/ implements it's own JsonDispatcher to use symfony/serializer. Also it somehow allows to return any value Object (DTO?) in controller that will be passed directly into serializer.

I did the same thing in my project based on nette/sandbox by extending DecoratedDispatcher::negotiate() which allows only array, scalar and IResponseEntity so I added is_object condition and returned new ObjectEntity wrapping my DTO which is already present in this repository but unsused. Then I created my own SerializerTransformer that transformed this TDO / value object into json exactly the same way you do in JsonDispatcher of apitte-skeleton.

My question is why is this part of apitte-skeleton and not supported out of the box by this library? Am I missing something? My point is that I migrated (basically I copied few folders into apitte-skeleton) my API I started to work at 2 weeks ago to contributte/api-skeleton and without changing much it magically started to work. So where's the difference between soluton in skeleton and my tinker solution?

@f3l1x
Copy link
Member

f3l1x commented May 31, 2021

If I get your point correctly, do you ask why some parts of apitte-skeleton, such as https://github.com/contributte/apitte-skeleton/blob/master/app/model/Api/Dispatcher/JsonDispatcher.php, is not part of apitte/core?

@northys
Copy link
Author

northys commented May 31, 2021

Yes

@northys
Copy link
Author

northys commented May 31, 2021

Basically what apitte/core allows me out of the box is piece of array *** while in some random sandbox which I didn't know about there is full featured serializer that allows me to return any DTO as response object from controller method. Those response objects can be nested and everything is typed and lovely. This option with serializer should be recommended default available in apitte/core <3

@northys
Copy link
Author

northys commented May 31, 2021

Before I discovered apitte sandbox I did it myself by extending DecoratedDispatcher's negotiate method with if (is_object) { return ObjectEntity::from($result); } and implementing SerializerTransformer that calls the symfony/serializer.

I don't know why you decided to put everything to dispatcher I don't think it is it's work to serialize responses. Aren't there transformers to do this job? I'm not nitpicking btw even if it may sound like so. It just confused me when I saw your solution for the first time. I thought my solution was bad usage of apitte and that I should do it in different way.

@f3l1x
Copy link
Member

f3l1x commented Jul 4, 2023

Closing here. Feel free to open it.

@f3l1x f3l1x closed this as completed Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants