FOSRestBundle icon indicating copy to clipboard operation
FOSRestBundle copied to clipboard

@RequestParam not working, symfony 4

Open sbahr001 opened this issue 8 years ago • 2 comments

Hello, I am new to symfony, and FOSRestBundle. I am trying to get @RequestParm to add an additional layer of protection, sending a 400 response when unexpected request attributes/form values are being sent. I am having a bit of difficulty getting it to work in symfony 4 and was wondering if anyone could help? I am using Postman to test the POST. Thank you

use App\Entity\Invoice;
use FOS\RestBundle\Controller\Annotations as Rest;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;

/**
     * @Rest\Post("invoice/{number}/item/{item}", name="pay_invoice")
     * @ParamConverter("invoice", options={"mapping" : {"number" : "invoice_number", "item" : "item_number"}})
     * @Rest\RequestParam(map=true,name="amount",default=null,nullable=false,allowBlank=false,strict=true)
     * @param Invoice $invoice
     * @return JsonResponse
 */

 public function __invoke(Invoice $invoice)
    {
       return JsonResponse::create(['success' => true]);
    }

I am obfuscating the url a bit, but this is the general url.

My fos_rest.yaml file looks like

# Read the documentation: https://symfony.com/doc/master/bundles/FOSRestBundle/index.html
fos_rest:
    param_fetcher_listener:  true
#    allowed_methods_listener:  true
#    routing_loader: true
#    view:
#        view_response_listener:  true
#    exception:
#        codes:
#            App\Exception\MyException: 403
#        messages:
#            App\Exception\MyException: Forbidden area.
#    format_listener:
#        rules:
#            - { path: ^/, prefer_extension: true, fallback_format: json, priorities: [ json ] }

sbahr001 avatar Dec 27 '17 18:12 sbahr001

up

antonisin avatar Jan 02 '18 09:01 antonisin

Do you have any exceptions in your log files?

juliusstoerrle avatar Jan 16 '18 07:01 juliusstoerrle