From f1c3f68e909e51f071f3f4b2ef9430163bbfd7a4 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 15 Oct 2016 16:46:42 +0200 Subject: [PATCH] ApiDoc & Route annotation were conflicted MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The generated error was “Unable to guess how to get a Doctrine instance from the request information.”. I haven’t checked deeper in Doctrine (I know it was coming from the DoctrineParamConverter). Anyway, I check for FosRest possiblity to add extra format without allowing them for every route (like it was done in the first place). I finally found a way but it then seems all request goes to the FormatListener of FosRest so I needed to add a custom rules to match all request to be sure we don’t get a 406 error from FosRest. Should be ok now … --- app/config/config.yml | 27 +++++++++++++++++-- app/config/routing_rest.yml | 5 ++-- composer.json | 4 +-- .../Controller/WallabagRestController.php | 2 -- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/app/config/config.yml b/app/config/config.yml index 2f102c45c..b4760073b 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -112,12 +112,26 @@ swiftmailer: fos_rest: param_fetcher_listener: true body_listener: true - format_listener: true view: + mime_types: + csv: + - 'text/csv' + - 'text/plain' + pdf: + - 'application/pdf' + epub: + - 'application/epub+zip' + mobi: + - 'application/x-mobipocket-ebook' view_response_listener: 'force' formats: xml: true - json : true + json: true + txt: true + csv: true + pdf: true + epub: true + mobi: true templating_formats: html: true force_redirects: @@ -126,6 +140,15 @@ fos_rest: default_engine: twig routing_loader: default_format: json + format_listener: + enabled: true + rules: + - { path: "^/api/entries/([0-9]+)/export.(.*)", priorities: ['epub', 'mobi', 'pdf', 'txt', 'csv'], fallback_format: false, prefer_extension: false } + - { path: "^/api", priorities: ['json', 'xml'], fallback_format: false, prefer_extension: false } + - { path: "^/annotations", priorities: ['json', 'xml'], fallback_format: false, prefer_extension: false } + # for an unknown reason, EACH REQUEST goes to FOS\RestBundle\EventListener\FormatListener + # so we need to add custom rule for custom api export but also for all other routes of the application... + - { path: '^/', priorities: ['text/html', '*/*'], fallback_format: html, prefer_extension: false } nelmio_api_doc: sandbox: diff --git a/app/config/routing_rest.yml b/app/config/routing_rest.yml index 52d395dd9..29f4ab14c 100644 --- a/app/config/routing_rest.yml +++ b/app/config/routing_rest.yml @@ -1,4 +1,3 @@ Rest_Wallabag: - type : rest - resource: "@WallabagApiBundle/Resources/config/routing_rest.yml" - + type : rest + resource: "@WallabagApiBundle/Resources/config/routing_rest.yml" diff --git a/composer.json b/composer.json index 79de337ba..4f7ad2915 100644 --- a/composer.json +++ b/composer.json @@ -54,8 +54,8 @@ "sensio/framework-extra-bundle": "^3.0.2", "incenteev/composer-parameter-handler": "^2.0", "nelmio/cors-bundle": "~1.4.0", - "friendsofsymfony/rest-bundle": "~1.4", - "jms/serializer-bundle": "~1.0", + "friendsofsymfony/rest-bundle": "~2.1", + "jms/serializer-bundle": "~1.1", "nelmio/api-doc-bundle": "~2.7", "mgargano/simplehtmldom": "~1.5", "tecnickcom/tcpdf": "~6.2", diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index fa573988b..96f758074 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -167,8 +167,6 @@ class WallabagRestController extends FOSRestController * } * ) * - * @Route(requirements={"_format"="epub|mobi|pdf|txt|csv"}) - * * @return Response */ public function getEntryExportAction(Entry $entry, Request $request)