Solved: Failed to Load API Definition in Magento 2 Swagger

While developing Magento 2 extensions, we often need to create a custom API to pass the data that has been fetched from the client. For example, while working with order tracking, we need to get the order id and email id from the customer and then pass it through API to perform further operations.

In order to maintain the standards of coding in API, we mostly prefer to add phpdoc in the file and if the editor is PHPStorm then we use the Ctrl+Alt+Ins shortcut key to do so.

The phpdoc contains code that seems like a comment but anyhow it affects the output in API creation.

For example, if you’ve not added the variable’s datatype in phpdoc of API, it generates an error of failed to load API definition in Magento 2 swagger,

Failed to Load API Definition

and displays in the swagger as below:

https://drops.meetanshi.com/zzdopo

So, the solution to this error is to add the missing datatype in the code as mentioned below:

Solution to Failed to Load API definition in Magento 2 Swagger

When we add phpdoc in API creation it adds like:

Replace the above code with:

Done!

The solution is simple but difficult to identify!

If you have any doubts regarding this post, just mention them in the Comments section below.

I would be happy to help.

Feel free to share the solution with Magento Community via social media.

Thank You.

5
(based on 9 Reviews)
Solved: Failed to Load API Definition in Magento 2 Swagger

Kanchi Upadhyay

Kanchi is a Magento Developer at Meetanshi. Apart from that, she is into dancing. In her free time, she likes to make handmade art and craft.

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *