8000 Add areas support by GuilhemN · Pull Request #1169 · nelmio/NelmioApiDocBundle · GitHub
[go: up one dir, main page]

Skip to content

Add areas support #1169

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

Merged
merged 5 commits into from
Jan 5, 2018
Merged

Add areas support #1169

merged 5 commits into from
Jan 5, 2018

Conversation

GuilhemN
Copy link
Collaborator
@GuilhemN GuilhemN commented Jan 3, 2018

Should fix #1105 (review).

Copy link
Collaborator
@dbu dbu left a comment

Choose a reason for hiding this comment

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

very interesting!

can you elaborate the documentation a bit, to add some more examples what exactly this does?

for reviewing it would be easier to split this up into at least the code cleanups and the actual feature. ideally, even the thing about refactoring how tagged services are integrated would have been separate, but that would now be a large effort to separate.

composer.json Outdated
@@ -16,27 +16,26 @@
],
"require": {
"php": "^7.0",
"symfony/framework-bundle": "^3.2.5|^4.0",
"symfony/property-info": "^3.1|^4.0",
"symfony/framework-bundle": "^3.4|^4.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

i would do this cleanup in a separate pull request that does not add new features.

*/

namespace Nelmio\ApiDocBundle\Tests\Functional\Entity;

use JMS\Serializer\Annotation as Serializer;

/**
* Class JMSComplex
* @package Nelmio\ApiDocBundle\Tests\Functional\Entity
* Class JMSComplex.
Copy link
Collaborator

Choose a reason for hiding this comment

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

this does not tell anything the code does not already say. i'd remove the text line completely. (and these things part of the cleanup pull request rather than the new feature.)

])
->addTag(sprintf('nelmio_api_doc.describer.%s', $area), ['priority' => -400]);

$container->register('nelmio_api_doc.describers.swagger_php', SwaggerPhpDescriber::class)
Copy link
Collaborator

Choose a reason for hiding this comment

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

i find it an antipattern to define services in the DI extension instead of in the services xml files. its much harder to read what is going on imho. i would rather have additional services xml files for specific features that are only loaded if that feature is to be enabled. but i guess its a question of taste as well...

Copy link
Collaborator Author
@GuilhemN GuilhemN Jan 4, 2018

Choose a reason for hiding this comment

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

I tend to agree but these services are dynamically generated and we can't put them in a file unfortunately... Maybe using the php syntax would be clearer though (see symfony/symfony#23834).

Copy link
Collaborator

Choose a reason for hiding this comment

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

its ok, i can live with it as is, if we can't move it to the xml :-)

->children()
->arrayNode('documentation')
->useAttributeAsKey('key')
->info('The documentation used as base')
->example(['info' => ['title' => 'My App']])
->prototype('variable')->end()
->end()
->arrayNode('routes')
Copy link
Collaborator

Choose a reason for hiding this comment

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

this will need to be documented in the changelog

})
->then(function ($v) {
$v['areas'] = $v['routes'];
unset($v['routes']);
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should also trigger a deprecation warning

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added

@@ -21,20 +21,49 @@ public function getConfigTreeBuilder()
$treeBuilder = new TreeBuilder();
$treeBuilder
->root('nelmio_api_doc')
->beforeNormalization()
->ifTrue(function ($v) {
return !isset($v['areas']) && isset($v['routes']);
Copy link
Collaborator

Choose a reason for hiding this comment

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

if both areas and routes are set, we should throw an invalid configuration exception explaining to use only the new areas section. otherwise the user will just see an error that routes is not known, which will be confusing when before, routes did work.

README.md Outdated
@@ -77,9 +77,9 @@ routes that are documented by configuring the bundle:
```yml
# app/config/config.yml
nelmio_api_doc:
routes:
areas:
Copy link
Collaborator

Choose a reason for hiding this comment

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

does the areas model allow to specify other criteria than path patterns? and how to specify more than one distinct area?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

does the areas model allow to specify other criteria than path patterns?

For now it's only based on path patterns but we could easily add more criteria if we want to, I'd rather do this later though to not complicate this PR. The best imo would be to allow to add a custom routes filter.

and how to specify more than one distinct area?

You can define as many areas as you want:

nelmio_api_doc:
    areas:
        default: [ path_patterns: [ ^/api ] ]
        internal: [ path_patterns: [ ^/internal ] ]
        commercial: [ path_patterns: [ ^/commercial ] ]
        # ...

Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add a doc section for configuring several areas? so if you specify what we have here, you implicitly create a default area, and if you would explicitly create a list of areas, you get several?

@GuilhemN GuilhemN mentioned this pull request Jan 4, 2018
@GuilhemN GuilhemN force-pushed the newfeature branch 4 times, most recently from 47b6464 to f72ce77 Compare January 4, 2018 13:29
@GuilhemN
Copy link
Collaborator Author
GuilhemN commented Jan 4, 2018

I added tests and docs. Much bigger diff :/

@GuilhemN GuilhemN mentioned this pull request Jan 4, 2018
@GuilhemN GuilhemN force-pushed the newfeature branch 3 times, most recently from a67d6e1 to e3d787f Compare January 4, 2018 19:07
Copy link
Collaborator
@dbu dbu left a comment

Choose a reason for hiding this comment

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

a features is also its test and doc, and this is no tiny thing ;-) great job!

i think there is something unfinished with the cache (that seems to be not tested if travis-ci is green) but otherwise looks good to me!

@@ -46,7 +46,7 @@ public function generate(): Swagger
}

if ($this->cacheItemPool) {
$item = $this->cacheItemPool->getItem('swagger_doc');
$item = $this->cacheItemPool->getItem($cacheItemId ?? 'swagger_doc');
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think this will never do anything. ?? is like isset, not telling you that the variable does not exist. but cacheItemId will never exist in this context unless i am missing something. did you mean to store the constructor parameter andin the class and use $this->cacheItemId?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, I added tests to make sure it works. Will have to use it one day to have better perfs...

if (!$generatorLocator instanceof ContainerInterface) {
@trigger_error(sprintf('Providing an instance of "%s" to "%s()" is deprecated since version 3.1. Provide it an instance of "%s" instead.', ApiDocGenerator::class, __METHOD__, ContainerInterface::class), E_USER_DEPRECATED);
$generatorLocator = new ServiceLocator(['default' => function () use ($generatorLocator) {
return $generatorLocator;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this will only work if $generatorLocator is the ApiDocGenerator, right? i would typehint both and explain that the generator is still supported for BC. and do a typecheck before the deprecation to fail loudly if its not something we can work with.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

type hint added :)

Copy link
Collaborator
@dbu dbu left a comment

Choose a reason for hiding this comment

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

great! looks good now, feel free to squash and merge.

@GuilhemN GuilhemN merged commit 393a6c0 into master Jan 5, 2018
@GuilhemN GuilhemN deleted the newfeature branch January 5, 2018 12:08
@GuilhemN
Copy link
Collaborator Author
GuilhemN commented Jan 5, 2018

Thanks for all your reviews! :)

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

Successfully merging this pull request may close these issues.

2 participants
0