PSR-7 validation with regex possible? (parameter clash)

463 views Asked by At

I'm currently generating OpenAPI annotations via Symfony (5.1) Routes and NelmioApiDocBundle,

One of the routes looks like this:

 * @Route("/users/{id}", methods={"GET"}, requirements={"id": "\d+"})
 * @OA\Parameter(name="id", in="path", description="The id of the user", required=true, @OA\Schema(type="integer"))

and another like

 * @Route("/users/followed", methods={"GET"})

I'm using the League's OpenAPI PSR-7 Message Validator (https://github.com/thephpleague/openapi-psr7-validator) by converting the Symfony Request to a PSR-7 Request with symfony/psr-http-message-bridge and nyholm/psr7. It all works well, except for those 2 endpoints. I keep getting

The given request matched these operations: [/api/users/{id},get],[/api/charter-calculations/followed,get]. However, it matched not a single schema of theirs.

Is it possible the /followed can only be matched against /{id}? and thus the validator gets confused? Or is a regex for {id} as I have already done possible?

1

There are 1 answers

0
Oliver Adria On

Figured it out, so answering myself. It was somewhat specific to my problem, but possibly helpful for other people.

I had additional parameters such as

* @OA\Parameter(name="pageSize", in="query", @OA\Schema(type="integer"))

When I unit tested some of the validations to trigger an error (e.g. pageSize=test), it would throw a League\OpenAPIValidation\PSR7\Exception\Validation\InvalidQueryArgs.

But when I added the "/users/followed" endpoint then the previous tests would throw a different error: League\OpenAPIValidation\PSR7\Exception\MultipleOperationsMismatchForRequest, because now the error isn't "Hey, I found the endpoint, but the query is wrong!" but rather "Hey, I found multiple possible endpoints, they're all wrong!".