Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Multiple ValidationContext : Wrong Swagger documentation

Open
#6,360 2 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
openapi, php
Domain
api, documentation

Research direction

Start with the reproduction in api/src/Entity/Book.php and compare the generated Swagger documentation for POST and PUT, using the linked validation documentation as context. Trace the documentation generation path for the two validation contexts; done when each operation shows its own Length constraint while validation behavior remains correct.

Written by the indexing model from the issue text.

Description

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

Dominant language
PHP
Stars
2.6k
Forks
989
Avg merge
2d 1h
Merged PRs (30d)
104

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from api-platform/core

All issues in api-platform/core

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.