Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple ValidationContext : Wrong Swagger documentation #6360

Open
Piairre opened this issue May 7, 2024 · 1 comment
Open

Multiple ValidationContext : Wrong Swagger documentation #6360

Piairre opened this issue May 7, 2024 · 1 comment

Comments

@Piairre
Copy link

Piairre commented May 7, 2024

API Platform version(s) affected: 3.2.13

Description
When multiple validationContext are used on the same property, the Swagger documentation is incorrectly generated; it utilizes the same Assert regardless of the validationContext .
The validation works correctly during the API call, it's just the Swagger documentation generation that is incorrect.

How to reproduce
Using Validation documentation :

<?php
// api/src/Entity/Book.php

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\ApiResource;
use Symfony\Component\Validator\Constraints as Assert;

#[ApiResource]
#[Delete]
#[Get]
#[Put(validationContext: ['groups' => ['Default', 'putValidation']])]
#[GetCollection]
#[Post(validationContext: ['groups' => ['Default', 'postValidation']])]
class Book
{
    #[Assert\Uuid]
    private $id;

    #[Assert\NotBlank(groups: ['postValidation'])]
    public $name;

    #[Assert\NotNull]
    #[Assert\Length(min: 2, max: 50, groups: ['postValidation'])]
    #[Assert\Length(min: 2, max: 70, groups: ['putValidation'])]
    public $author;

    // ...
}

Here is the generated documentation for the 'author' property for both the POST and PUT methods:
image

@soyuka
Copy link
Member

soyuka commented May 31, 2024

indeed serialization groups are handled but validation not, feel free to patch that looking at how we did with serialization groups (in the schema factory).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants