Skip to content

Webapi Swager schema generation fail in case when Get endpoint has param with Extension Attributes #24116

@swnsma

Description

@swnsma

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 Notice: Undefined index: parameters in Magento/Webapi/Model/Rest/Swagger/Generator.php on line 741

Metadata

Metadata

Assignees

Labels

Component: ApiUse with concrete module component label E.g. "Component: Api" + "Catalog"Component: WebapiUse with concrete module component label E.g. "Component: Webapi" + "Catalog"Fixed 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 passedProgress: PR CreatedIndicates that Pull Request has been created to fix issueReproduced 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