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

Add Subresource to swagger docs #1188

Closed
wants to merge 1 commit into from
Closed

Add Subresource to swagger docs #1188

wants to merge 1 commit into from

Conversation

pierredup
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets N/A
License MIT
Doc PR N/A

Display SubResources in the swagger docs

screen shot 2017-06-20 at 16 00 36


namespace ApiPlatform\Core\Metadata\Resource;

final class SubResourceMetadata
Copy link
Member

@soyuka soyuka Jun 20, 2017

Choose a reason for hiding this comment

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

Hmm this is a good idea. I didn't wanted to introduce a new Metadata class when I worked on subresources but this will give more power to subresource declarations (ping @teohhanhui ^^).

WDYT about going a bit further, so that PropertyMetadataFactory will create the SubResourceMetadata when it's declared as such? This is what the outcome may be in the code below:

$propertyMetadata = $this->propertyMetadataFactory->create($parentResourceClass, $property);
if ($propertyMetadata->hasSubresource()) {
        $subResourceMetadata = $propertyMetadata->getSubresource(); // this is an instance of SubResourceMetadata
}

With something like this we can avoid repeating the following code (for example also in ApiLoader):

$isCollection = $propertyMetadata->getType()->isCollection();
$resourceClass = $isCollection ? $propertyMetadata->getType()->getCollectionValueType()->getClassName() : $propertyMetadata->getType()->getClassName();

ping @api-platform/core-team

IMO we need to agree on this change first because it may involve many changes ^^. Anyway, if we introduce this new metadata class, it'd be a shame not to use it everywhere we can :).

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's worth it to introduce yet another metadata class.

In fact, I'd argue for the removal of PropertyMetadata::$subresource property. Just use an attribute.

$options = isset($serializerContext['groups']) ? ['serializer_groups' => $serializerContext['groups']] : [];
foreach ($this->propertyNameCollectionFactory->create($parentResourceClass, $options) as $property) {
$propertyMetadata = $this->propertyMetadataFactory->create($parentResourceClass, $property);
if ($propertyMetadata->hasSubresource()) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you use a guard clause to make the code easier to read?

if (!$propertyMetadata->hasSubresource()) {
    continue;
}

@soyuka soyuka mentioned this pull request Jul 4, 2017
@pierredup
Copy link
Contributor Author

Closing in favor of #1225

@pierredup pierredup closed this Jul 4, 2017
@pierredup pierredup deleted the swagger-subresource branch August 2, 2017 10:41
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.

None yet

4 participants