Nelmioapidocbundle: Notice: Undefined property: JMS\Serializer\Metadata\PropertyMetadata::$reflection

Created on 13 Nov 2018  路  9Comments  路  Source: nelmio/NelmioApiDocBundle

The serializer-bundle seems to have extensive changes in its latest release. Composer allows to install nelmio-api-doc-bundle with JMSSerializerBundle V3.0. But you will get a notice, which ends up in an exception in dev-mode:

in vendor/nelmio/api-doc-bundle/ModelDescriber/JMSModelDescriber.php (line 96)

        // read property options from Swagger Property annotation if it exists
        if (null !== $item->reflection) {
            $property = $properties->get($annotationsReader->getPropertyName($item->reflection, $name));
            $annotationsReader->updateProperty($item->reflection, $property, $groups);
        } else {
            $property = $properties->get($name);
        }

The formerly public variable $reflection is no longer available in JMS\Serializer\Metadata\PropertyMetadata (see https://github.com/schmittjoh/metadata/blob/e918c3a65105f73b74d94a0837b9f7d611d5bf0c/src/PropertyMetadata.php#L25 vs. https://github.com/schmittjoh/metadata/blob/e5854ab1aa643623dc64adde718a8eec32b957a8/src/Metadata/PropertyMetadata.php#L17

In the controller:

    /**
     * Get a list of something
     *
     * @SWG\Response(
     *     response=200,
     *
     *     @SWG\Schema(
     *         type="array",
     *         @SWG\Items(ref=@Model(type=MyModel::class))
     *     )
     * )
     *
     * @return Response
     */
    public function getListOfSomethingAction(): Response
    {     }

The model:

use JMS\Serializer\Annotation as Serializer;

class PaymentListItem
{
    /**
     *
     * @Serializer\Type("string")
     * @var string
     */
    private $type = 'my_type';

    /**
     * @Serializer\Type("string")
     * @var string
     */
    private $name = 'my_name';

}

composer.json - Symfony 4.1 project using composer version 1.7.3

{
    "name": "my app",
    "type": "project",
    "license": "proprietary",
    "require": {
        "php": "^7.1.3",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "friendsofsymfony/rest-bundle": "^2.4",
        "jms/serializer-bundle": "^3.0",
        "nelmio/api-doc-bundle": "^3.3",
        "sensio/framework-extra-bundle": "^5.2",
        "symfony/asset": "4.1.*",
        "symfony/console": "4.1.*",
        "symfony/flex": "^1.1",
        "symfony/framework-bundle": "4.1.*",
        "symfony/monolog-bundle": "^3.3",
        "symfony/orm-pack": "^1.0",
        "symfony/translation": "4.1.*",
        "symfony/twig-bundle": "4.1.*",
        "symfony/webpack-encore-bundle": "^1.0",
        "symfony/yaml": "4.1.*"
    },
    "require-dev": {
        "symfony/browser-kit": "4.1.*",
        "symfony/debug-pack": "*",
        "symfony/dotenv": "4.1.*",
        "symfony/phpunit-bridge": "4.1.*",
        "symfony/profiler-pack": "*"
    },
    "config": {
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    "replace": {
        "paragonie/random_compat": "2.*",
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php71": "*",
        "symfony/polyfill-php70": "*",
        "symfony/polyfill-php56": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": false,
            "require": "4.1.*"
        }
    }
}

Most helpful comment

All good Symfony packages should always be up to date with the latest changes. Looking forward for a fix. Will really help.

All 9 comments

jms/serializer-bundle v3 is not yet supported (see https://github.com/nelmio/NelmioApiDocBundle/pull/1433)

Hi, encountered same bug, shouldn't we add in composer.json

        "conflict": {
            "jms/serializer-bundle": ">^2",
        },

(unverified syntax)

@goetas,
see: Nelmio\ApiDocBundle\ModelDescriber\JMSModelDescriber:96
fix if (null !== $item->reflection) { on if (!empty($item->reflection)) { it's worked.

...
"jms/serializer-bundle": "^3.0",
"nelmio/api-doc-bundle": "^3.3",
...

So there are a PR for this fix?

"jms/serializer-bundle": "^2.0",

for now should fix the issue

@goetas Using Symfony 4.1 and fos/rest-bundle: "^2.0", it seems impossiblee to downgrade to "jms/serializer-bundle": "^2.0" - I keep getting conflicts no matter what version combinations I try.

As @atlance said, it's a very easy fix. I tried it locally and it works like a charm.

So if you have time please implement that change :+1: This way I cannot fully implement the apidoc in my new project..

you can downgrade it by removing vendor and composer.lock, and running composer update.

Please, fix it ASAP ))
as @atlance mentioned, this helps

All good Symfony packages should always be up to date with the latest changes. Looking forward for a fix. Will really help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ajaypatelbardoli picture ajaypatelbardoli  路  6Comments

timotheemoulin picture timotheemoulin  路  5Comments

jhkchan picture jhkchan  路  4Comments

manseuk picture manseuk  路  6Comments

andydandy80 picture andydandy80  路  4Comments