Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Commit f58a521

Browse files
committed
Don't make assumptions on how versioning should work
Api-Method versioning should completly get handled in userspace. The library itself should be version-agnostic
1 parent 16b90e3 commit f58a521

File tree

5 files changed

+12
-22
lines changed

5 files changed

+12
-22
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ to the json schema validator and work with the data right away.
1212
Every method needs a corresponding schema-file which describes, how the request data should like alike.
1313
You can find a simple example in the `example/schema`-folder.
1414

15-
Every request has also to follow a basic schema (see `dist/request.json`) which contains informations about the method and the methods version.
15+
Every request has also to follow a basic schema (see `dist/request.json`) which contains informations about the method.
1616

1717
## Requirements
1818

@@ -99,5 +99,5 @@ Just cd to the example-folder and fire up the the php internal webserver `php -S
9999
Now you can send `POST`-Requests to the api like this curl-request.
100100

101101
```shell script
102-
curl -X POST -d '{"method": "beerlist", "version": null, "parameter": {"test1": "foobar", "test2": 666}}' "http://localhost:8888"
102+
curl -X POST -d '{"method": "beerlist", "parameter": {"test1": "foobar", "test2": 666}}' "http://localhost:8888"
103103
```

dist/request.json

+5-6
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
"type": "object",
99
"properties": {
1010
"method": {
11-
"type": "string"
11+
"type": "string",
12+
"description": "The method name"
1213
},
1314
"parameter": {
14-
"type": "object"
15-
},
16-
"version": {
17-
"type": ["integer", "null"]
15+
"type": "object",
16+
"description": "The methods parameter"
1817
}
1918
}
2019
}
2120
},
22-
"required": ["method", "parameter", "version"]
21+
"required": ["method", "parameter"]
2322
}

src/Contract/MethodProviderInterface.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
namespace Usox\JsonSchemaApi\Contract;
44

55
/**
6-
* A method provider should perform a lookup an api method by its name.
7-
* If api versions are used, the version number gets appended to the method name.
8-
* e.g. someNamespace.someMethod, someNamespace.someMethod.1
6+
* Lookup a method name and return the api method handler (e.g. by using a dict<methodName, methodHandler>
97
*
108
* If the method name does not exist, lookup is expected to return null.
119
*/

src/Dispatch/MethodDispatcher.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,8 @@ public function dispatch(
4242
ServerRequestInterface $request,
4343
stdClass $input
4444
): array {
45-
// Get the method and version from the request
45+
// Get the method from the request and perform lookup
4646
$methodName = $input->method;
47-
$version = $input->version;
48-
49-
if ($version !== null) {
50-
$methodName = sprintf('%s.%d', $methodName, $version);
51-
}
5247

5348
$handler = $this->methodProvider->lookup($methodName);
5449
if (!$handler instanceof ApiMethodInterface) {

tests/Dispatch/MethodDispatcherTest.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ public function testDispatchThrowsExceptionIfMethodDoesNotExist(): void
4848
$this->expectExceptionCode(StatusCode::BAD_REQUEST);
4949

5050
$method = 'some-method';
51-
$version = null;
5251

53-
$input = ['method' => $method, 'version' => $version];
52+
$input = ['method' => $method];
5453

5554
$this->methodProvider->shouldReceive('lookup')
5655
->with($method)
@@ -66,13 +65,12 @@ public function testDispatchThrowsExceptionIfMethodDoesNotExist(): void
6665
public function testDispatchReturnsHandler(): void
6766
{
6867
$method = 'some-method';
69-
$version = 666;
7068
$result = ['some-result'];
7169
$parameter = (object) ['some-parameter'];
7270
$schemaContent = (object) ['some' => 'schema-content'];
7371
$schemaFilePath = 'some-path';
7472

75-
$input = (object) ['method' => $method, 'version' => $version, 'parameter' => $parameter];
73+
$input = (object) ['method' => $method, 'parameter' => $parameter];
7674

7775
$request = Mockery::mock(ServerRequestInterface::class);
7876
$handler = Mockery::mock(ApiMethodInterface::class);
@@ -88,7 +86,7 @@ public function testDispatchReturnsHandler(): void
8886
->andReturn($schemaContent);
8987

9088
$this->methodProvider->shouldReceive('lookup')
91-
->with(sprintf('%s.%d', $method, $version))
89+
->with($method)
9290
->once()
9391
->andReturn($handler);
9492

0 commit comments

Comments
 (0)