Skip to content

Add mandatory id and annotations #1080

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

Merged
merged 5 commits into from
Apr 12, 2020
Merged

Conversation

dhernandez
Copy link
Contributor

Adding an id to Book entity class and with the annotations included the example works from scratch including OpenAPI docs.

Adding an id to Book entity class and with the annotations included the example works from scratch including OpenAPI docs.
core/dto.md Outdated
@@ -6,7 +6,7 @@ However, it's sometimes useful to use a specific class to represent the input or

## Specifying an Input or an Output Data Representation

For a given resource class, you may want to have a different representation of this class as input (write) or output (read).
For a given resource class, you may want to have a different representation of this class as input (write) or output (read).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove the trailing space?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d094c19

@@ -27,6 +27,7 @@ use App\Dto\BookOutput;
*/
final class Book
{
public $id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example is needs also a @ApiProperty(identifier=true)
And to be honest, I should also have a property called $code
So the InputDataTransformer actually transform the isbn into a code.
And then in the OutputDataTransformer, from this code into the name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example only needs the annotation @ApiProperty(identifier=true) if you use another name to the property, like $code. But the example works without the annotation with the $id property.
Although, IMHO, Book entity shouldn't need a mandatory id property, because you have a BookInput and a BookOutput DTOs and BookInput have an id (called isbn).
So, to make a simple full example, that works with this issue, I think that adding an id called $id to Book is the clearest way.
Maybe, we can add also a note explaining the option of using $code property, annotated as identifier, and transforming it to isbn.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup it's a good idea, at least to clarify the process.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can check fabb572 🙂

Fix trailing space
Add process explanation
@dhernandez
Copy link
Contributor Author

Hi! What's happened with the PR? This is my first contribution so I don't know if you need anything else to merge. Please, tell me.

@alanpoulain alanpoulain merged commit e70fc5c into api-platform:2.5 Apr 12, 2020
@alanpoulain
Copy link
Member

Thank you @dhernandez.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants