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

DocParser can now ignore whole namespaces #45

Closed
wants to merge 3 commits into from
Closed

DocParser can now ignore whole namespaces #45

wants to merge 3 commits into from

Conversation

BreiteSeite
Copy link

We would like to ignore whole namespaces in the annotation-reader.

We use swagger-php to document our REST-API in our source code. However, zircote/swagger-php is a dev dependency and therefore not deployed to the production environment. As we use doctrine, the Application crashes because the AnnotationReader (used by doctrine-orm) throws an Exception because it can't resolve the @SWG\* annotations.

To fix this, we have to register every Swagger-Annotation with AnnotationReader::addGlobalIgnoredName();

This leads to this code (list of swagger annotations: http://zircote.com/swagger-php/annotations.html#annotation-hierarchy):

\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('SWG\Resource');
\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('SWG\Api');
\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('SWG\Operation');
\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('SWG\Parameter');
\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('SWG\ResponseMessage');
\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('SWG\Model');
\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('SWG\Property');
\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('SWG\Items');
\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('SWG\Authorization');
\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('SWG\Scope');
\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('SWG\Info');

With this PR, we could use:

\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredNamespace('SWG');

And won't have to update the global ignores if a new swagger annotation is introduced (with an update).

@@ -700,6 +700,14 @@ private function Annotation()
return false;
}

foreach (array_keys($this->ignoredAnnotationNames) as $annotationName) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't pack annotation names and namespaces into the same property.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the semantic meaning changes, which makes the code harder to read/understand.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. IMHO it's technically the name of the annotation. Plus... a spaced name is still a name. Just more organized.

What would you name the two (new) properties?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BreiteSeite ignoredNamespaces? :-)

@BreiteSeite BreiteSeite changed the title DocParser can now ignore whole namespaces or subnamespaces DocParser can now ignore whole namespaces Nov 26, 2014
@Ocramius Ocramius self-assigned this Dec 18, 2014
@BreiteSeite
Copy link
Author

Hi @Ocramius,

i rebased on master and refactored to a new property ignoredAnnotationNamespaces. This required the AnnotationReader to gain a new method: addGlobalIgnoredNamespace.

Could you please give Feedback on tests and implementation?

Thank you.

@Ocramius Ocramius added this to the v1.3.0 milestone Apr 14, 2015
@covex-nn
Copy link

sonata-project/user-bundle has optional dependency nelmio/api-doc-bundle and use @apidoc annotation in Controller/Api/UserController.php.

jms/di-extra-bundle inside it's cache warmer load all controllers with doctrine/annotations to "create injector".

If i want to use sonata-project/user-bundle and if i do not want to use nelmio/api-doc-bundle DocParser throws AnnotationException during cache warming up with this message:

The annotation "@nelmio\ApiDocBundle\Annotation\ApiDoc" in method Sonata\UserBundle\Controller\Api\GroupController::getGroupsAction() does not exist, or could not be auto-loaded.

So, i think it would be useful to ignore valid annotations (when $found === true) or/and fully qualified anotations (when '\\' === $name[0])

@Ocramius
Copy link
Member

Moved to #97, where I applied some additional fixes (functionality wasn't changed)

@Ocramius Ocramius closed this Oct 24, 2016
Ocramius added a commit that referenced this pull request Oct 24, 2016
… method, corrected property/parameter documentation
Ocramius added a commit that referenced this pull request Oct 24, 2016
…e-namespaces

Feature - #45 - allow ignoring entire namespaces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants