Closed jacraade closed 3 years ago
I don't see anything in the EnumInterface that allows us to know the type of values. So it's not possible at this time. You should perhaps raise this issue with them.
hmm. what would be needed to make it clear so i could create a pull request for it? a function that returns a php or json type name?
also i guess the backend binding doesn't help because its not a thing that always exists.
Hmm... It might help actually. They could create a PropertyInfo
extractor that uses the Doctrine metadata. But I don't lnow how good the PropertyInfo
component is at combining / merging type information from multiple sources. @dunglas?
IMO propertyinfo
can be easily decorated
Fair enough. But I don't think it should be done that way. Decorating the correct extractor sounds better.
@teohhanhui , ok after some more work i found out that only the get works but the put/post (denormalization) of enum values causes an "This value should be of type MyEnum" error.
i found out that api platform only passes the class name to the normalizer without the namespace (so "MyEnum" not "App\Enum\MyEnum"). This is likely the root issue as even with a custom Normalizer that adds the namespace back to it, it then fails at validation with the same error
@jacraade That doesn't sound like an API Platform issue. You probably forgot a use
statement?
i think i just solved it. the problem was not the use but the autogenerated @var \MyEnum
annotation.
never paid attention to it because i didn't imagine it being used. changed it to an absolute path seems to fix it (have to do more tests)
hope php gets native attributes some day and doesn't have to misuse comments 😞
sorry for the hassle
Edit: well fuck
Typed properties will be in PHP 7.4 :smile:
Closing as duplicate of https://github.com/api-platform/core/issues/2254
Hello.
Using Elao Enums as properties gets the openapi/swagger generator all confused. It always says that the type is string instead of the actual enum type or the type behind the enum (integer in my case). functionally it seems to work fine (as in you pass an integer not a string to the api and it saves it correctly) so that means the enum normalizer does its job.
is there a way to at least make it detect the correct type? (enum support in general seems to be WIP)
currently i'm overwriting it by hand using
but thats not optimal.
i suppose this is just how it is right now with enums not supported out of the box but is there a a better way doing it till they are supported?