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

Error with Model Attribute #2237

Closed
AdrienBr opened this issue Mar 6, 2024 · 6 comments · Fixed by #2239
Closed

Error with Model Attribute #2237

AdrienBr opened this issue Mar 6, 2024 · 6 comments · Fixed by #2239

Comments

@AdrienBr
Copy link

AdrienBr commented Mar 6, 2024

Hello,
Symfony version : 5.4
Bundle version : 4.22.1

When I use this attribute :

    use OpenApi\Attributes as OA;
    use Nelmio\ApiDocBundle\Annotation\Model;

    ...

    #[OA\Response(
        response: 200,
        description: "Lorem Ipsum",
        content: new OA\JsonContent(
            ref: new Model(type: MyEntity::class, groups: ['openapi'])
        )
    )]

I get this error :

Argument 3 passed to Nelmio\\ApiDocBundle\\ModelDescriber\\ObjectModelDescriber::__construct() must be an array of Nelmio\\ApiDocBundle\\PropertyDescriber\\PropertyDescriberInterface or a single Nelmio\\ApiDocBundle\\PropertyDescriber\\PropertyDescriberInterface.

Is there anything wrong with my usage of OA attribute ?

Thanks

@DjordyKoert
Copy link
Collaborator

Could you perhaps try dumping dd() the argument by manually changing the class inside ur vendor (assuming it's happening on your local running version)?

This should not be happening so I'm quite curious about what value is being passed on your end.

@MaximeLemolt
Copy link

Hello @DjordyKoert i'm a colleague of @AdrienBr , here's the dump you asked for :
dump

The RewindableGenerator object is made up of all the PropertyDescriber classes:

  • ArrayPropertyDescriber
  • BooleanPropertyDescriber
  • CompoundPropertyDescriber
  • DateTimePropertyDescriber
  • DictionaryPropertyDescriber
  • FloatPropertyDescriber
  • IntegerPropertyDescriber
  • NullablePropertyDescriber
  • ObjectPropertyDescriber
  • PropertyDescriber
  • RequiredPropertyDescriber
  • StringPropertyDescriber

Thanks

@MaximeLemolt
Copy link

MaximeLemolt commented Mar 7, 2024

@DjordyKoert there's still a problem despite your fix :

{"type":"https:\/\/tools.ietf.org\/html\/rfc2616#section-10","title":"An error occurred","status":500,"detail":"Attempted to call an undefined method named \"supports\" of class \"Symfony\\Component\\DependencyInjection\\Argument\\RewindableGenerator\"."}

I think the ObjectModelDescriber's describeProperty method also needs to be modified for this to work

@DjordyKoert
Copy link
Collaborator

DjordyKoert commented Mar 7, 2024

Just to be curious, may I ask if you are manually defining the nelmio_api_doc.object_model.property_describer or nelmio_api_doc.model_describers.object service?

@DjordyKoert
Copy link
Collaborator

I think the ObjectModelDescriber's describeProperty method also needs to be modified for this to work

Done, could you check again? :)

@MaximeLemolt
Copy link

@DjordyKoert yes we do manually defining the service :

    Nelmio\ApiDocBundle\ModelDescriber\ObjectModelDescriber:
        arguments:
            $mediaTypes: [ ]
            $propertyDescribers: !tagged_iterator nelmio_api_doc.object_model.property_describer
            $nameConverter: '@serializer.name_converter.camel_case_to_snake_case'
        tags: [ nelmio_api_doc.model_describer ]

I checked again, and this time everything worked fine. Thanks

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 a pull request may close this issue.

3 participants