Skip to content
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

Enum support #477

Closed
alanpoulain opened this issue Sep 29, 2022 · 5 comments · Fixed by #479
Closed

Enum support #477

alanpoulain opened this issue Sep 29, 2022 · 5 comments · Fixed by #479

Comments

@alanpoulain
Copy link
Member

Since enum support is available in api-doc-parser, an enum support could be added to InputGuesser.
It will dynamically generate a SelectInput with restricted choices.

@alanpoulain
Copy link
Member Author

@PawelSuwinski would you like to do it? 🙂

@PawelSuwinski
Copy link
Contributor

Why not, but I think at that moment still is hard to to fit all pieces together in an elegant way without figuring out of jsonld (hyra) representation of enum:
api-platform/api-doc-parser#123 (comment)

I don't have real case for hyra right now, I just stopped on openapi schema in brief decorating api_platform.metadata.property.metadata_factory service to generate enum schema keyword on every [#Assert\Choice(...)] validator constraint.

At admin level I have custom EnumInput component pasted before:
api-platform/api-doc-parser#123 (comment)

So having it right now without hydra representation I guess would required using in AdminGuesser additionally openapiDataProvider apart from hydraDataProvider.

@alanpoulain
Copy link
Member Author

It's OK if we don't have support for enum in Hydra yet. The api-doc-parser library is abstracting it anyway: you don't need to know if Hydra or OpenAPI is used.
Also this admin can be used with OpenAPI only: https://api-platform.com/docs/admin/openapi/.
And if you are using API Platform 2.7, there is already an enum support for Choice constraint:
https://github.com/api-platform/core/blob/8108899dc986b2c6dd4b905151a7e70229ff34d0/src/Symfony/Validator/Metadata/Property/Restriction/PropertySchemaChoiceRestriction.php#L47-L51

@PawelSuwinski
Copy link
Contributor

PawelSuwinski commented Sep 30, 2022

It's OK if we don't have support for enum in Hydra yet. The api-doc-parser library is abstracting it anyway: you don't need to know if Hydra or OpenAPI is used. Also this admin can be used with OpenAPI only: https://api-platform.com/docs/admin/openapi/.

So you mean to implement enum SelectInput guessing despite of which dataProvider is used and only for now it will only work only for OpenAPI, without assuming that we will now have both hydra features (schemaAnalyzer) and enum guessed, am I correct?

And if you are using API Platform 2.7, there is already an enum support for Choice constraint: https://github.com/api-platform/core/blob/8108899dc986b2c6dd4b905151a7e70229ff34d0/src/Symfony/Validator/Metadata/Property/Restriction/PropertySchemaChoiceRestriction.php#L47-L51

Nope, 2.6 from previous Api Platform Distrubution ;), I will upgrade and check it out, thanks for pointing.

@alanpoulain
Copy link
Member Author

So you mean to implement enum SelectInput guessing despite of which dataProvider is used and only for now it will only work only for OpenAPI, without assuming that we will now have both hydra features (schemaAnalyzer) and enum guessed, am I correct?

Yes you shouldn't know which data provider is used anyway: everything needs to be abstracted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants