API Tools fresh install can't create RCP
haclong opened this issue · 5 comments
Bug Report
i have a fresh install of API Tools
use built in PHP server
got a 422 HTTP error when i create new Rpc Service to my API
Q | A |
---|---|
PHP | 8.1.2 |
API Tools | ^1.6.0 (in composer) |
API Tools Admin | ^2.0.1 (in composer) |
Summary
I create project with API Tools
Followed the getting started tutorial
Adding a new API is ok (with the built in php server)
Adding a new REST service is ok
Adding a new RPC service is KO
Current behavior
How to reproduce
composer create-project laminas-api-tools/api-tools-skeleton my-project-directory
cd my-project-directory
composer update
composer serve
composer development-enable
log in http://localhost:8080/api-tools/ui#/
Create new API -> ok
Create new RPC service -> 422 Unprocessable Entity error
Expected behavior
add new RPC Service should create the RPC service (Controller and factory)
during my previous attempts, i DID have the Controller and the Controller Factory created but not with my last attempt, (the only one left since i have made TOO MANY changes to the previous attempt...
With last attempt,
Nothing has been added to module.config.php
No Controller nor Controller Factory has been generated
Here is the Request Headers
POST /api-tools/api/module/First/rpc HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0
Accept: application/json
Accept-Language: en,en-US;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: application/json
Content-Length: 55
Origin: http://localhost:8080
DNT: 1
Connection: keep-alive
Referer: http://localhost:8080/api-tools/ui
Cookie: laminas-hidden=0
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
Pragma: no-cache
Cache-Control: no-cache
Here the Response Headers
HTTP/1.1 422 Unprocessable Content
Host: localhost:8080
Date: Mon, 26 Jun 2023 20:50:24 GMT
Connection: close
X-Powered-By: PHP/8.1.2-1ubuntu2.11
Content-Type: application/problem+jsonf
Here's the Response body
{
"validation_messages": {
"controller_class": ["The Controller Class must be a valid, fully qualified, PHP class name"],
"accept_whitelist":["The Accept Whitelist must be an array of valid media type expressions"],
"content_type_whitelist":["The Content-Type Whitelist must be an array of valid media type expressions"],
"http_methods":["The HTTP Methods must be an array of valid HTTP method names"]
},
"type":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
"title":"Unprocessable Entity",
"status":422,
"detail":"Failed Validation"
}
ok, Api Tools can create RPC services BUT Api Tools Admin can NOT
The documentation shows mostly HOW to use API Tools admin in order to have the RPC services created... and it doesn't show how it is wired underneath.
It is doable by creating the RPC services manually but there's not that much examples and tutorials out there showing the configuration keys and everything.
no, @Xerkus. unfortunately, i have api-tools-admin "^2.1.0",
i managed to create a new API (half done by api tools admin and half finishing manually so i don't know if all options have been added correctly).
But i still can't add a new RPC service. bits of code has been added such as
- the Controller
- the ControllerFactory
- entries in module.config.php :
- controllers.factories
- router.routes
- api-tools-versioning.uri
- api-tools-rpc
- api-tools-content-negotiation.controllers
- api-tools-content-negotiation.accept_whitelist
- api-tools-content-negotiation.content_type_whitelist
But when i try to open the route, i got Laminas\ServiceManager\Exception\ServiceNotFoundException error saying
Unable to resolve service "ApiSample\V1\Rpc\Liveliness\Controller" to a factory; are you certain you provided it during configuration? -> which is the part generated by API Tools Admin
i don't know what is missing. if i'm comparing to "regular" MVC services, the controllers.factories key looks legit to me... is something missing elsewhere ?
I don't use laminas-api-tools so I do not know how it is supposed to work.
"Unable to resolve controller" is a generic mvc error and it points at two possibilities:
- controller is not registered with controller manager via factory or abstract factory. If there is abstract factory then it might not be able to find controller class as it can't be autoloaded.
- stale configuration cache. This is most likely the case if controllers.factories looks correct.
Stale configuration cache 👍.
I'll follow this trail... Thanks for the hint