mma-customapi icon indicating copy to clipboard operation
mma-customapi copied to clipboard

Extension breask Swagger UI generation

Open 0xMatt opened this issue 5 years ago • 4 comments

I'm no longer able to access swagger because of two errors

  1. Message: The service interface name "MMA\CustomApi\Model\PaymentTokenManagement" is invalid.
  2. After fixing this endpoint on my local copy, another error with @return array causes the APIgen to fail, changing @return mixed fixes the issue

0xMatt avatar Sep 04 '20 15:09 0xMatt

@0xMatt After fixing this endpoint on my local copy .

  1. What was the issue and how did you fix it?
  2. What is Magento version you are using?

dimaportenko avatar Sep 04 '20 16:09 dimaportenko

  1. The issue is:
<route url="/V1/mma/me/vault/items" method="GET">
        <service class="MMA\CustomApi\Model\PaymentTokenManagement" method="getListByCustomerId"/>
        <resources>
            <resource ref="self" />
        </resources>
        <data>
            <parameter name="customerId" force="true">%customer_id%</parameter>
        </data>
    </route>

You are pointing to a methodrather than an interface.

There should be a method defined for this within MMA\CustomApi\Api\PaymentTokenManagementInterface and it should be mapped in di.xml like the other methods have.

Also, you are using param docblocks of @param array or @return array, those actually need to be changed to mixed, rather than array. Fixing those allows Swagger UI to properly generate. I believe I had to fix 7 occurrences of this.

  1. Magento version 2.3.5

0xMatt avatar Sep 08 '20 13:09 0xMatt

From https://devdocs.magento.com/guides/v2.3/coding-standards/technical-guidelines.html#1-basic-programming-principles

6.4.3.1. Strict typing is enforced for Service and Data interfaces located under MyCompany/MyModuleApi/Api. Only the following types are allowed:

- Scalar types: string (including Date and DateTime); int; float; boolean

- Data interfaces

- One-dimensional indexed arrays of scalars or data interfaces: for example string[], \MyCompany\MyModuleApi\Api\Data\SomeInterface[]. Hash maps (associative arrays) are not supported.

- Nullable scalars or data interfaces: for example string|null. Using just null is prohibited.

- void

So using mixed isn't allowed and I remember it causes some issues on one of my projects. I don't remember exactly what it was. Also, I'm using array more like a hack to avoid spending time on the creation of a proper interface. So feel free to use mixed if it works for you, just be aware it can cause something.

dimaportenko avatar Sep 08 '20 14:09 dimaportenko

You are pointing to a methodrather than an interface.

There should be a method defined for this within MMA\CustomApi\Api\PaymentTokenManagementInterface and it should be mapped in di.xml like the other methods have.

If you like to create PR for this I'll appreciate it

dimaportenko avatar Sep 08 '20 14:09 dimaportenko