Skip to content

PHP 8.4 & Symfony 7.2.x support #840

@MikeSepteo

Description

@MikeSepteo

Jane version(s) affected: 7.8.1
PHP version: 8.4
Symfony version(s): 7.2.x

Description
When generating models from OpenAPI 3 yaml, the ReferenceNormalizer is not compatible :

Compile Error: Declaration of App\Http\External\***\Runtime\Normalizer\ReferenceNormalizer::supportsNormalization($data, $format = null): bool must be compatible with Symfony\Component\Serializer\Normalizer\NormalizerInterface::supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool

How to reproduce

  1. Create PHP 8.4, Symfony 7.2.x stack
  2. Run php vendor/bin/jane-openapi generate -c

Possible Solution
Update the template in generator, something like this :

if (Kernel::MAJOR_VERSION >= 7 || (Kernel::MAJOR_VERSION === 6 && Kernel::MINOR_VERSION === 4)) {
    class ReferenceNormalizer implements NormalizerInterface
    {
        /**
         * {@inheritdoc}
         */
        public function normalize(mixed $object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
        {
            $ref = [];
            $ref['$ref'] = (string) $object->getReferenceUri();
            return $ref;
        }
        /**
         * {@inheritdoc}
         * @param mixed $data
         * @param null $format
         * @param array $context
         */
        public function supportsNormalization($data, $format = null, array $context = []): bool
        {
            return $data instanceof Reference;
        }

        public function getSupportedTypes(?string $format) : array
        {
            return [Reference::class => false];
        }
    }
} else {
    class ReferenceNormalizer implements NormalizerInterface
    {
        /**
         * {@inheritdoc}
         */
        public function normalize($object, $format = null, array $context = [])
        {
            $ref = [];
            $ref['$ref'] = (string) $object->getReferenceUri();
            return $ref;
        }
        /**
         * {@inheritdoc}
         */
        public function supportsNormalization($data, $format = null): bool
        {
            return $data instanceof Reference;
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions