core icon indicating copy to clipboard operation
core copied to clipboard

[OpenApi] Subresource path description wrong/missleading

Open KDederichs opened this issue 4 years ago • 5 comments

API Platform version(s) affected: 2.6.8 Description
Assuming you have the following classes:

#[ApiResource]
class Project {
    ...
    #[OneToMany(mappedBy: 'project', targetEntity: Transaction::class)]
    #[ApiSubresource]
   private Collection $collectionOfB;
}

#[ApiResource]
class Transaction {
   ...
    #[ManyToOne(targetEntity: A::class)]
    #[JoinColumn(name: 'project_id', referencedColumnName: 'id'')]
   private Project $project;
}

You'd expect the openApi to generate generate the subresource to be something like this:

[/api/projects/{id}/transactions] Retrieves a collection of Transaction resources.

You'll actually get this though: Screenshot 2022-02-22 at 16 12 20

How to reproduce
Setup a subresource as described above and go to the api docs.

Possible Solution
n.A

Additional Context
n.A

KDederichs avatar Feb 22 '22 15:02 KDederichs

The expected and the actual looks the same to me - I see no difference.

henrikac avatar Jun 17 '22 12:06 henrikac

@henrikac It's in the description, if you looks closely on the picture it says 'Receives a PROJECT resource' while it should say Transaction.

KDederichs avatar Jun 19 '22 06:06 KDederichs

@KDederichs oh, I see. I thought you were talking about the url. I did not learn about the subresource in api platform until like a week ago and my experience so far has been that they are difficult to configure.

henrikac avatar Jun 19 '22 16:06 henrikac

tbh from what I've seen at the Symfony Live it might be mute with 2.7/3.0 anyways since they're scrapping the current sub resources, though maybe the same thing also occurs with the new Link attribute

KDederichs avatar Jun 19 '22 20:06 KDederichs

I don't know if you have found a solution but this worked for me

#[ApiResource(
  subresourceOperations: [
    'collection_of_b_get_subresource' => [
      'openapi_context' => [
        'description' => 'Retrieves a collection of Transaction resources',
        'summary' => 'Retrieves a collection of Transaction resources',
      ],
    ],
  ],
)]
class Product
{
  // ...
}

The name of subresources (if you run debug:router) will all begin with api_<api_resource_class>_<subresource_property_name>_get_subresource but when you try to customize the subresource in subresourceOperations you have to omit the api_<api_resource_class>_ prefix.

See #3458 for more details.

henrikac avatar Jun 20 '22 08:06 henrikac

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 04 '22 21:11 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 04 '23 01:01 stale[bot]