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

[Bug]: The PropertyInfo component was not able to guess the type of Company::$edAt. You may need to add a @var annotation or use @OA\Property(type="") to make its type explicit #2286

Open
tomasvts opened this issue May 17, 2024 · 1 comment
Labels

Comments

@tomasvts
Copy link

tomasvts commented May 17, 2024

Version

4.26

Description

Whenever I document a property that has a getter method with the word "ADD" in its name, the bundle fails with the following error:
The PropertyInfo component was not able to guess the type of Company::$edAt. You may need to add a `@var` annotation or use `@OA\Property(type="")` to make its type explicit

In this error, the property addedAt has a getter method with the same name addedAt(), and the bundle parses or interprets the ADD part, and only reads the rest (in this case edAt).

image

Company class

#[Schema(properties: [
    new Property(property: 'id', type: 'string', example: '8a8f8e8e-8e8e-8e8e-8e8e-8e8e8e8e8e8e'),
    new Property(property: 'name', type: 'string', example: 'Agency Name'),
    new Property(property: 'addedAt', type: 'integer', example: 1631610000),
])]
class Company
{
          public function addedAt(): int
          {
                  return $this->addedAt;
          }

Company Controller

class CompanyController extends SymfonyController
{
    #[Get(description: 'Get company details', summary: 'Get company details')]
    #[Response(content: new JsonContent(properties: [
        new Property(property: 'data', ref: new Model(type: Company::class))
    ]))]
    public function index()
    {

Additional context

Check this reproducible repository, and you can see it yourself.
https://github.com/tomasvts/nelmioApiDocBundleBug

Note: If I change the name of the getter to getAddedAt(), the problem goes away, which is the temporary solution I'm using. Nevertheless, I believe I have the right to name my getters the way I want.

@tomasvts tomasvts added the bug label May 17, 2024
@tomasvts
Copy link
Author

tomasvts commented May 17, 2024

The problem is in the (symfony/property-info) ReflecionExtractor class. It assumes that if a method has an "add" at the start, is a mutator, thus it should be stripped the word add:

https://github.com/symfony/property-info/blob/7.0/Extractor/ReflectionExtractor.php#L658
image

Then

image

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

No branches or pull requests

1 participant