-
-
Notifications
You must be signed in to change notification settings - Fork 849
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
Swagger Path Identifier to reflect the annotation of ApiProperty(identifier=true) #1367
Closed
Closed
Changes from 1 commit
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 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 |
---|---|---|
|
@@ -48,6 +48,7 @@ | |
use Symfony\Component\Serializer\NameConverter\NameConverterInterface; | ||
|
||
/** | ||
* @author Philippe Guilbault <philippe.guilbault@gmail.com> | ||
* @author Amrouche Hamza <hamza.simperfit@gmail.com> | ||
* @author Kévin Dunglas <dunglas@gmail.com> | ||
*/ | ||
|
@@ -1823,4 +1824,129 @@ public function testNormalizeWithSubResource() | |
|
||
$this->assertEquals($expected, $normalizer->normalize($documentation)); | ||
} | ||
|
||
/** | ||
* | ||
* @group yourmom | ||
*/ | ||
public function testNormalizeWithIdentifierName() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a test with composite identifiers? |
||
{ | ||
$documentation = new Documentation(new ResourceNameCollection([Dummy::class]), '', '', '0.0.0', ['jsonld' => ['application/ld+json']]); | ||
|
||
$propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class); | ||
$propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->shouldBeCalled()->willReturn(new PropertyNameCollection(['id', 'name', 'description'])); | ||
|
||
$dummyMetadata = new ResourceMetadata( | ||
'Dummy', | ||
'This is a dummy.', | ||
'http://schema.example.com/Dummy', | ||
['get' => ['method' => 'GET']], | ||
[], | ||
[] | ||
); | ||
$resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataFactoryInterface::class); | ||
$resourceMetadataFactoryProphecy->create(Dummy::class)->shouldBeCalled()->willReturn($dummyMetadata); | ||
|
||
$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class); | ||
$propertyMetadataFactoryProphecy->create(Dummy::class, 'id')->shouldBeCalled()->willReturn(new PropertyMetadata( | ||
new Type(Type::BUILTIN_TYPE_INT), | ||
'This is an id.', | ||
true, | ||
false, | ||
null, | ||
null, | ||
false | ||
)); | ||
$propertyMetadataFactoryProphecy->create(Dummy::class, 'name')->shouldBeCalled()->willReturn(new PropertyMetadata( | ||
new Type(Type::BUILTIN_TYPE_STRING), | ||
'This is a name.', | ||
true, | ||
false, | ||
null, | ||
null, | ||
true, | ||
true | ||
)); | ||
$propertyMetadataFactoryProphecy->create(Dummy::class, 'description')->shouldBeCalled()->willReturn(new PropertyMetadata( | ||
new Type(Type::BUILTIN_TYPE_STRING), | ||
'This is a description.', | ||
true, | ||
true | ||
)); | ||
|
||
$resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class); | ||
$resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true); | ||
|
||
$operationMethodResolverProphecy = $this->prophesize(OperationMethodResolverInterface::class); | ||
$operationMethodResolverProphecy->getItemOperationMethod(Dummy::class, 'get')->shouldBeCalled()->willReturn('GET'); | ||
|
||
$urlGeneratorProphecy = $this->prophesize(UrlGeneratorInterface::class); | ||
//$urlGeneratorProphecy->generate('api_entrypoint')->willReturn('/')->shouldBeCalled(); | ||
|
||
$operationPathResolver = new CustomOperationPathResolver(new UnderscoreOperationPathResolver()); | ||
|
||
$normalizer = new DocumentationNormalizer( | ||
$resourceMetadataFactoryProphecy->reveal(), | ||
$propertyNameCollectionFactoryProphecy->reveal(), | ||
$propertyMetadataFactoryProphecy->reveal(), | ||
$resourceClassResolverProphecy->reveal(), | ||
$operationMethodResolverProphecy->reveal(), | ||
$operationPathResolver, | ||
$urlGeneratorProphecy->reveal() | ||
); | ||
|
||
$expected = array ( | ||
'swagger' => '2.0', | ||
'basePath' => '/', | ||
'info' => ['title' => '', 'version' => '0.0.0', ], | ||
'paths' => new \ArrayObject([ | ||
'/dummies/{id}' => [ | ||
'get' => new \ArrayObject([ | ||
'tags' => ['Dummy'], | ||
'operationId' => 'getDummyItem', | ||
'produces' => ['application/ld+json'], | ||
'summary' => 'Retrieves a Dummy resource.', | ||
'parameters' => [[ | ||
'name' => 'name', | ||
'type' => 'string', | ||
'in' => 'path', | ||
'required' => true, | ||
]], | ||
'responses' => [ | ||
200 => [ | ||
'description' => 'Dummy resource response', | ||
'schema' => ['$ref' => '#/definitions/Dummy'], | ||
], | ||
404 => ['description' => 'Resource not found'], | ||
], | ||
]), | ||
], | ||
]), | ||
'definitions' => new \ArrayObject([ | ||
'Dummy' => new \ArrayObject([ | ||
'type' => 'object', | ||
'description' => 'This is a dummy.', | ||
'externalDocs' => ['url' => 'http://schema.example.com/Dummy'], | ||
'properties' => [ | ||
'id' => new \ArrayObject([ | ||
'readOnly' => true, | ||
'description' => 'This is an id.', | ||
'type' => 'integer', | ||
]), | ||
'name' => new \ArrayObject([ | ||
'readOnly' => true, | ||
'description' => 'This is a name.', | ||
'type' => 'string', | ||
]), | ||
'description' => new \ArrayObject([ | ||
'description' => 'This is a description.', | ||
'type' => 'string', | ||
]), | ||
], | ||
]), | ||
]), | ||
); | ||
|
||
$this->assertEquals($expected, $normalizer->normalize($documentation)); | ||
} | ||
} |
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.
We have an issue on composite identifiers here. Indeed, a composite identifier would be written as a string (for example
foo=1;bar=2
). With this code, the identifier would only bebar
./About the
id
name, I think it's like this so that it's being used in the path from Swagger. I'm not sure how Swagger is identifying the url parameter like this.You could maybe reuse the same code from a new method instead of repeating it.