Skip to content

Webapi Swagger schema generation fail in case when Get endpoint has param with Extension Attributes [Case#2] #24626

Closed
@swnsma

Description

@swnsma

After refactoring which was done in 735024a, the issue #24116 is come back.
Original report: tap

Preconditions (*)

  1. Magento 2.3.1 & 2.3-develop
  2. Created and enabled custom module 'DreamVendor\DreamModule'.

Steps to reproduce (*)

  1. Create php interface which will be used for the endpoint. E.g.
namespace DreamVendor\DreamModule\Api;

use Magento\Framework\Api\Search\SearchResultInterface;

/**
 * My Custom Endpoint API.
 */
interface MyCustomEndpointInterface
{
    /**
     * Get some awesome stuff!
     *
     * @param \DreamVendor\DreamModule\Api\Data\SearchRequestInterface $searchRequest
     *
     * @return \Magento\Framework\Api\Search\SearchResultInterface
     */
    public function execute(\DreamVendor\DreamModule\Api\Data\SearchRequestInterface $searchRequest): SearchResultInterface;
}
  1. Create SearchRequestInterface. Make it extensible with extension attributes.
namespace DreamVendor\DreamModule\Api\Data;

use Magento\Framework\Api\ExtensibleDataInterface;

/**
 * Search Request Data Object.
 */
interface SearchRequestInterface extends ExtensibleDataInterface
{
    /**
     * Get Extension Attributes.
     *
     * @return \DreamVendor\DreamModule\Api\Data\SearchRequestExtensionInterface|null
     */
    public function getExtensionAttributes(): ?\DreamVendor\DreamModule\Api\Data\SearchRequestExtensionInterface;

    /**
     * Set Extension Attributes.
     *
     * @param \DreamVendor\DreamModule\Api\Data\SearchRequestExtensionInterface|null $extension
     */
    public function setExtensionAttributes(?\DreamVendor\DreamModule\Api\Data\SearchRequestExtensionInterface $extension): void;

  1. Declare your endpoint via webapi.xml in etc folder of your module.
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
    <route url="/V1/my-custom-endpoint" method="GET">
        <service class="DreamVendor\DreamModule\Api\MyCustomEndpointInterface" method="execute"/>
        <resources>
            <resource ref="anonymous" />
        </resources>
    </route>
</routes>

  1. Flush caches.
  2. Try to generate schema. Go to your.website.com/swagger/.

Expected result (*)

  1. The page has been opened.
  2. You can see your new endpoint.

Actual result (*)

  1. You can see message like Failed to load API definition. Internal Server Error http://magento2.local/rest/all/schema?services=all
  2. Error message Warning: array_merge() expects at least 1 parameter, 0 given in \/var\/www\/html\/app\/code\/Magento\/Webapi\/Model\/Rest\/Swagger\/Generator.php:762

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: ApiUse with concrete module component label E.g. "Component: Api" + "Catalog"Component: Framework/WebapiUSE ONLY for FRAMEWORK RELATED BUG! E.g If bug related to Catalog WEB API use just CatalogFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions