Skip to content

Add config option to convert operationIds into camel case #5

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/swagger-generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@
'ignoredAnnotationNames' => ['mixin'],
/*
|---------------------------------------------------------
| Use camel case for operation IDs instead of dots
|---------------------------------------------------------
*/
'camelCaseOperationIds' => false,
/*
|---------------------------------------------------------
| List of classes to additionally generate definitions
|---------------------------------------------------------
|
Expand Down
8 changes: 6 additions & 2 deletions src/RoutesParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public function parse(): array
$matches = config('swagger-generator.routes.matches', []);
$matchesNot = config('swagger-generator.routes.notMatches', []);
$documentedMethods = config('swagger-generator.routes.methods', ['GET']);
$camelCaseOperationIds = config('swagger-generator.camelCaseOperationIds', false);
$this->routeNum = 1;
foreach ($this->routes as $route) {
if (! $this->checkRoute($route, $matches, $matchesNot, $only, $except)) {
Expand All @@ -98,7 +99,7 @@ public function parse(): array
if ($ref instanceof \ReflectionFunction) {
$this->trigger(static::EVENT_PROBLEM_FOUND, static::PROBLEM_ROUTE_CLOSURE, $route);
}
$this->parseRoute($paths, $route, $documentedMethods, $this->routeNum);
$this->parseRoute($paths, $route, $documentedMethods, $this->routeNum, $camelCaseOperationIds);
++$this->routeNum;
$this->trigger(static::EVENT_ROUTE_PROCESSED, $route);
}
Expand All @@ -116,7 +117,7 @@ public function parse(): array
* @param int $num
* @return array
*/
protected function parseRoute(array &$data, Route $route, array $documentedMethods, int $num = 1): array
protected function parseRoute(array &$data, Route $route, array $documentedMethods, int $num = 1, bool $camelCaseOperationIds = false): array
{
$routeWoBody = ! empty(array_intersect(['GET', 'HEAD'], $route->methods));
$routeData = [
Expand Down Expand Up @@ -151,6 +152,9 @@ protected function parseRoute(array &$data, Route $route, array $documentedMetho

$tag = ! empty($routeData['tags']) ? reset($routeData['tags']) : 'default';
$routeData['operationId'] = $this->getRouteId($route, $tag);
if ($camelCaseOperationIds) {
$routeData['operationId'] = Str::camel(str_replace('.', '_', $routeData['operationId']));
}
$path = $this->normalizeUri($route->uri(), true);
$methods = array_intersect($route->methods, $documentedMethods);
$dataRows = [
Expand Down