-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Core\Bridge\Symfony\Routing; | ||
|
||
use ApiPlatform\Core\Api\OperationType; | ||
use ApiPlatform\Core\Api\OperationTypeDeprecationHelper; | ||
use ApiPlatform\Core\Exception\InvalidArgumentException; | ||
use Doctrine\Common\Util\Inflector; | ||
|
||
/** | ||
* Generates the Symfony route name associated with an operation name and a resource short name. | ||
* | ||
* @internal | ||
* | ||
* @author Baptiste Meyer <baptiste.meyer@gmail.com> | ||
*/ | ||
class RouteNameGenerator | ||
{ | ||
const ROUTE_NAME_PREFIX = 'api_'; | ||
|
||
private function __construct() | ||
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. why ? 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. Static class. Should this class be moved to 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. 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Yep, right! Recipe for static classes:
|
||
{ | ||
} | ||
|
||
/** | ||
* Generates a Symfony route name. | ||
* | ||
* @param string $operationName | ||
* @param string $resourceShortName | ||
* @param string|bool $operationType | ||
* | ||
* @throws InvalidArgumentException | ||
* | ||
* @return string | ||
*/ | ||
public static function generate(string $operationName, string $resourceShortName, $operationType): string | ||
{ | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Yes, ideally... |
||
|
||
return sprintf( | ||
'%s%s_%s_%s', | ||
static::ROUTE_NAME_PREFIX, | ||
Inflector::pluralize(Inflector::tableize($resourceShortName)), | ||
$operationName, | ||
$operationType | ||
); | ||
} | ||
} |
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 IIRCThere 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 />
...