feat(metadata): add parameter name to uriVariablesConverter context - #8431
feat(metadata): add parameter name to uriVariablesConverter context#8431jannes-io wants to merge 1 commit into
Conversation
328b28a to
f72672a
Compare
| "justinrainbow/json-schema": "^6.5.2", | ||
| "laravel/framework": "^11.0 || ^12.0 || ^13.0", | ||
| "mcp/sdk": "^0.6", | ||
| "mcp/sdk": "^0.7", |
There was a problem hiding this comment.
Needed to change this to have a valid installable state,... without this all workflows and local composer install result in a non-resolvable set of dependencies.
There was a problem hiding this comment.
I initially wanted to add it as a fully qualified parameter to both the supports and transform functions, but that would be a backwards compatibility break.
| $paramContext = $context; | ||
| $paramContext['parameterName'] = $parameterName; |
There was a problem hiding this comment.
This is just so we don't overwrite anything that might've been added by the user to the context. The context remains the same outside of this function.
Downside? We have to copy the entire context array for every uri variable, so there might be a tiny performance overhead. Could also check outside of the foreach and keep whatever value was set out there, and reset it again after the foreach.
Adds the parameter name of the variable that's currently being processed to the context so custom implementations of
UriVariableTransformerInterfacecan do something with it.Our immediate use-case is that we have a uri variable that's a base64 encoded classname for a foreign entity, say:
#[GetCollection( uriTemplate: '/blips/{targetClass}/{foreignKey}', uriVariables: ['targetClass', 'foreignKey'], )] class Blip {}The
targetClassvalue is actually just a base64 encoded string, and it's also stored in the database. If we just use it like this (using symfony/doctrine), it will create the query with the correct parameters, but the value for targetClass remains b64 encoded.We can get around that by adding a custom uri variables transformer:
But this also triggers for the foreign key argument, so we need to base64 decode, and then check if the class exists, during the transformation itself:
This is not very clean... 😞
So this pull requests adds the current parameter name that's being transformed to the context, which will change our implementation to:
Very nice! 👍
I've also noticed there wasn't a unit test yet for
UriVariablesConverter, so I just added one but it only validates that theparameterNameis temporarily available in the context and not overwritten outside of it.