4

I'm trying to view the cool interactive Swagger UI on my own running Magento 2.1 instance.

When I go to https://example.com/swagger it shows the swagger header, but under it is an error message:

Can't read swagger JSON from https://example.com/index.php/rest/default/schema?services=all

When I query that URI myself with

curl -X GET "https://example.com/rest/default/schema" -H "Authorization: Bearer mytoken"

I get a 404 response with message {"message":"Request does not match any route","trace":null}

Do I need to do anything to generate the swagger json? Where is the controller that's supposed to process this request so that I can debug it? Why is this not working? Any ideas?

4
  • Can you try by clearing your browser cache or some other browser or CTRL+R.
    – Arjun
    Aug 12, 2016 at 4:51
  • It's not a browser issue. That curl command is not running in the browser but on the terminal.
    – peedee
    Aug 12, 2016 at 6:29
  • Have you found a solution for this issue? Sep 2, 2016 at 8:17
  • Me not yet, but someone just posted an answer, I have yet to try it.
    – peedee
    Sep 2, 2016 at 10:49

1 Answer 1

7

https://example.com/rest/default/schema is not available because you probably don't have a storeview with code "default".

So you have to create a storeview with code "default" OR you can edit(override of course) the template in the Magento Swagger module "view/frontend/templates:swagger-ui/index.phtml":

$schemaUrl = rtrim($block->getBaseUrl(), '/') . '/rest/default/schema?services=all';

and change it to:

 $schemaUrl = rtrim($block->getBaseUrl(), '/') . '/rest/[storecode]/schema?services=all';

Of course it would be better if Magento would make the storecode a parameter you can pass to the request.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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