Skip to content

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

Closed
ymaillard wants to merge 1 commit into
api-platform:mainfrom
ymaillard:patch-1
Closed

Return the data type "string" for the enum PHP class in the JSON Schema document.#4857
ymaillard wants to merge 1 commit into
api-platform:mainfrom
ymaillard:patch-1

Conversation

@ymaillard

Copy link
Copy Markdown
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
Copy Markdown
Member

I don't think the enum format exists though.

@ymaillard

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Yes, also you should add a unit test.

@GregoireHebert

Copy link
Copy Markdown
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
Copy Markdown
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

webda2l commented Sep 23, 2022

Copy link
Copy Markdown
Contributor

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

@alanpoulain

Copy link
Copy Markdown
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