Skip to content

assertMatchesResourceItemJsonSchema throws "InvalidArgumentException: 0 is an invalid type for int" for int backed enum #5928

Description

@ErnestoNCarrea

API Platform version(s) affected: 3.2.1

Description
assertMatchesResourceItemJsonSchema throws JsonSchema\Exception\InvalidArgumentException: 0 is an invalid type for int when comparing against an int backed enum property.

How to reproduce
Simplified example:

public Status: int {
case Active = 1;
case Inactive = 0;
}

class Entity {
#[ORM\Column()]
private Status $status = Status::Active;
}

Use assertMatchesResourceItemJsonSchema against a request to /api/entities/1

Possible Solution
TypeConstraint.php@278 compares $type to 'integer'. Looks like int backed enums are detected as 'int' and not 'integer'.

Additional Context
Symfony 6.3.6
PHP 8.2

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions