Skip to content

Commit

Permalink
revert: "Support php7.4 nullable typed properties for JMS serializer." (
Browse files Browse the repository at this point in the history
#2325)

Reverts #2103
  • Loading branch information
DjordyKoert authored Jul 22, 2024
1 parent 4f3c4f2 commit c952390
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 174 deletions.
31 changes: 0 additions & 31 deletions src/ModelDescriber/JMSModelDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ public function describe(Model $model, OA\Schema $schema)
} catch (\ReflectionException $ignored) {
}
}
$this->checkRequiredFields($reflections, $schema, $name);
if (null !== $item->setter) {
try {
$reflections[] = new \ReflectionMethod($item->class, $item->setter);
Expand Down Expand Up @@ -398,34 +397,4 @@ private function propertyTypeUsesGroups(array $type): ?bool
return null;
}
}

/**
* Mark property as required if it is not nullable.
*
* @param array<\ReflectionProperty|\ReflectionMethod> $reflections
*/
private function checkRequiredFields(array $reflections, OA\Schema $schema, string $name): void
{
foreach ($reflections as $reflection) {
$nullable = false;
if ($reflection instanceof \ReflectionProperty) {
$type = PHP_VERSION_ID >= 70400 ? $reflection->getType() : null;
if (null !== $type && !$type->allowsNull()) {
$nullable = true;
}
} elseif ($reflection instanceof \ReflectionMethod) {
$returnType = $reflection->getReturnType();
if (null !== $returnType && !$returnType->allowsNull()) {
$nullable = true;
}
}
if ($nullable) {
$required = Generator::UNDEFINED !== $schema->required ? $schema->required : [];
$required[] = $name;

$schema->required = $required;
break;
}
}
}
}
15 changes: 0 additions & 15 deletions tests/Functional/Controller/JMSController80.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSComplex80;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSDualComplex;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSNamingStrategyConstraints;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSTyped80;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSUser;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\NestedGroup\JMSChat;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\NestedGroup\JMSChatRoomUser;
Expand Down Expand Up @@ -167,18 +166,4 @@ public function minUserNestedAction()
public function discriminatorMapAction()
{
}

/**
* @Route("/api/jms_typed", methods={"GET"})
*
* @OA\Response(
* response=200,
* description="Success",
*
* @Model(type=JMSTyped80::class)
* )
*/
public function typedAction()
{
}
}
11 changes: 0 additions & 11 deletions tests/Functional/Controller/JMSController81.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSComplex81;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSDualComplex;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSNamingStrategyConstraints;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSTyped81;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSUser;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\NestedGroup\JMSChat;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\NestedGroup\JMSChatRoomUser;
Expand Down Expand Up @@ -142,14 +141,4 @@ public function enum()
public function discriminatorMapAction()
{
}

#[Route('/api/jms_typed', methods: ['GET'])]
#[OA\Response(
response: 200,
description: 'Success',
content: new Model(type: JMSTyped81::class))
]
public function typedAction()
{
}
}
46 changes: 0 additions & 46 deletions tests/Functional/Entity/JMSTyped80.php

This file was deleted.

36 changes: 0 additions & 36 deletions tests/Functional/Entity/JMSTyped81.php

This file was deleted.

25 changes: 0 additions & 25 deletions tests/Functional/JMSFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,6 @@ public function testEnumSupport(): void
],
],
'schema' => 'Article81',
'required' => [
'id',
'type',
'int_backed_type',
'not_backed_type',
],
], json_decode($this->getModel('Article81')->toJson(), true));

self::assertEquals([
Expand Down Expand Up @@ -426,23 +420,4 @@ protected static function createKernel(array $options = []): KernelInterface
{
return new TestKernel(TestKernel::USE_JMS);
}

public function testModelTypedDocumentation(): void
{
self::assertEquals([
'type' => 'object',
'properties' => [
'id' => ['type' => 'integer'],
'user' => ['$ref' => '#/components/schemas/JMSUser'],
'name' => ['type' => 'string'],
'virtual_friend' => ['$ref' => '#/components/schemas/JMSUser'],
],
'required' => [
'virtual_friend',
'id',
'user',
],
'schema' => 'JMSTyped',
], json_decode($this->getModel('JMSTyped')->toJson(), true));
}
}
10 changes: 0 additions & 10 deletions tests/Functional/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
use Nelmio\ApiDocBundle\Tests\Functional\Entity\BazingaUser;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSComplex80;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSComplex81;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSTyped80;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSTyped81;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\NestedGroup\JMSPicture;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\PrivateProtectedExposure;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\SymfonyConstraintsWithValidationGroups;
Expand Down Expand Up @@ -223,10 +221,6 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
'type' => JMSComplex80::class,
'groups' => null,
],
[
'alias' => 'JMSTyped',
'type' => JMSTyped80::class,
],
]);
} elseif (self::isAttributesAvailable()) {
$models = array_merge($models, [
Expand All @@ -244,10 +238,6 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
'type' => JMSComplex81::class,
'groups' => null,
],
[
'alias' => 'JMSTyped',
'type' => JMSTyped81::class,
],
]);
}

Expand Down

0 comments on commit c952390

Please sign in to comment.