3

Installed fresh magento 2.4.4 version on server . When i added some categories and products unable to check the swagger URL for API's

I navigated to https://myip/swagger. It is giving 404 page not found error.

When i google for this error , In magento2.4.4 by default swagger is disabled in production mode. But i enabled developer mode in magento then also it is not useful

I am using bitnami magento image to up and run my magento instance. Can any body know how to enable swagger in magento 2.4.4 .

I verified etc/config.php file as well, The Magento_Swagger module is already enabled.

Please help me on this.

I am using this bitnami instance https://bitnami.com/stack/magento/cloud

2 Answers 2

5

If you didn't change deploy mode for your instance, by default deploy mode is default (not developer)

You need to change mode to developer for Swagger

How to display current mode (CLI)

bin/magento deploy:mode:show

How to change deploy mode (CLI)

bin/magento deploy:mode:set developer

You can see logic in \Magento\Swagger\Model\Config::isEnabled

namespace Magento\Swagger\Model;

use Magento\Framework\App\State;
//...
class Config
{
    //...
    public function isEnabled(): bool
    {
        return $this->state->getMode() === State::MODE_DEVELOPER || $this->enabledInProduction;
    }
}

Also you can set force mode with di in your module

app/code/Acme/StackExchange/etc/di.xml

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Swagger\Model\Config">
        <arguments>
            <argument name="enabledInProduction" xsi:type="boolean">true</argument>
        </arguments>
    </type>
</config>
9
  • I tried to change the code to public function isEnabled(): bool { return true; } Still i am unable to access swagger. My magento mode is developer.
    – Dinesh
    Commented Jun 6, 2022 at 16:47
  • In this case i just can suggest to debug \Magento\Swagger\Controller\Index\Index. Double check if you have module enabled in app/etc/config.php. I don't see any other reasons. Commented Jun 6, 2022 at 17:20
  • app/etc/config.php module is enabled but when i put die or exit in Contoller/Index/Index its still showing page not found.
    – Dinesh
    Commented Jun 6, 2022 at 17:29
  • Is there any issue with http_cache_hosts . in env.php presently it is pointed to localhost and port as 80
    – Dinesh
    Commented Jun 6, 2022 at 17:31
  • comment dispatch method for disable and just add some into execute Commented Jun 6, 2022 at 17:34
0

Finally i found the issue. It is with bitnami

when i run the following command it worked for me

sudo /opt/bitnami/ctlscript.sh restart

Hope it helps for you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.