-
Notifications
You must be signed in to change notification settings - Fork 23
How to generate controller code with distinct method names in case of prefix in paths #84
Comments
Seems there is no way. This route is out of json-api resource conception. GET /domains Also GET /calendar/{calendarId}/domains |
Or do you assume REST usage, without JsonApi? But anyway - we need to detect and support CRUD operations (list/view/create/update/delete) and non-crud operations like /password/recovery/{token} /confirm/email/{email} /avatar/upload/{id} |
As of now I need to use with JSON:API. I am using your package. It is very helpful. Generic actions fulfil my most use-cases. I am using it most to avoid custom actions. regarding above end-points: Calendar in not model or a DB table in my use-case as of now. It is just a prefix. |
So, prefixes are not supported. We expects that a resource name is a single world You can use GET /domains or GET /calendar-domains or GET /calendar/domains/list |
If we will start supporting prefixed resource routes, But now @cebe what you think? |
JSON-API itself does not really say anything about URL design in this case. https://jsonapi.org/recommendations/#urls
it should probably be a configuration option to allow specifying grouping prefixes. If the API contains these prefixes a configuration could decide what to do with it. In some cases it might also make sense to generate Modules from URL prefixes. So for example: $urlPrefixes = [
'calendar' => '', // drop prefix, create controller in main app
'order' => 'order', // create controller in the order module
'base/auth' => 'auth', // create controller in the auth module
'auth' => 'auth/base', // create controller in the base/auth module - not sure if this case is needed (never used submodules in any application)
] |
It is not clear about the "base/auth module" We can define Namespace and path should be resolved from Yii::$app->getModule('moduleName')->controllerNamespace etc/ or we need explicit |
good point, we might need to generate the module if it does not exist so we have no idea about namespaces and paths. We could allow both, string for module name and use default assumptions about naming and path. and allow array configuration for more detailed config. |
I suggest to make module creation for every prefix optional. Example: Lets take my above I need I just need it as prefix. Path Current code generation Yii2-app-api for
this is fine
Now coming to main question that is present in issue description. How to generate distinct function name for case like:
This should be taken care of by code generator. A thought of mine: GET /calendar/domains => CalendarController/actionDomains To achieve this I think we can use
new GroupUrlRule([
'prefix' => 'calendar',
'routePrefix' => '',
'rules' => [
'GET domains' => 'calendar/domains',
'GET domains/<id:\d+>' => 'calendar/domain-by-id',
...
],
]); |
Yes, module definition will be optional.
But what by you mind should be for |
You mean to ask what are my thoughts about controller and action for below paths? If yes, then I think we can name it like:
|
I don't get why these routes should not generate DomainControlller with actionList(), actionCreate(), actionUpdate()... do you suggest do provide GroupUrlRule in config to determine generated routes, controller and action from it? |
I have use-case like below
calendar
is just the prefixHere the base controller generates:
Two method with same name leads to errors.
How can code generation for above end-points can be achieved?
The text was updated successfully, but these errors were encountered: