OpenAPI-Symfony-Routing icon indicating copy to clipboard operation
OpenAPI-Symfony-Routing copied to clipboard

Incompatibility with NelmioApiDocBundle

Open kilobyte2007 opened this issue 4 years ago • 6 comments

Hello, I have an issue when trying to use this package while also using the NelmioApiDocBundle. I have this configuration:

     * @SWG\Get(
     *     path="/account",
     *     summary="Gets account",
     *     @SWG\Response(
     *         response="200",
     *         description="Returned when successful",
     *         @SWG\Schema(@SWG\Items(ref=@Model(type="App\Entity\Common\Account", groups={"account"})))
     *     )
     * )

and it gives me the following error:

User Warning: [Syntax Error] Expected Doctrine\Common\Annotations\DocLexer::T_CLOSE_PARENTHESIS, got '(' in \App\Controller\Api\AccountController->getAccountAction() in src/Controller/A  
  pi/AccountController.php on line 42:49  

If I understand it correctly, the annotations loader is not understanding the @ Model (which is a NelmioApiDocBundle class) definition. Is there a way to fix this?

kilobyte2007 avatar Nov 16 '20 14:11 kilobyte2007

Not sure where the error is coming from. But just based on the swagger spec and annotation library using ref=@Model(type="App\Entity\Common\Account", groups={"account"}) seems invalid. ref must be a string, not an object. See https://github.com/zircote/swagger-php/blob/fa686e0463203b68d4f497def2a5b3dde4abc8fd/src/Annotations/Schema.php#L23-L27

So this looks like an invalid extension from NelmioApiDocBundle if it's supposed to be like that. Not sure what OpenAPI-Symfony-Routing library can do here as annotation parsing happens in https://github.com/zircote/swagger-php. Maybe NelmioApiDocBundle uses some custom annotation parsing?

Tobion avatar Nov 26 '20 17:11 Tobion

Seems like it's this class https://github.com/nelmio/NelmioApiDocBundle/blob/master/OpenApiPhp/ModelRegister.php that is handling the ref=@Model annotation. So to be compatible with NelmioApiDocBundle, we could add the class to the annotation analysis in case it exists. Then it shouldn't fail. @kilobyte2007 you want to give it a try and create a PR?

Tobion avatar Nov 26 '20 17:11 Tobion

@kilobyte2007 are you still interested in solving this?

Tobion avatar May 20 '21 14:05 Tobion

Hey @Tobion. Yes! I have actually given it a try but struggled to understand how all of this works :-(

kilobyte2007 avatar May 20 '21 15:05 kilobyte2007

@DjordyKoert could you help out here?

mario-fehr avatar Feb 22 '24 06:02 mario-fehr

Hmmm you could have a look at the way NelmioApiDocBundle currently integrates with swagger-php. Maybe that can help you with creating a solution.

https://github.com/nelmio/NelmioApiDocBundle/blob/61c08f139e104db21b12832173b08fa37c22e619/ApiDocGenerator.php#L121-L132

DjordyKoert avatar Feb 22 '24 09:02 DjordyKoert