Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

How to validate the UUID parameter before SQL request for a "GET item" request in API-Platform?

$
0
0

Using:

  • PostgreSQL 11 with uuid_generate_v4 type
  • Symfony 4.4.11
  • Api Platform 2.5.6

I have an Entity with the following Id :

/** * @ORM\Entity(repositoryClass="App\Repository\ContractRepository") * @ORM\HasLifecycleCallbacks */class Contract{    /**     * @ORM\Id()     * @ORM\GeneratedValue(strategy="UUID")     * @ORM\Column(name="id", type="guid", unique=true)     */    private $id;[...]

I generate the following route with Api Platform :

App\Entity\Contract:  itemOperations:    get:

So I get a generated route like /contracts/{id}

Currently, if I do /contracts/TEST, it will try to do the SQL request with "TEST" in a where clause and so will fail as a 500.

I would like to prevent this behaviour by asserting that the {id} parameter is a UUID_v4 and return a 400 if not.


Viewing all articles
Browse latest Browse all 3925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>