Skip to content

Fallback attributes in the @ApiResource annotation #1788

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

Conversation

meyerbaptiste
Copy link
Member

@meyerbaptiste meyerbaptiste commented Mar 22, 2018

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets N/A
License MIT
Doc PR api-platform/docs#526

This PR adds the ability to configure resource attributes directly at the first level of the @ApiResource annotation. This improves the DX by adding autocompletion on annotation properties with modern IDEs.

Attribute keys are normally in snake_case but we use lowerCamelCase at the first level of the @ApiResource annotation. So I made the choice to define them also in lowerCamelCase here but they are then normalized to snake_case.

About private properties (see the second commit), they are "virtual" because of this issue: Haehnchen/idea-php-annotation-plugin#112. I don't like that, so if you have a better idea, just tell me.

In the same way, what about priorities? For example, actually: validationGroups={"foo"}, attributes={"validation_groups"={"bar"}} = ['bar'].
Are you agree? Or do you want ['foo'] or ['foo', 'bar'] instead?

@meyerbaptiste meyerbaptiste force-pushed the fallback_attributes_api_resource_annotation branch 3 times, most recently from cf73222 to 1e4dbad Compare March 22, 2018 17:08
/**
* @var string
*/
private $accessControl;
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a reference to the PHPStorm plugin issue, so we'll not forget and drop those properties later :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

* @Attribute("shortName", type="string"),
* @Attribute("subresourceOperations", type="array"),
* @Attribute("validationGroups", type="mixed")
* )
Copy link
Member

@soyuka soyuka Mar 23, 2018

Choose a reason for hiding this comment

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

FTR I'm using vim and all I see is noise 😈

(it's friday I'm allowed to rage coz I'm a hater)

Copy link
Member Author

Choose a reason for hiding this comment

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

Dear @soyuka,

I encourage you to download a real IDE. Here is the link to PHPStorm: https://www.jetbrains.com/phpstorm/download/.

I hope this could help you to find the truth!

Yours sincerely.

Copy link
Member Author

@meyerbaptiste meyerbaptiste Mar 23, 2018

Choose a reason for hiding this comment

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

More seriously, @Attribute annotations are needed when using a constructor in your annotation class. The noise here are the private properties.

@meyerbaptiste meyerbaptiste force-pushed the fallback_attributes_api_resource_annotation branch from 1e4dbad to 87edf6c Compare March 23, 2018 14:41
@meyerbaptiste meyerbaptiste force-pushed the fallback_attributes_api_resource_annotation branch from 87edf6c to 2cbee1d Compare March 23, 2018 16:58
private $routePrefix;

/**
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not having it on the class level since it's on every property?

Copy link
Member

Choose a reason for hiding this comment

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

Because we may introduce other properties for valid reasons later.

@dunglas dunglas merged commit d2b657e into api-platform:master Mar 29, 2018
@dunglas
Copy link
Member

dunglas commented Mar 29, 2018

Thanks @meyerbaptiste

@bendavies
Copy link
Contributor

I wonder if these could be fully documented in the docs?

@meyerbaptiste meyerbaptiste deleted the fallback_attributes_api_resource_annotation branch March 29, 2018 23:36
@meyerbaptiste
Copy link
Member Author

Yes it will be @bendavies, it's on my todo list 😉

@teohhanhui
Copy link
Contributor

Didn't see this earlier, but I also think it's bad, as the attributes were arbitrary keys we used, and many of them were specific to the Symfony integration. But now they've been elevated to a more important status.

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.

6 participants