Repository: janephp/janephp (php)

Issue:
Making generated exceptions loggable
Dear developers,
when catching a generated Exception with a Scheme our logging tool (`monolog`) is not able to get a string representation of the error. As seen in my example an Exception contains a Scheme `errorResponse` which consists of multiple objects of the Scheme `error`.

```json
"components": {
        "schemas": {
            "errorResponse": {
                "properties": {
                    "errors": {
                        "description": "errors",
                        "type": "array",
                        "items": {
                            "$ref": "#/components/schemas/error"
                        }
                    }
                },
                "type": "object"
            },
            "error": {
                "required": [
                    "code",
                    "message"
                ],
                "properties": {
                    "code": {
                        "description": "Code",
                        "type": "string"
                    },
                    "message": {
                        "description": "Message",
                        "type": "string"
                    }
                },
                "type": "object"
            }
        }
}
```
Therefore it would be great if the generated Schemes as well as the Exception Class itself would implement the interface [`JsonSerializable`](https://www.php.net/manual/en/class.jsonserializable.php) and/or [`__toString()`](https://www.php.net/manual/en/language.oop5.magic.php#object.tostring) and we think that this feature would help more users.
 
We would love to hear from you and would be happy to contribute if necessary.
Kind Regards



Pull request:
report the actual validation errors when logging validation error
fix #614

this will make logs of a ValidationException much more usable.

Patch:
diff --git a/src/Component/JsonSchema/Generator/RuntimeGenerator.php b/src/Component/JsonSchema/Generator/RuntimeGenerator.php
index 60899cc69..6ced6cdc7 100644
--- a/src/Component/JsonSchema/Generator/RuntimeGenerator.php
+++ b/src/Component/JsonSchema/Generator/RuntimeGenerator.php
@@ -99,8 +99,9 @@ class RuntimeGenerator implements GeneratorInterface
                     ->addStmt(new Expr\Assign(new Expr\PropertyFetch($thisVariable, 'violationList'), $violationListVariable))
                     ->addStmt(new Expr\StaticCall(new Node\Name('parent'), '__construct', [
                         new Node\Arg(new Expr\FuncCall(new Node\Name('sprintf'), [
-                            new Node\Arg(new Scalar\String_('Model validation failed with %d errors.')),
+                            new Node\Arg(new Scalar\String_('Model validation failed with %d errors: %s')),
                             new Node\Arg(new Expr\MethodCall($violationListVariable, 'count')),
+                            new Expr\Cast\String_($violationListVariable),
                         ])),
                         new Node\Arg(new Expr\ConstFetch(new Node\Name('400'))),
                     ]))


Test patch:
diff --git a/src/Component/JsonSchema/Tests/fixtures/validator/expected/Validator/ValidationException.php b/src/Component/JsonSchema/Tests/fixtures/validator/expected/Validator/ValidationException.php
index f87f9ddf0..830eb3a50 100644
--- a/src/Component/JsonSchema/Tests/fixtures/validator/expected/Validator/ValidationException.php
+++ b/src/Component/JsonSchema/Tests/fixtures/validator/expected/Validator/ValidationException.php
@@ -10,7 +10,7 @@ class ValidationException extends \RuntimeException
     public function __construct(ConstraintViolationListInterface $violationList)
     {
         $this->violationList = $violationList;
-        parent::__construct(sprintf('Model validation failed with %d errors.', $violationList->count()), 400);
+        parent::__construct(sprintf('Model validation failed with %d errors: %s', $violationList->count(), (string) $violationList), 400);
     }
     public function getViolationList() : ConstraintViolationListInterface
     {
diff --git a/src/Component/OpenApi2/Tests/fixtures/docker-api/expected/Validator/ValidationException.php b/src/Component/OpenApi2/Tests/fixtures/docker-api/expected/Validator/ValidationException.php
index 075f9898a..8fcc0b35c 100644
--- a/src/Component/OpenApi2/Tests/fixtures/docker-api/expected/Validator/ValidationException.php
+++ b/src/Component/OpenApi2/Tests/fixtures/docker-api/expected/Validator/ValidationException.php
@@ -10,7 +10,7 @@ class ValidationException extends \RuntimeException
     public function __construct(ConstraintViolationListInterface $violationList)
     {
         $this->violationList = $violationList;
-        parent::__construct(sprintf('Model validation failed with %d errors.', $violationList->count()), 400);
+        parent::__construct(sprintf('Model validation failed with %d errors: %s', $violationList->count(), (string) $violationList), 400);
     }
     public function getViolationList() : ConstraintViolationListInterface
     {
diff --git a/src/Component/OpenApi3/Tests/fixtures/github/expected/Validator/ValidationException.php b/src/Component/OpenApi3/Tests/fixtures/github/expected/Validator/ValidationException.php
index 0ad4347d4..db5f2460b 100644
--- a/src/Component/OpenApi3/Tests/fixtures/github/expected/Validator/ValidationException.php
+++ b/src/Component/OpenApi3/Tests/fixtures/github/expected/Validator/ValidationException.php
@@ -10,7 +10,7 @@ class ValidationException extends \RuntimeException
     public function __construct(ConstraintViolationListInterface $violationList)
     {
         $this->violationList = $violationList;
-        parent::__construct(sprintf('Model validation failed with %d errors.', $violationList->count()), 400);
+        parent::__construct(sprintf('Model validation failed with %d errors: %s', $violationList->count(), (string) $violationList), 400);
     }
     public function getViolationList() : ConstraintViolationListInterface
     {