Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call to undefined method [SomeAnnotation]::isRoot() #1415

Closed
eigan opened this issue Feb 17, 2023 · 7 comments · Fixed by #1417
Closed

Call to undefined method [SomeAnnotation]::isRoot() #1415

eigan opened this issue Feb 17, 2023 · 7 comments · Fixed by #1417
Labels

Comments

@eigan
Copy link

eigan commented Feb 17, 2023

Error: Call to undefined method Symfony\Component\Serializer\Annotation\DiscriminatorMap::isRoot()

/vendor/zircote/swagger-php/src/Analysis.php:341
/vendor/zircote/swagger-php/src/Processors/ExpandClasses.php:35
/vendor/zircote/swagger-php/src/Analysis.php:425
/vendor/zircote/swagger-php/src/Generator.php:458

This can happen if you have a different annotation on an @OA\Schema.

/**
 * @OA\Schema(title="Some DTO", required={"title", "data_type"})
 * @Serializer\DiscriminatorMap(typeProperty="data_type", mapping={
 *     "foo"="bar",
 * })
 */
abstract class SomeDto {}

The line in Analysis seems to just assume that all annotations on the class has the isRoot method.

if ($annotation->isRoot(OA\Schema::class) && !$annotation->_context->is('generated')) {

Seems to be related to e449670 #1403

@DerManoMann
Copy link
Collaborator

Have you tried upgrading swagger-php ? I tried creating a testcase and it looks like the latest code should be ok with this.

@eigan
Copy link
Author

eigan commented Feb 18, 2023

Sorry, I should have provided better example.

<?php
require "vendor/autoload.php";

use OpenApi\Annotations as OA;

/**
 * @Annotation
 */
class CustomAnnotation {}

/**
 * @OA\Schema
 * @CustomAnnotation
 */
class SomeParent {}

/**
 * @OA\Schema
 */
class Child extends SomeParent {}

$generator = new \OpenApi\Generator();

$generator->generate([
    __FILE__
]);

@DerManoMann
Copy link
Collaborator

Interesting - things change depending on whether there is a namespace used or not 🧇

@eigan
Copy link
Author

eigan commented Feb 19, 2023

Thank you for the quick fix! 🙂

@akalineskou
Copy link
Contributor

akalineskou commented Mar 1, 2023

FYI this is also happening in

if (!$schema->isRoot(OA\Schema::class)) {
also

Call to undefined method OpenApi\\Attributes\\JsonContent::isRoot()
Using the latest 4.7.1 version.

Adding the same $schema instanceof OA\Schema check seems to get rid of the error, but I'm not sure if that is the correct solution.
I take this back, it this does not work, JsonContent is an instance of OA\Schema but still does not have the isRoot function, not sure why in this PR #1417 it works...
I've added localy method_exists($schema, 'isRoot') just to have it pass

@DerManoMann
Copy link
Collaborator

I am not sure what is going on there - JsonContent definitly shoudl have AbstractAnnotation as parent somewhere and that has the isRoot method.

@akalineskou
Copy link
Contributor

@DerManoMann You are correct, the function should be there but isn't... something went haywire with my vendor folder, re-installed everything and it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants