-
-
Notifications
You must be signed in to change notification settings - Fork 903
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
Fix path for custom operation with Swagger UI #1192
Conversation
537a3b2
to
1b31a5c
Compare
a6755f1
to
806deaa
Compare
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.
Just a little comment but LGTM
{ | ||
const ROUTE_NAME_PREFIX = 'api_'; | ||
|
||
private function __construct() |
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.
why ?
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.
Static class. Should this class be moved to Util
?
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 don't think it should be moved to Util, it's a right place here ;)
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.
private constructor does prevent the class from being instantiated no? I think it's the point here :p.
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.
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. |
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.
indentation
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 would merge this patch in 2.1, WDYT? I don't like to introduce deprecations in patch releases.
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.
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 |
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.
Oh okay we're on 2.0
here. We need to change the collection
flag to an OperationType
when merging this on master IMO.
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 my previous comment (we should merge this only in master IMO)
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.
So they will upgrade to 2.1 :P
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.
😄 Okay, I'll update the base branch, and my PR.
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.
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.
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.
Not so easy with sub resources 😢
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 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!
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.
Are sub resources not exposed by Swagger UI? 😮
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.
Not yet but we've an open pr here: #1188
806deaa
to
568ab59
Compare
@@ -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> |
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.
<argument />
is enough IIRC
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.
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. |
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 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 |
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.
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 |
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 my previous comment (we should merge this only in master IMO)
568ab59
to
c1c2e6d
Compare
5fc0e5e
to
daa672e
Compare
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 |
daa672e
to
7114ebb
Compare
Amazing work! Thank you very much for this fix and this cleanup @meyerbaptiste!! |
{ | ||
if (OperationType::SUBRESOURCE === $operationType = OperationTypeDeprecationHelper::getOperationType($operationType)) { | ||
throw new InvalidArgumentException(sprintf('%s::SUBRESOURCE is not supported as operation type by %s().', OperationType::class, __METHOD__)); | ||
} |
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.
@meyerbaptiste I have to remove this basically and use this class in the RouterOperationPathResolver?
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.
Yes, ideally...
…ustom_operation_path Fix path for custom operation with Swagger UI
A fix while waiting for Swagger 3 which will permit overriding the base path at the path item level.
See: