diff --git a/CHANGELOG.md b/CHANGELOG.md index d1932ef..da86611 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.2.0] - 2025-03-14 + +### Removed +- Dto tests + +## [0.1.0] - 2025-03-14 + ### Deprecated - mark classes in namespace FreeElephants\JsonApiToolkit\DTO are deprecated @@ -132,7 +139,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - FastRoute Dispatcher generation from swagger operationIds -[Unreleased]: https://github.com/FreeElephants/json-api-php-toolkit/compare/0.0.15...HEAD +[Unreleased]: https://github.com/FreeElephants/json-api-php-toolkit/compare/0.1.0...HEAD +[0.1.0]: https://github.com/FreeElephants/json-api-php-toolkit/compare/0.0.15...0.1.0 [0.0.15]: https://github.com/FreeElephants/json-api-php-toolkit/compare/0.0.14...0.0.15 [0.0.14]: https://github.com/FreeElephants/json-api-php-toolkit/compare/0.0.13...0.0.14 [0.0.13]: https://github.com/FreeElephants/json-api-php-toolkit/compare/0.0.12...0.0.13 diff --git a/README.md b/README.md index ff2019b..bad8c74 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ * [x] Build FastRoute Dispatcher by defined in OAS3 `operationsIds` values * [x] Serialize Doctrine entities with Neomerx schemas (resolve issue https://github.com/neomerx/json-api/issues/40) * [ ] Generate PHP Data Transfer Objects by OAS3 `reponseBody` and `requestBody` schema reference compliance with json:api -* [x] Map Psr Requests to Data Transfer Objects * [x] Validate incoming Psr Requests with swagger specification and user defined rules, and build Psr Response with json:api errors * [x] Map application models to Psr Response compliance with json:api structure @@ -26,7 +25,6 @@ Available in [/docs](/docs). #### Index: 1. [Routing](/docs/routing.md) 1. [Serialize doctrine entities](/docs/doctrine.md) -1. [DTO from psr server request](/docs/dto-psr7.md) 1. [Validation](/docs/validation.md) ## Development @@ -34,3 +32,7 @@ Available in [/docs](/docs). All dev env is dockerized. Your can use make receipts and `bin/` scripts without locally installed php, composer. For run tests with different php version change `PHP_VERSION` value in .env and rebuild image with `make build`. + +## See also: + +Package for map PSR-7 http messages with Json Api structure to PHP DTO: https://github.com/FreeElephants/json-api-dto diff --git a/composer.json b/composer.json index 96c0181..596de88 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,6 @@ "doctrine/persistence": "^2.0|^3.0", "fig/http-message-util": "^1.0", "free-elephants/i18n": "^0.0.1", - "free-elephants/json-api-dto": "^0.0.1", "laminas/laminas-stratigility": "^3.2", "laravel-json-api/neomerx-json-api": "^5.0.2", "league/openapi-psr7-validator": "0.19 - 0.22", @@ -41,6 +40,7 @@ "suggest": { "doctrine/orm": "^2.7", "free-elephants/di": "*", + "free-elephants/json-api-dto": "*", "laminas/laminas-httphandlerrunner": "*", "nyholm/psr7": "^1.2" }, diff --git a/docs/dto-psr7.md b/docs/dto-psr7.md deleted file mode 100644 index 2ea128d..0000000 --- a/docs/dto-psr7.md +++ /dev/null @@ -1,7 +0,0 @@ -# Build Data Transfer Objects from PSR7 Messages - -Full typed objects from request or response body. - -See example in [test](/tests/FreeElephants/JsonApiToolkit/DTO/DocumentTest.php). - -Union types support for relationships in PHP 8. diff --git a/src/FreeElephants/JsonApiToolkit/DTO/AbstractAttributes.php b/src/FreeElephants/JsonApiToolkit/DTO/AbstractAttributes.php deleted file mode 100644 index bb5b1b0..0000000 --- a/src/FreeElephants/JsonApiToolkit/DTO/AbstractAttributes.php +++ /dev/null @@ -1,11 +0,0 @@ -getTypes() as $type) { - $candidateType = $type->getName(); - $candidateClass = new \ReflectionClass($candidateType); - $isCandidate = false; - foreach ($data as $propertyName => $propertyData) { - if (!$candidateClass->hasProperty($propertyName)) { - break; - } - $isCandidate = true; - } - if ($isCandidate) { - break; - } - } - - return $candidateType; - } -} diff --git a/src/FreeElephants/JsonApiToolkit/DTO/RelationshipToOne.php b/src/FreeElephants/JsonApiToolkit/DTO/RelationshipToOne.php deleted file mode 100644 index a78d870..0000000 --- a/src/FreeElephants/JsonApiToolkit/DTO/RelationshipToOne.php +++ /dev/null @@ -1,11 +0,0 @@ -getBody()->write(<<assertInstanceOf(FooResource::class, $fooDTO->data); - $this->assertInstanceOf(FooAttributes::class, $fooDTO->data->attributes); - $this->assertSame('foo', $fooDTO->data->type); - $this->assertSame('bar', $fooDTO->data->attributes->foo); - $this->assertEquals(new \DateTime('2012-04-23T18:25:43.511Z'), $fooDTO->data->attributes->date); - $this->assertSame('someValue', $fooDTO->data->attributes->nested->someNestedStructure->someKey); - $this->assertSame('baz-id', $fooDTO->data->relationships->baz->data->id); - } -} - -class FooDocument extends AbstractDocument -{ - public FooResource $data; -} - -class FooResource extends AbstractResourceObject -{ - public FooAttributes $attributes; - public FooRelationships $relationships; -} - -class FooAttributes extends AbstractAttributes -{ - public string $foo; - public \DateTime $date; - public Nested $nested; -} - -class FooRelationships extends AbstractRelationships -{ - public \FreeElephants\JsonApi\DTO\RelationshipToOne $baz; -} - -class Nested extends BaseKeyValueStructure -{ - public SomeNestedStructure $someNestedStructure; -} - -class SomeNestedStructure extends BaseKeyValueStructure -{ - public string $someKey; -} diff --git a/tests/FreeElephants/JsonApiToolkit/DTO/Example/Attributes.php b/tests/FreeElephants/JsonApiToolkit/DTO/Example/Attributes.php deleted file mode 100644 index a7c2b00..0000000 --- a/tests/FreeElephants/JsonApiToolkit/DTO/Example/Attributes.php +++ /dev/null @@ -1,10 +0,0 @@ -getType(); - $detectedOne = $detector->detect($relationshipsPropertyUnionType, [ - 'fuzz' => [ - 'data' => [ - 'id' => 'fuzz', - 'type' => 'fuzz', - ], - ], - ]); - $this->assertSame(FuzzRelationships::class, $detectedOne); - - $detectedTwo = $detector->detect($relationshipsPropertyUnionType, [ - 'bar' => [ - 'data' => [ - 'id' => 'bazz', - 'type' => 'bazz', - ], - ], - ]); - $this->assertSame(BarRelationships::class, $detectedTwo); - } -} - -class ResourceWithUnionTypedRelationships extends AbstractResourceObject -{ - public BazzAttributes $attributes; - public FuzzRelationships|BarRelationships $relationships; -} - -class BazzAttributes extends AbstractAttributes -{ - public string $bazz; -} - -class FuzzRelationships extends AbstractRelationships -{ - public RelationshipToOne $fuzz; -} - -class BarRelationships extends AbstractRelationships -{ - public RelationshipToOne $bar; -} diff --git a/tests/FreeElephants/JsonApiToolkit/DTO/ResourceObjectTest.php b/tests/FreeElephants/JsonApiToolkit/DTO/ResourceObjectTest.php deleted file mode 100644 index 2cde333..0000000 --- a/tests/FreeElephants/JsonApiToolkit/DTO/ResourceObjectTest.php +++ /dev/null @@ -1,33 +0,0 @@ - 'id', - 'type' => 'type', - 'attributes' => [ - 'foo' => 'bar', - ], - 'relationships' => [ - 'one' => [ - 'data' => [ - 'type' => 'one', - 'id' => 'one', - ], - ], - ], - ]) extends AbstractResourceObject { - public Example\Attributes $attributes; - public Example\OneRelationships $relationships; - }; - - $this->assertInstanceOf(Example\OneRelationships::class, $resourceObject->relationships); - $this->assertSame('one', $resourceObject->relationships->one->data->type); - } -} diff --git a/tests/FreeElephants/JsonApiToolkit/DTO/ResourceObjectTestPHP8.php b/tests/FreeElephants/JsonApiToolkit/DTO/ResourceObjectTestPHP8.php deleted file mode 100644 index 3910c33..0000000 --- a/tests/FreeElephants/JsonApiToolkit/DTO/ResourceObjectTestPHP8.php +++ /dev/null @@ -1,33 +0,0 @@ - 'id', - 'type' => 'type', - 'attributes' => [ - 'foo' => 'bar', - ], - 'relationships' => [ - 'one' => [ - 'data' => [ - 'type' => 'one', - 'id' => 'one', - ], - ], - ], - ]) extends AbstractResourceObject{ - public Example\Attributes $attributes; - public Example\OneRelationships|Example\TwoRelationships $relationships; - }; - - $this->assertSame('one', $resourceObject->relationships->one->data->type); - } -} -