OpenAPI-Symfony-Routing
OpenAPI-Symfony-Routing copied to clipboard
Incompatibility with NelmioApiDocBundle
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?
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?
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?
@kilobyte2007 are you still interested in solving this?
Hey @Tobion. Yes! I have actually given it a try but struggled to understand how all of this works :-(
@DjordyKoert could you help out here?
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