contributte / apitte

:wrench: An opinionated and enjoyable API framework based on Nette Framework. Supporting content negotiation, debugging, middlewares, attributes, annotations and loving openapi/swagger.
https://contributte.org/packages/contributte/apitte/
MIT License
61 stars 36 forks source link

Custom parameter mapping types #157

Closed northys closed 1 year ago

northys commented 3 years ago

When I saw this part of documentation about overriding mapping datatypes I immediately created my own UuidTypeMapper and registered it like

api:
    plugins:
        Apitte\Core\DI\Plugin\CoreMappingPlugin:
            types:
                uuid: App\Api\Mapping\Parameter\UuidTypeMapper

This is not supported though. Is there any way to add custom parameter mapping types? I'm not yet much familiar with the library codebase but from what I already saw it shouldn't be hard to implement. Maybe I could take a look at it but not this month. I have to finish something before deadline :D

Now I'm confused about dupllication of checks in multiple plugin and I think this must be fixed to implement this. Validation in CoreSchemaPlugin raises exception https://github.com/apitte/core/blob/c99c923ba006896a685a5d5b27fcdcc7d9432e49/src/Schema/Validation/RequestParameterValidation.php#L48 using in_array check inside array of hardcoded types. While CoreMappingPlugin does the actual mapping and is the one who registers the mappers. This array of mappers (their keys respectively) must be somehow passed to RequestParameterValidation inside CoreSchemaPlugin.

f3l1x commented 3 years ago

I see. Validation is a problem here. Great report.

MartinMystikJonas commented 2 years ago

@f3l1x Is there any work done on this already? In one of our apps it would be very useful to define custom types. I can try to prepare PR

MartinMystikJonas commented 2 years ago

@f3l1x I prepared PR that would allow custom mapping types to be added. Could you check it out? See https://github.com/contributte/apitte/pull/187

northys commented 2 years ago

Just btw - I'm no longer a programmer so I can't check it nor test it...

f3l1x commented 1 year ago

Done in #187