api-platform / admin

A beautiful and fully-featured administration interface builder for hypermedia APIs
https://api-platform.com/docs/admin/
MIT License
480 stars 130 forks source link

Enum support #477

Closed alanpoulain closed 1 year ago

alanpoulain commented 1 year ago

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 commented 1 year ago

@PawelSuwinski would you like to do it? :slightly_smiling_face:

PawelSuwinski commented 1 year ago

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: https://github.com/api-platform/api-doc-parser/pull/123#issuecomment-1251338201

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: https://github.com/api-platform/api-doc-parser/pull/123#issue-1377925268

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

alanpoulain commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.