mma-customapi
mma-customapi copied to clipboard
Extension breask Swagger UI generation
I'm no longer able to access swagger because of two errors
- Message: The service interface name "MMA\CustomApi\Model\PaymentTokenManagement" is invalid.
- After fixing this endpoint on my local copy, another error with
@return arraycauses the APIgen to fail, changing@return mixedfixes the issue
@0xMatt After fixing this endpoint on my local copy .
- What was the issue and how did you fix it?
- What is Magento version you are using?
- 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.
- Magento version 2.3.5
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.
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