-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[Slim] Abstract API controllers #1483
[Slim] Abstract API controllers #1483
Conversation
Few things that bothers me:
|
(I'm sorry if the comment below missing the point, I'm not familiar with Slim.) 1.I prefer that doesn't add CLI option to disable that feature as I think it is better to keep options less and also we can do it later. 2.
I prefer to avoid the misunderstanding via add "Abstract" prefix to both
I think the helper function that dynamically strips out "Abstract" prefix isn't necessarily have to add. The concrete class name which implements the abstract class is determined by the users. How about the simple exception message without "How about implementing call123TestSpecialTags as a PATCH method?" 3.Totally agree with you. |
|
2.Thanks for the details! I understand the importance that force user to stick with predefined Quick idea: How about indicate "Abstract" in namespace (folder name) instead of class name? // lib/Api/AbstractFakeApi.php
namespace OpenAPIServer\Api;
abstract class AbstractFakeApi
{
} ↓↓↓ // lib/Abstracts/FakeApi.php
namespace OpenAPIServer\Abstracts;
abstract class FakeApi
{
} 3.I'm sorry I didn't explain enough. 💦 I agree with that generate unit tests for both implementation and abstract classes is overkill. Generating unit tests only for implementation class (predefined |
I was inspited by PSR Naming Conventions. I think it's a good practice.
|
Yeah, I don't think also put "Abstract" in namespace is best way. It's just an idea while thinking about Another idea: How about force the prefix as The naming conventions says "Abstract classes MUST be prefixed by Abstract". |
Actually, right now we don't have an option to change By the way, additional property |
There are two ways to solve this issue:
I've ended up that PHP helper function to parse implementation classname from abstract classname isn't enough, because there will be many cases when that implementation classname required in mustaches(readme.md etc.), so it should be in codegen itself. UPD: |
862b7d2
to
cce46f3
Compare
Feature branch has been rebased on latest 4.0.x branch. Please, review that PR, because I need to submit two more before 4.0.0 release. |
This PR has been submitted before @renepardon joined community, but I think he can review this changes too. |
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.
Looks good to me 👍
Oh, this PR may have to target |
cce46f3
to
eb8f5d9
Compare
eb8f5d9
to
a3ebb61
Compare
👍 👍 |
* [Slim] Add abstract prefix to API controllers * [Slim] Add userClassname property to codegen * [Slim] Add src folder to Composer autoload * [Slim] Change template to produce abstract controllers * [Slim] Update API tests template * [Slim] Add implementation note * [Slim] Remove deprecated AbstractApiController * [Slim] Refresh samples
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.master
,3.4.x
,4.0.x
. Default:master
.Description of the PR
Inspired by #426
Generator produces abstract API controller classes which needs to be extended by implementation classes in
./src
folder.When implementation class doesn't exist application throws exception:
Upgrade note
Do not modify abstract API controllers directly! Instead extend them by implementation classes like:
Place all your implementation classes in
./src
folder accordingly.For instance, when abstract class located at
./lib/Api/AbstractPetApi.php
you need to create implementation class at./src/Api/PetApi.php
.Run
$ composer dump-autoload
every time your create new class.To show error details with Slim modify
index.php
:cc @jebentier @dkarlovi @mandrean @jfastnacht @ackintosh