Search code examples
api-platform.com

YAML validation on API plaftform


I use API platform with YAML instead of Annotations. It's very easy to add validation constraint on Annotation but how add constraint in YAML. In the doc in Validation chapter I don't find. https://api-platform.com/docs/core/validation/#validation


Solution

  • API Platform uses the constraint validator from Symfony, you can refer to the symfony constraints documentation.

    For example, using the Product sample from API platform with NotBlank constraint you should have:

    # config/validator/validation.yaml
    App\Entity\Product:
        properties:
            name:
                - NotBlank: ~