-
-
Notifications
You must be signed in to change notification settings - Fork 920
Allow generating documentation when property and method start from "is" #4064
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
Allow generating documentation when property and method start from "is" #4064
Conversation
…s" (property `isActive` and method `isActive`)
src/JsonSchema/SchemaFactory.php
Outdated
@@ -327,6 +327,9 @@ private function getFactoryOptions(array $serializerContext, array $validationGr | |||
{ | |||
$options = []; | |||
|
|||
/* @see https://github.com/symfony/symfony/blob/v5.1.0/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php */ | |||
$options['enable_getter_setter_extraction'] = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO you could add it directly above 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I thought about this as well.
But IMHO it won't look good in case when it will be needed to add one more key-value there with explanation comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not like this:
$options = [
/* @see https://github.com/symfony/symfony/blob/v5.1.0/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php */
'enable_getter_setter_extraction' => true,
// Another explanation.
'another_option' => 'foo',
];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay to do this if you still think that it is critical. Should I?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not critical at all. It's only some code style 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in this case 👍
phpunit.xml.dist
Outdated
@@ -6,6 +6,7 @@ | |||
backupGlobals="false" | |||
bootstrap="tests/Fixtures/app/bootstrap.php" | |||
colors="true" | |||
stopOnFailure="true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it wanted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope. reverted
Couldn't it be like a BC? Since the generated OpenAPI documentation will change after this PR? |
@alanpoulain I'd say that it is not a BC as API Platform just doesn't generate right documentation. without this fix and exactly same structure like in my example class I'd be able to add |
Makes sense indeed. |
Thank you @sidz and congratulations for your first contribution (it seems)! |
thank you @alanpoulain, @dunglas for assistance |
{ | ||
$this->isDummyBoolean = $isDummyBoolean; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing existing tests is not recommended, I hope that using isDummyBoolean
on the property still works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The isDummyBoolean
method was not taken for the schema generation, only the property.
I don't think the tests have changed.
Currently API Platform doesn't generate documentation for case when both property and method names start from
is
. We need to defineisIsActive
orgetIsActive
orcanIsActive
orhasIsActive
For example:
In this case documentation won't include property
isActive
. But if we add missed property to the request it will be processed successfully and entity will be created.Documentation for such case is not generated due to changes in symfony since 5.1 inside ReflectionExtractor: https://github.com/symfony/symfony/blob/v5.1.0/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php#L232-L253
Let's see on line https://github.com/symfony/symfony/blob/v5.1.0/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php#L239-L240
Property
$camelProp
containsIsActive
string which will be iteratively concatenated with all possible prefixes. We get 4 possible method names which we may have to solve this issue:But we don't have such method in our class and we would like to use
isActive
without prefixes.So we go to line https://github.com/symfony/symfony/blob/v5.1.0/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php#L249
there we can see that
$reflClass->hasMethod($getsetter)
will find methodisActive
in our class but$allowGetterSetter
is equal to false as$context['enable_getter_setter_extraction']
is null.So this PR solve this issue and it will be possible to have
isActive
property and the same method name.p.s. The answer on question why everything works fine when we add missed
isActive
property to the request manually is on lines: https://github.com/symfony/property-access/blob/v5.1.0/PropertyAccessor.php#L472-L476