Skip to content

Return the data type "string" for the enum PHP class in the JSON Schema document. #4857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

ymaillard
Copy link

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']

…ma document.

Actually, the JSON Schema document specifies the data type "object". According to my interpretation of the specification, it should be a string ( https://swagger.io/docs/specification/data-models/enums/ )
@alanpoulain
Copy link
Member

I don't think the enum format exists though.

@ymaillard
Copy link
Author

I don't think the enum format 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.

@alanpoulain
Copy link
Member

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.

@ymaillard
Copy link
Author

Ok I understand. Thanks for json-schema reference. I change my PR by removing the 'format' attribute. Is it ok for you ?

@alanpoulain
Copy link
Member

Yes, also you should add a unit test.

@GregoireHebert
Copy link
Contributor

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 #2254

@GregoireHebert
Copy link
Contributor

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 #2254
I wonder how much should part this type detection should be part of PropertyInfo

@webda2l
Copy link
Contributor

webda2l commented Sep 23, 2022

This can be added as well for GraphQl with OLYBe@1b63666

@alanpoulain
Copy link
Member

Superseded #5120.

@alanpoulain alanpoulain closed this Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants