Laminas API Tools - unable to create new API in Admi UI

Anyone else is experiencing an error when creating new API tool when navigating to: [url]/api-tools/ui ?

Currently I am getting:

Fatal error: Uncaught Laminas\ModuleManager\Exception\RuntimeException: Module (ApplicationTest) could not be initialized. in E:\RZECZY_ADAMA\_XAMPP\xampp-7.4\htdocs\laminas_app\vendor\laminas\laminas-modulemanager\src\ModuleManager.php:202

It looks like you added the module ApplicationTest in config/modules.config.php.
You shouldn’t. Can you show use the content of this file => config/modules.config.php

Yes, the Admin UI during creation of new endpoint did add the 'ApplicationTest', into the list as the last item. Is that a bug?

Full list:

return array(
    'Laminas\\Serializer',
    'Laminas\\Paginator',
    'Laminas\\Di',
    'Laminas\\Log',
    'Laminas\\Db',
    'Laminas\\Mvc\\Plugin\\FilePrg',
    'Laminas\\Mvc\\Plugin\\FlashMessenger',
    'Laminas\\Mvc\\Plugin\\Identity',
    'Laminas\\Mvc\\Plugin\\Prg',
    'Laminas\\Session',
    'Laminas\\Mvc\\I18n',
    'Laminas\\Mvc\\Console',
    'Laminas\\Form',
    'Laminas\\Hydrator',
    'Laminas\\InputFilter',
    'Laminas\\Filter',
    'Laminas\\I18n',
    'Laminas\\Cache',
    'Laminas\\Router',
    'Laminas\\Validator',
    'Laminas\\DeveloperTools',
    'Laminas\\ApiTools\\ApiProblem',
    'Laminas\\ApiTools\\ContentNegotiation',
    'Laminas\\ApiTools\\Rpc',
    'Laminas\\ApiTools\\MvcAuth',
    'Laminas\\ApiTools\\Hal',
    'Laminas\\ApiTools\\Rest',
    'Laminas\\ApiTools\\ContentValidation',
    'Laminas\\ApiTools',
    'Laminas\\ApiTools\\Configuration',
    'Laminas\\ApiTools\\Admin',
    'Laminas\\ApiTools\\Documentation',
    'Application',
    
);

ok now can you show us the parts involving autoloading in your composer.json please

@gary it turns out Laminas API Tools Admin UI have a bug as the default module structure have changed. Here is how it should look like:

image

I will raise a ticket on the related repo.

Here is a link: https://github.com/laminas-api-tools/api-tools-admin/issues/52

have you tried to overwrite the value of path_spec to psr-4 in the following config:

    'api-tools-admin' => [
    // path_spec defines whether modules should be created using PSR-0
    //     or PSR-4 module structure; the default is to use PSR-0.
    //     Valid values are:
    //     - Laminas\ApiTools\Admin\Model\ModulePathSpec::PSR_0 ("psr-0")
    //     - Laminas\ApiTools\Admin\Model\ModulePathSpec::PSR_4 ("psr-4")
    // 'path_spec' => 'psr-0',
],

I’ve already found out a solution myself above and marked it as Solution.

Thanks for reply anyway :slight_smile:

Can you give us the Solution? It would be nice!

I’ve typed a solution above: Laminas API Tools - unable to create new API in Admi UI - #5 by divix

If you will modify the file structure to the one from my image, then the API endpoint creation will start to work :slight_smile:

I am facing the same error as you have mentioned. In the picture I could see 2 Module.php which one need to be there. Thanks

You should have both, but the root one only includes the contents from src/Module.php so it’s your call.

Thanks for the response. In reference to the above pic your tried to create the “ApplicationAPI” module and with in that directory you have all this directory structure: confg, src, view etc. Is that right. In my case it is not created at all in the module folder and the UI just responds with the error message “…already exists”. Neither there is any entry that gets created ( “ApplicationAPI” or whatever I try to create) in modules.config.php. Please advise.

I have found the solution:
I gave 0744 permission to ‘config’ and ‘module’ folders and that resolved the problem of “…already exists”:
$ sudo chmod 0744 config
$ sudo chown www-data:www-data module
$ sudo chmod 0744 module
$ sudo systemctl reload apache2