> For the complete documentation index, see [llms.txt](https://stack.sylius.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stack.sylius.com/resource/index/validation.md).

# Validation

* [on HTML request](#on-html-request)
* [on API request](#on-api-request)
* [Disable validation](#disable-validation)

It uses `symfony/validator` to validate your data.

## on HTML request

{% code title="src/Entity/Book.php" lineNumbers="true" %}

```php
namespace App\Entity;

use App\Form\Type\BookType;
use Sylius\Resource\Model\ResourceInterface;
use Sylius\Resource\Metadata\AsResource;
use Sylius\Resource\Metadata\Create;
use Symfony\Component\Validator\Constraints as Assert;

#[AsResource(
    formType: BookType::class, 
    operations: [
        new Create(),
    ],
)
class Book implements ResourceInterface
{
    // ...
    #[Assert\NotBlank()]
    private ?string $title;
}
```

{% endcode %}

In this example, validation will fail when adding a new book without specifying its title on the form.

## on API request

{% code title="src/Entity/Book.php" lineNumbers="true" %}

```php
namespace App\Entity;

use App\Form\Type\BookType;
use Sylius\Resource\Metadata\Api\Post;
use Sylius\Resource\Model\ResourceInterface;
use Sylius\Resource\Metadata\AsResource;
use Symfony\Component\Validator\Constraints as Assert;

#[AsResource(
    operations: [
        new Post(),
    ],
)
class Book implements ResourceInterface
{
    // ...
    #[Assert\NotBlank()]
    private ?string $title;
}
```

{% endcode %}

In this example, validation will fail when adding a new book without specifying its title on the payload.

## Disable validation

In some case, you may want to disable this validation.

For example, in a "publish" operation, you may want to apply a state machine transition without validation existing data.

{% code title="src/BoardGameBlog/Infrastructure/Sylius/Resource/BoardGameResource.php" lineNumbers="true" %}

```php
namespace App\BoardGameBlog\Infrastructure\Sylius\Resource;

use App\BoardGameBlog\Infrastructure\Sylius\State\Http\Processor\PublishBoardGameProcessor;
use App\BoardGameBlog\Infrastructure\Sylius\State\Http\Provider\BoardGameItemProvider;
use App\BoardGameBlog\Infrastructure\Symfony\Form\Type\BoardGameType;
use Sylius\Resource\Metadata\ApplyStateMachineTransition;
use Sylius\Resource\Model\ResourceInterface;
use Sylius\Resource\Metadata\AsResource;
use Sylius\Resource\Metadata\Create;
use Symfony\Component\Validator\Constraints as Assert;

#[AsResource(
    formType: BoardGameType::class, 
    operations: [
        new Update(
            provider: BoardGameItemProvider::class, 
            processor: PublishBoardGameProcessor::class,
            validate: false, // disable resource validation        
        ),
    ],
)
class BoardGameResource implements ResourceInterface
{
}
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://stack.sylius.com/resource/index/validation.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
