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]: problem with traversables #2323

Open
nikophil opened this issue Jul 18, 2024 · 2 comments
Open

[Bug]: problem with traversables #2323

nikophil opened this issue Jul 18, 2024 · 2 comments
Labels

Comments

@nikophil
Copy link

Version

all

Description

Before this PR in property info, documenting a property like this:

/**
 * @var \Doctrine\Common\Collections\Collection<SomeClass>
 */
public $someClasses

was ok-ish, because property-info was creating a Type such as:

Symfony\Component\PropertyInfo\Type^ {#23829
    -builtinType: "object"
    -nullable: false
    -class: "Doctrine\Common\Collections\Collection"
    -collection: true
    -collectionKeyType: array:0 []
    -collectionValueType: array:1 [
      0 => Symfony\Component\PropertyInfo\Type^ {#23825
        -builtinType: "object"
        -nullable: false
        -class: "App\Domain\SomeClass"
        -collection: false
        -collectionKeyType: []
        -collectionValueType: []
      }
    ]
  }

and then, ArrayPropertyDescriber was used because, the collection type does not have any collectionKeyType.

But now, for the same phpdoc annotation, the collection gets created with two collectionKeyType:

    -collectionKeyType: array:2 [
      0 => Symfony\Component\PropertyInfo\Type^ {#23827
        -builtinType: "string"
        // ...
      }
      1 => Symfony\Component\PropertyInfo\Type^ {#23830
        -builtinType: "int"
        // ...
      }
    ]

and then ArrayPropertyDescriber is not used anymore. And it result in the following error:

Schema of type "\Doctrine\Common\Collections\Collection" can't be generated, no describer supports it

I'm not really sure about the solution... maybe create a new TraversablePropertyDescriber would be enough?

JSON OpenApi

No response

Additional context

No response

@nikophil nikophil added the bug label Jul 18, 2024
@DjordyKoert
Copy link
Collaborator

I think this is mainly an issue with the way symfony/property-info handles unions. I think you should be able to fix this by specifying the key type of your collection:

/**
 * @var \Doctrine\Common\Collections\Collection<int, SomeClass>
 */
public $someClasses

@DjordyKoert
Copy link
Collaborator

Adding support for the newly added symfony/type-info component might offer a solution. https://symfony.com/doc/current/components/type_info.html

#2212

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

2 participants