core
core copied to clipboard
Return the data type "string" for the enum PHP class in the JSON Schema document.
| Q | A |
|---|---|
| Branch? | 2.7 |
| License | MIT |
Actually, the JSON Schema document specifies the data type "object" for an enum property. According to my interpretation of the specification, it should be a string ( https://swagger.io/docs/specification/data-models/enums/ )
This PR add a test if the class is a BackedEnum class and in this case, return an array ['type'=>'string, 'format'=>'enum']
I don't think the enum format exists though.
I don't think the
enumformat exists though.
I read on this page https://swagger.io/docs/specification/data-models/data-types/, 'format' is an open value. By example, I assume 'uuid' format used in the same method is not a value defined by open api specification. So enum format is a suggest.
uuid is a built-in format, see https://json-schema.org/draft/2020-12/json-schema-validation.html#name-resource-identifiers.
I don't think adding a custom format is a good idea, even if the specification allows it, since it will not be understood by clients.
Ok I understand. Thanks for json-schema reference. I change my PR by removing the 'format' attribute. Is it ok for you ?
Yes, also you should add a unit test.
A Backed Enum may be backed by types of int or string, and a given enumeration supports only a single type at a time. Is there a way to detect the right type? Plus, some detail have to be taken in consideration. Please have a look at https://github.com/api-platform/core/issues/2254
https://3v4l.org/dLRMX#v8.1.8 is an approach to find the backed type and associate it accordingly, or fall back into embedded object or resource as proposed in https://github.com/api-platform/core/issues/2254
I wonder how much should part this type detection should be part of PropertyInfo
This can be added as well for GraphQl with https://github.com/OLYBe/core/commit/1b63666a7394dcf78ac30f11964d71bbf51bd8ac
Superseded https://github.com/api-platform/core/pull/5120.