Skip to content

Fix path for custom operation with Swagger UI #1192

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

Conversation

meyerbaptiste
Copy link
Member

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

A fix while waiting for Swagger 3 which will permit overriding the base path at the path item level.
See:

@meyerbaptiste meyerbaptiste force-pushed the fix_swagger_custom_operation_path branch from 537a3b2 to 1b31a5c Compare June 21, 2017 18:08
@meyerbaptiste meyerbaptiste force-pushed the fix_swagger_custom_operation_path branch 2 times, most recently from a6755f1 to 806deaa Compare June 22, 2017 08:34
Copy link
Contributor

@Simperfit Simperfit left a comment

Choose a reason for hiding this comment

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

Just a little comment but LGTM

{
const ROUTE_NAME_PREFIX = 'api_';

private function __construct()
Copy link
Contributor

Choose a reason for hiding this comment

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

why ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Static class. Should this class be moved to Util?

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 should be moved to Util, it's a right place here ;)

Copy link
Member

Choose a reason for hiding this comment

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

private constructor does prevent the class from being instantiated no? I think it's the point here :p.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, right! Recipe for static classes:

  • final class
  • private constructor
  • static attributes/methods

@@ -35,6 +34,10 @@
*/
final class ApiLoader extends Loader
{
/**
* @deprecated since version 2.0.10, to be removed in 3.0.
* Use {@see RouteNameGenerator::ROUTE_NAME_PREFIX} instead.
Copy link
Member

Choose a reason for hiding this comment

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

indentation

Copy link
Member

Choose a reason for hiding this comment

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

I would merge this patch in 2.1, WDYT? I don't like to introduce deprecations in patch releases.

Copy link
Member Author

Choose a reason for hiding this comment

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

As you want, but this bug seems critic for many people (cf issue).

*
* @return string
*/
public static function generate(string $operationName, string $resourceShortName, bool $collection): string
Copy link
Member

Choose a reason for hiding this comment

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

Oh okay we're on 2.0 here. We need to change the collection flag to an OperationType when merging this on master IMO.

Copy link
Member

Choose a reason for hiding this comment

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

See my previous comment (we should merge this only in master IMO)

Copy link
Member

Choose a reason for hiding this comment

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

So they will upgrade to 2.1 :P

Copy link
Member Author

Choose a reason for hiding this comment

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

😄 Okay, I'll update the base branch, and my PR.

Copy link
Member

Choose a reason for hiding this comment

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

Oh okay @dunglas didn't saw your comment, and I'm 👍 on merging this in master! So yes, please drop the bool $collection for an OperationType :D.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not so easy with sub resources 😢

Copy link
Member

Choose a reason for hiding this comment

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

I can take care of it if you want, anyway I want to refactor some parts and introduce Subresource metadata which should make things easier. For now, you can just support Item and Collection!

Copy link
Member Author

Choose a reason for hiding this comment

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

Are sub resources not exposed by Swagger UI? 😮

Copy link
Member

Choose a reason for hiding this comment

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

Not yet but we've an open pr here: #1188

@meyerbaptiste meyerbaptiste force-pushed the fix_swagger_custom_operation_path branch from 806deaa to 568ab59 Compare June 22, 2017 12:26
@@ -13,7 +13,7 @@
<argument type="service" id="api_platform.resource_class_resolver" />
<argument type="service" id="api_platform.operation_method_resolver" />
<argument type="service" id="api_platform.operation_path_resolver" />
<argument type="service" id="api_platform.router" />
<argument>null</argument>
Copy link
Member

Choose a reason for hiding this comment

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

<argument /> is enough IIRC

Copy link
Member Author

Choose a reason for hiding this comment

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

An empty string is dumped with <argument />...

@@ -35,6 +34,10 @@
*/
final class ApiLoader extends Loader
{
/**
* @deprecated since version 2.0.10, to be removed in 3.0.
* Use {@see RouteNameGenerator::ROUTE_NAME_PREFIX} instead.
Copy link
Member

Choose a reason for hiding this comment

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

I would merge this patch in 2.1, WDYT? I don't like to introduce deprecations in patch releases.

*
* @author Baptiste Meyer <baptiste.meyer@gmail.com>
*/
class RouteNameGenerator
Copy link
Member

Choose a reason for hiding this comment

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

Can we mark this class @internal, I don't like public static classes.

*
* @return string
*/
public static function generate(string $operationName, string $resourceShortName, bool $collection): string
Copy link
Member

Choose a reason for hiding this comment

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

See my previous comment (we should merge this only in master IMO)

@meyerbaptiste meyerbaptiste force-pushed the fix_swagger_custom_operation_path branch from 568ab59 to c1c2e6d Compare June 23, 2017 19:25
@meyerbaptiste meyerbaptiste changed the base branch from 2.0 to master June 23, 2017 19:26
@meyerbaptiste meyerbaptiste force-pushed the fix_swagger_custom_operation_path branch 2 times, most recently from 5fc0e5e to daa672e Compare June 23, 2017 19:42
@meyerbaptiste
Copy link
Member Author

Okay, the PR is ready with the master branch and ready for review.

I didn't take care of sub-resources. IMO we can add the support of these ones when the DocumentationNormalizer will support them.

@meyerbaptiste meyerbaptiste force-pushed the fix_swagger_custom_operation_path branch from daa672e to 7114ebb Compare June 23, 2017 20:03
@dunglas
Copy link
Member

dunglas commented Jun 26, 2017

Amazing work! Thank you very much for this fix and this cleanup @meyerbaptiste!!

@dunglas dunglas merged commit fd1a553 into api-platform:master Jun 26, 2017
@meyerbaptiste meyerbaptiste deleted the fix_swagger_custom_operation_path branch June 26, 2017 20:03
{
if (OperationType::SUBRESOURCE === $operationType = OperationTypeDeprecationHelper::getOperationType($operationType)) {
throw new InvalidArgumentException(sprintf('%s::SUBRESOURCE is not supported as operation type by %s().', OperationType::class, __METHOD__));
}
Copy link
Member

Choose a reason for hiding this comment

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

@meyerbaptiste I have to remove this basically and use this class in the RouterOperationPathResolver?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, ideally...

hoangnd25 pushed a commit to hoangnd25/core that referenced this pull request Feb 23, 2018
…ustom_operation_path

Fix path for custom operation with Swagger UI
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.

4 participants