api-platform / core

The server component of API Platform: hypermedia and GraphQL APIs in minutes
https://api-platform.com
MIT License
2.45k stars 874 forks source link

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

Open ErnestoNCarrea opened 1 year ago

ErnestoNCarrea commented 1 year ago

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

GwendolenLynch commented 6 months ago

This looks to have been fixed circa 3.2.8 as my test case passed from there on.