forked from cebe/yii2-openapi
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from php-openapi/35-resolve-todo-re-check-opti…
…ons-route-in-fractal-action Resolve TODO: re-check options route in fractal action #35
- Loading branch information
Showing
20 changed files
with
650 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (c) 2018 Carsten Brandt <[email protected]> and contributors | ||
* @license https://github.com/cebe/yii2-openapi/blob/master/LICENSE | ||
*/ | ||
|
||
namespace cebe\yii2openapi\lib\items; | ||
|
||
trait OptionsRoutesTrait | ||
{ | ||
public function getOptionsRoute():string | ||
{ | ||
if ($this->prefix && !empty($this->prefixSettings)) { | ||
if (isset($this->prefixSettings['module'])) { | ||
$prefix = $this->prefixSettings['module']; | ||
return static::finalOptionsRoute($prefix, $this->controllerId); | ||
} elseif (isset($this->prefixSettings['namespace']) && str_contains($this->prefixSettings['namespace'], '\modules\\')) { # if `module` not present then check in namespace and then in path | ||
$prefix = static::computeModule('\\', $this->prefixSettings['namespace']); | ||
if ($prefix) { | ||
return static::finalOptionsRoute($prefix, $this->controllerId); | ||
} | ||
} elseif (isset($this->prefixSettings['path']) && str_contains($this->prefixSettings['path'], '/modules/')) { | ||
$prefix = static::computeModule('/', $this->prefixSettings['path']); | ||
if ($prefix) { | ||
return static::finalOptionsRoute($prefix, $this->controllerId); | ||
} | ||
} | ||
} | ||
return $this->controllerId.'/options'; | ||
} | ||
|
||
/** | ||
* @param string $separator | ||
* @param string $entity path or namespace | ||
* @return void | ||
*/ | ||
public static function computeModule(string $separator, string $entity): ?string | ||
{ | ||
$parts = explode($separator . 'modules' . $separator, $entity); # /app/modules/forum/controllers => /forum/controllers | ||
if (empty($parts[1])) { | ||
return null; | ||
} | ||
if (str_contains($parts[1], 'controller')) { | ||
$result = explode($separator . 'controller', $parts[1]); // compute everything in between "modules" and "controllers" e.g. api/v1 | ||
$result = array_map(function ($val) { | ||
return str_replace('\\', '/', $val); | ||
}, $result); | ||
} else { | ||
$result = explode($separator, $parts[1]); # forum/controllers => forum | ||
} | ||
if (empty($result[0])) { | ||
return null; | ||
} | ||
return $result[0]; | ||
} | ||
|
||
public static function finalOptionsRoute(string $prefix, string $controllerId): string | ||
{ | ||
return trim($prefix, '/') . '/' . $controllerId . '/options'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
tests/specs/issue_fix/35_resolve_todo_re_check_options_route_in_fractal_action/index.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
return [ | ||
'openApiPath' => '@specs/issue_fix/35_resolve_todo_re_check_options_route_in_fractal_action/index.yaml', | ||
'generateUrls' => true, | ||
'generateModels' => false, | ||
'excludeModels' => [ | ||
'Error', | ||
], | ||
'generateControllers' => true, | ||
'generateMigrations' => false, | ||
'useJsonApi' => false, | ||
'urlPrefixes' => [ | ||
'animals' => '', | ||
'/info' => ['module' => 'petinfo', 'namespace' => '\app\modules\petinfo\controllers'], | ||
'/forum' => ['namespace' => '\app\modules\forum\controllers'], # namespace contains "\modules\" | ||
'/forum2' => ['path' => '@app/modules/forum2/controllers', 'namespace' => '\app\forum2\controllers'], # path contains "/modules/" | ||
'/api/v1' => ['path' => '@app/modules/some/controllers', 'namespace' => '\app\api\v1\controllers'], # namespace contains "\modules\"; module will be "api/v1" | ||
'/api/v2' => ['path' => '@app/modules/api/v2/controllers', 'namespace' => '\app\some\controllers'], # namespace contains "\modules\"; module will be "api/v2" | ||
] | ||
]; |
177 changes: 177 additions & 0 deletions
177
tests/specs/issue_fix/35_resolve_todo_re_check_options_route_in_fractal_action/index.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
openapi: "3.0.0" | ||
info: | ||
version: 1.0.0 | ||
title: Swagger Petstore | ||
license: | ||
name: MIT | ||
servers: | ||
- url: http://petstore.swagger.io/v1 | ||
paths: | ||
/api/v1/pets: | ||
get: | ||
summary: List all pets | ||
operationId: listPets | ||
tags: | ||
- pets | ||
parameters: | ||
- name: limit | ||
in: query | ||
description: How many items to return at one time (max 100) | ||
required: false | ||
schema: | ||
type: integer | ||
format: int32 | ||
responses: | ||
'200': | ||
description: A paged array of pets | ||
headers: | ||
x-next: | ||
description: A link to the next page of responses | ||
schema: | ||
type: string | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Pets" | ||
default: | ||
description: unexpected error | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Error" | ||
post: | ||
summary: Create a pet | ||
operationId: createPets | ||
tags: | ||
- pets | ||
responses: | ||
'201': | ||
description: Null response | ||
default: | ||
description: unexpected error | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Error" | ||
/animals/pets/{id}: | ||
parameters: | ||
- name: id | ||
in: path | ||
required: true | ||
description: The id of the pet to update | ||
schema: | ||
type: string | ||
get: | ||
summary: Info for a specific pet | ||
operationId: showPetById | ||
tags: | ||
- pets | ||
responses: | ||
'200': | ||
description: Expected response to a valid request | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Pet" | ||
default: | ||
description: unexpected error | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Error" | ||
patch: | ||
summary: update a specific pet | ||
operationId: updatePetById | ||
tags: | ||
- pets | ||
responses: | ||
'200': | ||
description: The updated pet | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Pet" | ||
delete: | ||
summary: delete a specific pet | ||
operationId: deletePetById | ||
tags: | ||
- pets | ||
responses: | ||
'204': | ||
description: successfully deleted pet | ||
/petComments: | ||
get: | ||
description: list all pet comments | ||
responses: | ||
'200': | ||
description: list of comments | ||
/info/pet-details: | ||
get: | ||
description: list all pet details | ||
responses: | ||
'200': | ||
description: list of details | ||
/forum/pet2-details: | ||
get: | ||
description: list all pet details | ||
responses: | ||
'200': | ||
description: list of details | ||
/forum2/pet3-details: | ||
get: | ||
description: list all pet details | ||
responses: | ||
'200': | ||
description: list of details | ||
/api/v2/comments: | ||
get: | ||
description: list all pet details | ||
responses: | ||
'200': | ||
description: list of details | ||
|
||
components: | ||
schemas: | ||
Pet: | ||
description: A Pet | ||
required: | ||
- id | ||
- name | ||
properties: | ||
id: | ||
type: integer | ||
format: int64 | ||
readOnly: True | ||
name: | ||
type: string | ||
store: | ||
$ref: '#/components/schemas/Store' | ||
tag: | ||
type: string | ||
x-faker: "$faker->randomElement(['one', 'two', 'three', 'four'])" | ||
Store: | ||
description: A store's description | ||
required: | ||
- id | ||
- name | ||
properties: | ||
id: | ||
type: integer | ||
format: int64 | ||
readOnly: True | ||
name: | ||
type: string | ||
Pets: | ||
type: array | ||
items: | ||
$ref: "#/components/schemas/Pet" | ||
Error: | ||
required: | ||
- code | ||
- message | ||
properties: | ||
code: | ||
type: integer | ||
format: int32 | ||
message: | ||
type: string |
25 changes: 25 additions & 0 deletions
25
...e_fix/35_resolve_todo_re_check_options_route_in_fractal_action/mysql/config/urls.rest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* OpenAPI UrlRules | ||
* | ||
* This file is auto generated. | ||
*/ | ||
return [ | ||
'GET api/v1/pets' => 'api/v1/pet/list', | ||
'POST api/v1/pets' => 'api/v1/pet/create', | ||
'GET animals/pets/<id:[\w-]+>' => 'pet/view', | ||
'DELETE animals/pets/<id:[\w-]+>' => 'pet/delete', | ||
'PATCH animals/pets/<id:[\w-]+>' => 'pet/update', | ||
'GET petComments' => 'pet-comment/list', | ||
'GET info/pet-details' => 'petinfo/pet-detail/list', | ||
'GET forum/pet2-details' => 'forum/pet2-detail/list', | ||
'GET forum2/pet3-details' => 'forum2/pet3-detail/list', | ||
'GET api/v2/comments' => 'api/v2/comment/list', | ||
'api/v1/pets' => 'some/pet/options', | ||
'animals/pets/<id:[\w-]+>' => 'pet/options', | ||
'petComments' => 'pet-comment/options', | ||
'info/pet-details' => 'petinfo/pet-detail/options', | ||
'forum/pet2-details' => 'forum/pet2-detail/options', | ||
'forum2/pet3-details' => 'forum2/pet3-detail/options', | ||
'api/v2/comments' => 'api/v2/comment/options', | ||
]; |
20 changes: 20 additions & 0 deletions
20
..._todo_re_check_options_route_in_fractal_action/mysql/controllers/PetCommentController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace app\controllers; | ||
|
||
class PetCommentController extends \app\controllers\base\PetCommentController | ||
{ | ||
|
||
public function checkAccess($action, $model = null, $params = []) | ||
{ | ||
//TODO implement checkAccess | ||
} | ||
|
||
public function actionList() | ||
{ | ||
//TODO implement actionList | ||
} | ||
|
||
|
||
} | ||
|
Oops, something went wrong.