From e5a35b409db50cd3c16623a0b06a06401a90fd96 Mon Sep 17 00:00:00 2001 From: "n.gnato" Date: Fri, 14 Mar 2025 18:53:29 +0300 Subject: [PATCH 1/3] set version 0.1.0 in changelog --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1932ef..bfb26ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.1.0] - 2025-03-14 + ### Deprecated - mark classes in namespace FreeElephants\JsonApiToolkit\DTO are deprecated @@ -132,7 +134,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 From 1fef852baa47248545f20e2228f97ca7e446096f Mon Sep 17 00:00:00 2001 From: samizdam Date: Fri, 14 Mar 2025 18:58:56 +0300 Subject: [PATCH 2/3] Remove dto staff from project --- CHANGELOG.md | 3 + composer.json | 2 +- .../JsonApiToolkit/DTO/AbstractAttributes.php | 11 --- .../JsonApiToolkit/DTO/AbstractDocument.php | 14 ---- .../DTO/AbstractRelationships.php | 11 --- .../DTO/AbstractResourceObject.php | 14 ---- .../DTO/BaseKeyValueStructure.php | 11 --- .../SuitableRelationshipsTypeDetector.php | 27 ------ .../JsonApiToolkit/DTO/RelationshipToOne.php | 11 --- .../DTO/ResourceIdentifierObject.php | 11 --- .../JsonApiToolkit/DTO/DocumentTest.php | 84 ------------------- .../JsonApiToolkit/DTO/Example/Attributes.php | 10 --- .../DTO/Example/OneRelationships.php | 11 --- .../DTO/Example/TwoRelationships.php | 11 --- .../SuitableRelationshipsTypeDetectorTest.php | 61 -------------- .../JsonApiToolkit/DTO/ResourceObjectTest.php | 33 -------- .../DTO/ResourceObjectTestPHP8.php | 33 -------- 17 files changed, 4 insertions(+), 354 deletions(-) delete mode 100644 src/FreeElephants/JsonApiToolkit/DTO/AbstractAttributes.php delete mode 100644 src/FreeElephants/JsonApiToolkit/DTO/AbstractDocument.php delete mode 100644 src/FreeElephants/JsonApiToolkit/DTO/AbstractRelationships.php delete mode 100644 src/FreeElephants/JsonApiToolkit/DTO/AbstractResourceObject.php delete mode 100644 src/FreeElephants/JsonApiToolkit/DTO/BaseKeyValueStructure.php delete mode 100644 src/FreeElephants/JsonApiToolkit/DTO/Reflection/SuitableRelationshipsTypeDetector.php delete mode 100644 src/FreeElephants/JsonApiToolkit/DTO/RelationshipToOne.php delete mode 100644 src/FreeElephants/JsonApiToolkit/DTO/ResourceIdentifierObject.php delete mode 100644 tests/FreeElephants/JsonApiToolkit/DTO/DocumentTest.php delete mode 100644 tests/FreeElephants/JsonApiToolkit/DTO/Example/Attributes.php delete mode 100644 tests/FreeElephants/JsonApiToolkit/DTO/Example/OneRelationships.php delete mode 100644 tests/FreeElephants/JsonApiToolkit/DTO/Example/TwoRelationships.php delete mode 100644 tests/FreeElephants/JsonApiToolkit/DTO/Reflection/SuitableRelationshipsTypeDetectorTest.php delete mode 100644 tests/FreeElephants/JsonApiToolkit/DTO/ResourceObjectTest.php delete mode 100644 tests/FreeElephants/JsonApiToolkit/DTO/ResourceObjectTestPHP8.php diff --git a/CHANGELOG.md b/CHANGELOG.md index bfb26ce..6c01786 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Removed +- Dto tests + ## [0.1.0] - 2025-03-14 ### Deprecated 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/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); - } -} - From e5fd3da838714a49683cec8338f0a1338481d38a Mon Sep 17 00:00:00 2001 From: samizdam Date: Fri, 14 Mar 2025 20:55:24 +0300 Subject: [PATCH 3/3] Update readme and changelog, prepare v0.2.0 --- CHANGELOG.md | 2 ++ README.md | 6 ++++-- docs/dto-psr7.md | 7 ------- 3 files changed, 6 insertions(+), 9 deletions(-) delete mode 100644 docs/dto-psr7.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c01786..da86611 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.2.0] - 2025-03-14 + ### Removed - Dto tests 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/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.