Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- [JsonSchema] [GH#798](https://github.com/janephp/janephp/pull/798) Do not implements `CacheableSupportsMethodInterface` when generating SF7 normalizers

## [7.6.1] - 2024-03-12
### Changed
- [Jane] [GH#792](https://github.com/janephp/janephp/pull/792) Improve Normalizer generation by including null values or not
Expand Down
16 changes: 2 additions & 14 deletions src/Component/JsonSchema/Generator/NormalizerGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function __construct(Naming $naming, Parser $parser, bool $useReference =
$this->naming = $naming;
$this->parser = $parser;
$this->useReference = $useReference;
$this->useCacheableSupportsMethod = $this->canUseCacheableSupportsMethod($useCacheableSupportsMethod);
$this->useCacheableSupportsMethod = $useCacheableSupportsMethod;
$this->skipNullValues = $skipNullValues;
$this->skipRequiedFields = $skipRequiedFields;
$this->validation = $validation;
Expand Down Expand Up @@ -165,13 +165,6 @@ public function generate(Schema $schema, string $className, Context $context): v
));
}

protected function canUseCacheableSupportsMethod(?bool $useCacheableSupportsMethod): bool
{
return
true === $useCacheableSupportsMethod
|| (null === $useCacheableSupportsMethod && class_exists('Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface'));
}

protected function createJaneObjectNormalizerClass(Schema $schema, array $normalizers): array
{
if ($this->useReference) {
Expand All @@ -197,14 +190,9 @@ protected function createJaneObjectNormalizerClass(Schema $schema, array $normal
$methods[] = $this->createBaseNormalizerInitNormalizerMethod();
$methods[] = $this->createProxyGetSupportedTypesMethod(array_keys($normalizers));

if ($this->useCacheableSupportsMethod) {
$methods[] = $this->createHasCacheableSupportsMethod();
}

$symfony7NormalizerClass = $this->createNormalizerClass(
'JaneObjectNormalizer',
$methods,
$this->useCacheableSupportsMethod
$methods
);

$methods = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ private function objectValidation(): void
'stringProperty4' => 'toto',
'stringProperty5' => 'tototo',
'stringProperty6' => 'totototo',
], ObjectObject::class);
], ObjectObject::class);
} catch (ValidationException $exception) {
$caughtException = $exception;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
if (!class_exists(Kernel::class) or (Kernel::MAJOR_VERSION >= 7 or Kernel::MAJOR_VERSION === 6 and Kernel::MINOR_VERSION === 4)) {
class JaneObjectNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface
class JaneObjectNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface
{
use DenormalizerAwareTrait;
use NormalizerAwareTrait;
Expand Down Expand Up @@ -56,10 +56,6 @@ public function getSupportedTypes(?string $format = null) : array
{
return ['Jane\\Component\\OpenApi2\\Tests\\Expected\\Model\\Schema' => false, 'Jane\\Component\\OpenApi2\\Tests\\Expected\\Model\\SchemaObjectProperty' => false, '\\Jane\\Component\\JsonSchemaRuntime\\Reference' => false];
}
public function hasCacheableSupportsMethod() : bool
{
return true;
}
}
} else {
class JaneObjectNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
if (!class_exists(Kernel::class) or (Kernel::MAJOR_VERSION >= 7 or Kernel::MAJOR_VERSION === 6 and Kernel::MINOR_VERSION === 4)) {
class JaneObjectNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface
class JaneObjectNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface
{
use DenormalizerAwareTrait;
use NormalizerAwareTrait;
Expand Down Expand Up @@ -56,10 +56,6 @@ public function getSupportedTypes(?string $format = null) : array
{
return ['Jane\\Component\\OpenApi3\\Tests\\Expected\\Model\\Schema' => false, 'Jane\\Component\\OpenApi3\\Tests\\Expected\\Model\\SchemaObjectProperty' => false, '\\Jane\\Component\\JsonSchemaRuntime\\Reference' => false];
}
public function hasCacheableSupportsMethod() : bool
{
return true;
}
}
} else {
class JaneObjectNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface
Expand Down
70 changes: 35 additions & 35 deletions src/Component/OpenApiCommon/Generator/ExceptionGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,50 +121,50 @@ public function generate(string $functionName, int $status, Context $context, ?C
EOD
)]]),
new Stmt\ClassMethod('__construct', [
'type' => Stmt\Class_::MODIFIER_PUBLIC,
'params' => [
new Param(new Expr\Variable($realPropertyName), null, $isArray ? null : new Name('\\' . $classFqdn)),
new Param(new Expr\Variable('response'), null, new Name('\\Psr\\Http\\Message\\ResponseInterface')),
],
'stmts' => [
new Stmt\Expression(new Expr\StaticCall(new Name('parent'), '__construct', [
new Scalar\String_($description),
])),
new Stmt\Expression(new Expr\Assign(
new Expr\PropertyFetch(
new Expr\Variable('this'),
$propertyName
), new Expr\Variable($realPropertyName)
)),
new Stmt\Expression(new Expr\Assign(
new Expr\PropertyFetch(
new Expr\Variable('this'),
'response'
), new Expr\Variable('response')
)),
],
]),
'type' => Stmt\Class_::MODIFIER_PUBLIC,
'params' => [
new Param(new Expr\Variable($realPropertyName), null, $isArray ? null : new Name('\\' . $classFqdn)),
new Param(new Expr\Variable('response'), null, new Name('\\Psr\\Http\\Message\\ResponseInterface')),
],
'stmts' => [
new Stmt\Expression(new Expr\StaticCall(new Name('parent'), '__construct', [
new Scalar\String_($description),
])),
new Stmt\Expression(new Expr\Assign(
new Expr\PropertyFetch(
new Expr\Variable('this'),
$propertyName
), new Expr\Variable($realPropertyName)
)),
new Stmt\Expression(new Expr\Assign(
new Expr\PropertyFetch(
new Expr\Variable('this'),
'response'
), new Expr\Variable('response')
)),
],
]),
new Stmt\ClassMethod($methodName, [
'type' => Stmt\Class_::MODIFIER_PUBLIC,
'stmts' => [
new Stmt\Return_(
new Expr\PropertyFetch(
new Expr\Variable('this'),
$propertyName
)
),
new Stmt\Return_(
new Expr\PropertyFetch(
new Expr\Variable('this'),
$propertyName
)
),
],
'returnType' => ($isArray ? null : new Name('\\' . $classFqdn)),
]),
new Stmt\ClassMethod('getResponse', [
'type' => Stmt\Class_::MODIFIER_PUBLIC,
'stmts' => [
new Stmt\Return_(
new Expr\PropertyFetch(
new Expr\Variable('this'),
'response'
)
),
new Stmt\Return_(
new Expr\PropertyFetch(
new Expr\Variable('this'),
'response'
)
),
],
'returnType' => new Name('\\Psr\\Http\\Message\\ResponseInterface'),
]),
Expand Down