-
-
Notifications
You must be signed in to change notification settings - Fork 966
Ensure that api:openapi:export produces JSON with unescaped forward slashes
#3368
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
dunglas
merged 1 commit into
api-platform:2.5
from
Ocramius:fix/dump-openapi-schema-without-escaping-slashes
Jan 31, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
69 changes: 69 additions & 0 deletions
69
tests/Bridge/Symfony/Bundle/Command/SwaggerCommandUnitTest.php
This file contains hidden or 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,69 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the API Platform project. | ||
| * | ||
| * (c) Kévin Dunglas <dunglas@gmail.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace ApiPlatform\Core\Tests\Bridge\Symfony\Bundle\Command; | ||
|
|
||
| use ApiPlatform\Core\Bridge\Symfony\Bundle\Command\SwaggerCommand; | ||
| use ApiPlatform\Core\Documentation\Documentation; | ||
| use ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface; | ||
| use ApiPlatform\Core\Metadata\Resource\ResourceNameCollection; | ||
| use PHPUnit\Framework\MockObject\MockObject; | ||
| use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
| use Symfony\Component\Console\Input\ArrayInput; | ||
| use Symfony\Component\Console\Output\BufferedOutput; | ||
| use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
|
||
| class SwaggerCommandUnitTest extends KernelTestCase | ||
| { | ||
| /** @var MockObject&NormalizerInterface */ | ||
| private $normalizer; | ||
|
|
||
| /** @var ResourceNameCollectionFactoryInterface&MockObject */ | ||
| private $resources; | ||
|
|
||
| /** @var SwaggerCommand */ | ||
| private $command; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| $this->normalizer = $this->createMock(NormalizerInterface::class); | ||
| $this->resources = $this->createMock(ResourceNameCollectionFactoryInterface::class); | ||
| $this->command = new SwaggerCommand( | ||
| $this->normalizer, | ||
| $this->resources, | ||
| 'My API', | ||
| 'I told you already: it is my API', | ||
| 'one-zero-zero' | ||
| ); | ||
|
|
||
| $this->resources->method('create') | ||
| ->willReturn(new ResourceNameCollection()); | ||
| } | ||
|
|
||
| public function testDocumentationJsonDoesNotUseEscapedSlashes(): void | ||
| { | ||
| $this->normalizer->method('normalize') | ||
| ->with(self::isInstanceOf(Documentation::class)) | ||
| ->willReturn(['a-jsonable-documentation' => 'containing/some/slashes']); | ||
|
|
||
| $output = new BufferedOutput(); | ||
|
|
||
| $this->command->run(new ArrayInput([]), $output); | ||
|
|
||
| $jsonOutput = $output->fetch(); | ||
|
|
||
| self::assertJson($jsonOutput); | ||
| self::assertStringNotContainsString('containing\/some\/slashes', $jsonOutput); | ||
| self::assertStringContainsString('containing/some/slashes', $jsonOutput); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: a unit test was much simpler and efficient to write - the current integration test is not something I could work with anyway, since I don't run MongoDB on any system I maintain (including my dev environment) by choice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually there was a an attempt to remove the hard dev dependency to MongoDB (#2703), but it has been added again by #2843 (an issue with PHPStan it seems).
By default though, the Behat tests are run without MongoDB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope that can be achieved again at some point: for now, I'm happy with adding a unit test, and providing more unit tests in future, shall I encounter isolated issues, like this one.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to do this once we upgrade to phpstan
^0.12.4! 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, we still can't remove the MongoDB packages, because we'd get errors such as:
😞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ondrejmirtes Do you perhaps have any suggestions on how this could be resolved? I see there are MongoDB ODM stubs in https://github.com/phpstan/phpstan-doctrine/tree/master/stubs
Is there a way to tell phpstan that these types "exist" purely based on the stubs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #3431 for an attempt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'd have to make the class available for the autoloader. See: https://phpstan.org/user-guide/autoloading