Magento – Magento 2.1.3 Swagger and api error

apiimportmagento2restsoap

Im using Magento 2.1.3 and PHP 7.0.8.

I would like to test some Magentos 2 import api.

When I'm trying to connect to swagger by http://localhost/swagger error 500 is received:
enter image description here

I'm also trying to connect to http://localhost/rest/default/schema?services=all
and return:
enter image description here

I am worried about that it doesn't works.
However I am able to connect via rest to eg. http://localhost/index.php/rest/V1/integration/admin/token and get user token.

I also tried to install https://www.npmjs.com/package/magento2-swagger
result:

root@2d426841549e:/var/www/html# npm install magento2-swagger --save
npm WARN saveError ENOENT: no such file or directory, open '/var/www/html/package.json'
/var/www/html
`-- magento2-swagger@0.0.8  

npm WARN enoent ENOENT: no such file or directory, open '/var/www/html/package.json'
npm WARN html No description
npm WARN html No repository field.
npm WARN html No README data
npm WARN html No license field.  

Best Answer

Swagger try to generate documentation from class annotation.

You use array as API type.

It is not support by Magento swagger implementation.

You can try to use anyType as a workaround or create your custom type.

Reference :

\Magento\Framework\Reflection\TypeProcessor

Allowed base type :

/**#@+
 * Normalized type constants
 */
const NORMALIZED_STRING_TYPE = 'string';
const NORMALIZED_INT_TYPE = 'int';
const NORMALIZED_FLOAT_TYPE = 'float';
const NORMALIZED_DOUBLE_TYPE = 'double';
const NORMALIZED_BOOLEAN_TYPE = 'boolean';
const NORMALIZED_ANY_TYPE = 'anyType';

You can also add array type but you need to do some custom development.

If your website is different than default, you will need to change the form URL hidden value to match your website.

Related Topic