-
Notifications
You must be signed in to change notification settings - Fork 96
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
Collision between parametrized and not parametrized routes #123
Comments
Looks like https://github.com/thephpleague/openapi-psr7-validator/blob/master/src/PSR7/OperationAddress.php#L33-L44 this code knows nothing about intended types to match Does it fail any kind of validation? |
I want to validate a response before send it to client. I have request URI and method.
$pathFinder = new PathFinder($responseValidator->getSchema(), $path, $method);
$addresses = $pathFinder->search();
foreach ($addresses as $address) {
$responseValidator->validate($address, $psrResponse);
} I can't use OperationAddress without PathFinder: $operation = new \League\OpenAPIValidation\PSR7\OperationAddress('/apples/12345678', 'get') ;
// Exception, because it wants '/apples/{apple_id}', not '/apples/12345678'
$validator->validate($operation, $response); |
If types matching is too hard, maybe prioritize static routes over parametrized routes is better way. I mean exclude all parametrized OperationAddress from PathFinder return value, if it find one with exact match to static route. |
Request validation fails too. "GET /apples/ready-to-eat".
|
Can you provide more info on this? Because for me is the correct way to do this, but not really tested |
Maybe I confuse you by my inaccurate description of behaviors, but, please, help me understand, why the code validates response content against $schema = /** @lang JSON */ '
{
"openapi": "3.0.0",
"info": {
"description": "",
"version": "1.0.0",
"title": "Apples"
},
"servers": [
{
"url": "/api"
}
],
"paths": {
"/apples/{apple_id}": {
"get": {
"summary": "",
"description": "",
"operationId": "appleGet",
"parameters": [
{
"in": "path",
"name": "apple_id",
"schema": {
"type": "integer"
},
"required": true
}
],
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"apple"
],
"properties": {
"apple": {
"$ref": "#/components/schemas/apple"
}
}
}
}
}
}
}
}
},
"/apples/ready-to-eat": {
"get": {
"summary": "",
"description": "",
"operationId": "applesReadyGet",
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"properties": {
"apples": {
"type": "array",
"items": {
"$ref": "#/components/schemas/apple"
}
}
},
"required": [
"apples"
]
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"apple": {
"type": "object",
"required": [
"id"
],
"properties": {
"id": {
"type": "integer"
}
}
}
}
}
}
';
$validator = (new \League\OpenAPIValidation\PSR7\ValidatorBuilder)->fromJson($schema)->getResponseValidator();
$operation = new \League\OpenAPIValidation\PSR7\OperationAddress('/api/apples/ready-to-eat', 'get') ;
$responseContent = /** @lang JSON */ '
{
"apples": [
{
"id": 0
}
]
}
';
$response = new \Nyholm\Psr7\Response(200, ['Content-Type' => 'application/json'], $responseContent);
$validator->validate($operation, $response); |
This sound like a solid bug now. I will try to check it, thanks |
Sorry for late response. I've managed to fix last "test" by replacing |
Yeah, |
For example, 2 routes:
PathFinder::search() must return only one route in this case, because
apple_id
is integer.league/openapi-psr7-validator: v0.15.2
The text was updated successfully, but these errors were encountered: