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

[RFC] Support for DTOs / resource representation classes #2053

Closed
teohhanhui opened this issue Jun 28, 2018 · 7 comments
Closed

[RFC] Support for DTOs / resource representation classes #2053

teohhanhui opened this issue Jun 28, 2018 · 7 comments

Comments

@teohhanhui
Copy link
Contributor

We should support resource representation classes as an intermediary so that our resource classes can be clean / strongly typed.

To illustrate: https://gist.github.com/teohhanhui/970cf7d5bff27530aa3935a1566f67bf

@teohhanhui
Copy link
Contributor Author

nb. @dunglas even if the type check is performed in the normalizer, it's still not a good error message when we'd expect to get validation errors instead. I think it's a symptom of a design problem when validation is not done using the Symfony Validator.

@teohhanhui
Copy link
Contributor Author

Uhh, more importantly, input validation is more than just checking for the correct types and required values. Having a resource representation class is a really powerful thing as it allows supporting all kinds of validation and authorization scenarios.

@er1z
Copy link
Contributor

er1z commented Jul 4, 2018

What are benefits in real apps?

@bertrandseurot
Copy link

+1
@er1z Especially useful for specific roles actions. Avoid a lot of complexity and tricks

Actually when you add contextual serializer groups (according to the user role), the swagger documentation is incomplete (properties key missing). You can actually create your own DTO, but you have to manually hydrate your entity in an event subscriber, and the route appears disconnected of your resources routes in the swagger UI interface (not Front developpers friendly)

@ApiResource(relatedResource="Book") ?

@teohhanhui
Copy link
Contributor Author

@Bertranddev I imagine it should be the other way around. @ApiResource should be on the actual resource class itself, which declares its representation classes.

@er1z
Copy link
Contributor

er1z commented Jul 17, 2018

Sounds legit. You're right that creating DTOs, currently, is not very convenient but the best way to make the app looking the same regardless the data is fetched via entity or generated in some way.

One request — keep docs actual, especially if someone do not use any annotations because right now it requires too much of guessing. Switching to YAML/XML needs to dig into sources. :(

@dunglas
Copy link
Member

dunglas commented Dec 22, 2018

Fixed (at least partially) by #2235

@dunglas dunglas closed this as completed Dec 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants