-
-
Notifications
You must be signed in to change notification settings - Fork 836
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(2056): support opt out of JMS serializer usage (#2342)
| Q | A | |---------------|---------------------------------------------------------------------------------------------------------------------------| | Bug fix? | no | | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | | Issues | Fix #2056 #2341 <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | <!-- Replace this notice by a description of your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally: - Always add tests and ensure they pass. - For new features, provide some code snippets to help understand usage. --> Always registers `JMSModelDescriber` when the bundle is active, independently of the configured global `models.use_jms` option. If `models.use_jms` is set, then `JMSModelDescriber` will be added with a priority of 50, just as before. If `models.use_jms` is not set, it will be added with -50 so that `ObjectModelDescriber` is used instead. This should not lead to any behavior change. Adds support to `options.useJms` in the model by early exiting in either `JMSModelDescriber` or `ObjectModelDescriber` when it is either explicitly `false` or `true`. Together with the priorities of the describer this allows to have either JMS or Symfony serializer as default and switch per model if necessary. In #2341 I played around with this in an app and it worked as expected. (sorry btw, I'm a fan of rebase + force-push and realized too late that mentioning the issue in the first commit is a bad idea then because GitHub spams whenever I push..) Closes #2056 Closes #2341 --------- Co-authored-by: djordy <[email protected]>
- Loading branch information
1 parent
5eda246
commit 322c47b
Showing
7 changed files
with
341 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
nelmio_api_doc: | ||
models: | ||
use_jms: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the NelmioApiDocBundle package. | ||
* | ||
* (c) Nelmio | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nelmio\ApiDocBundle\Tests\Functional\Controller; | ||
|
||
use Nelmio\ApiDocBundle\Annotation\Model; | ||
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSUser; | ||
use OpenApi\Attributes as OA; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
#[Route(host: 'api.example.com')] | ||
final class JmsOptOutController | ||
{ | ||
#[Route('/api/jms', methods: ['GET'])] | ||
#[OA\Response( | ||
response: 200, | ||
description: 'Success', | ||
content: new Model(type: JMSUser::class) | ||
)] | ||
public function jms() | ||
{ | ||
} | ||
|
||
#[Route('/api/jms_opt_out', methods: ['GET'])] | ||
#[OA\Response( | ||
response: 200, | ||
description: 'Success', | ||
content: new Model(type: JMSUser::class, serializationContext: ['useJms' => false]) | ||
)] | ||
public function jmsOptOut() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.