1

I am implementing Swagger-PHP for an API we've built.

Here is a brief recap:

Language: PHP5.3

Framework: FuelPHP 1.5.3

Environment: Local (served with Nginx)

Now I have an API method defined as follow:

/**
 * @SWG\Api(
 *   path="/site/list",
 *   description="Get sites list",
 *   @SWG\Operation(...,
 *      @SWG\Parameter(...),
 *      @SWG\ResponseMessage(...),
 *      @SWG\ResponseMessage(...)
 *   )
 * )
 */
public function action_run()
{
    //doing stuff
}

I now try the following (from elsewhere in my application) to generate the JSON:

$swagger = new Swagger\Swagger('my/root/dir');
$swagger->getResource('/site/list', array('output' => 'json'));

And that first line here (when instanciating my Swagger class) is throwing me an error:

ErrorException [ User Warning ]: [Semantical Error] The class "package" is not annotated with @Annotation. Are you sure this class can be used as annotation? If so, then you need to add @Annotation to the class doc comment of "package". If it is indeed no annotation, then you need to add @IgnoreAnnotation("package") to the class doc comment of class @Swagger\Annotations\Api.

Adding the @IgnoreAnnotation("package") is actually not helping.

I notice the error disappears if I remove the @package from here:

https://github.com/zircote/swagger-php/blob/master/library/Swagger/Annotations/Api.php#L28

But that's not a solution.

I'm guessing this is mainly Doctrine-related but I can't seem to figure it out.

Thanks for any tips or ideas on that matter.

1 Answer 1

1

Because FuelPHP has a Package class (in fuel/core/package.php), which isn’t an @Annotation the DocParser generates this warning.

Swagger-PHP uses the $docParser->setIgnoreNotImportedAnnotations(true) setting, which should prevent warnings like these.

I've reported the issue and fixed the problem but sadly the patch was rejected
Report the issue (again) to doctrine, the more people complain the faster it gets fixed 😉

As a workaround replace your DocParser.php with this version

Sign up to request clarification or add additional context in comments.

2 Comments

Two years later, the original class has evolved a bit compared to this fork linked in this answer. Be careful when using his fork.
I was too optimistic, expecting my 1 line change to be merged. I've updated the fork and re-aplied the patch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.