示例#1
0
 /**
  * {@inheritdoc}
  */
 protected function generateSchema($requestedServiceMetadata, $requestScheme, $requestHost, $endpointUrl)
 {
     /** @var Swagger $swagger */
     $swagger = $this->swaggerFactory->create();
     $swagger->setInfo($this->getGeneralInfo());
     $this->addCustomAttributeTypes();
     $swagger->setHost($requestHost);
     $swagger->setBasePath(strstr($endpointUrl, Rest::SCHEMA_PATH, true));
     $swagger->setSchemes([$requestScheme]);
     foreach ($requestedServiceMetadata as $serviceName => $serviceData) {
         if (!isset($this->tags[$serviceName])) {
             $this->tags[$serviceName] = $this->generateTagInfo($serviceName, $serviceData);
             $swagger->addTag($this->tags[$serviceName]);
         }
         foreach ($serviceData[Converter::KEY_ROUTES] as $uri => $httpMethods) {
             $uri = $this->convertPathParams($uri);
             foreach ($httpMethods as $httpOperation => $httpMethodData) {
                 $httpOperation = strtolower($httpOperation);
                 $phpMethodData = $serviceData[Converter::KEY_METHODS][$httpMethodData[Converter::KEY_METHOD]];
                 $httpMethodData[Converter::KEY_METHOD] = $phpMethodData;
                 $httpMethodData['uri'] = $uri;
                 $httpMethodData['httpOperation'] = $httpOperation;
                 $swagger->addPath($this->convertPathParams($uri), $httpOperation, $this->generatePathInfo($httpOperation, $httpMethodData, $serviceName));
             }
         }
     }
     $swagger->setDefinitions($this->getDefinitions());
     return $swagger->toSchema();
 }
 protected function setUp()
 {
     $this->serviceMetadataMock = $this->getMockBuilder('Magento\\Webapi\\Model\\ServiceMetadata')->disableOriginalConstructor()->getMock();
     $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $swagger = $this->objectManager->getObject('Magento\\Webapi\\Model\\Rest\\Swagger');
     $this->swaggerFactoryMock = $this->getMockBuilder('Magento\\Webapi\\Model\\Rest\\SwaggerFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->swaggerFactoryMock->expects($this->any())->method('create')->will($this->returnValue($swagger));
     $this->cacheMock = $this->getMockBuilder('Magento\\Framework\\App\\Cache\\Type\\Webapi')->disableOriginalConstructor()->getMock();
     $this->cacheMock->expects($this->any())->method('load')->will($this->returnValue(false));
     $this->cacheMock->expects($this->any())->method('save')->will($this->returnValue(true));
     $this->typeProcessorMock = $this->getMockBuilder('Magento\\Framework\\Reflection\\TypeProcessor')->disableOriginalConstructor()->getMock();
     $this->typeProcessorMock->expects($this->any())->method('getOperationName')->will($this->returnValue(self::OPERATION_NAME));
     $this->customAttributeTypeLocatorMock = $this->getMockBuilder('Magento\\Framework\\Webapi\\CustomAttributeTypeLocatorInterface')->disableOriginalConstructor()->getMock();
     $this->customAttributeTypeLocatorMock->expects($this->any())->method('getAllServiceDataInterfaces')->willReturn(['$customAttributeClass']);
     $this->storeManagerMock = $this->getMockBuilder('Magento\\Store\\Model\\StoreManagerInterface')->setMethods(['getStore'])->disableOriginalConstructor()->getMockForAbstractClass();
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock));
     $storeMock->expects($this->any())->method('getCode')->will($this->returnValue('store_code'));
     $this->generator = $this->objectManager->getObject('Magento\\Webapi\\Model\\Rest\\Swagger\\Generator', ['swaggerFactory' => $this->swaggerFactoryMock, 'cache' => $this->cacheMock, 'typeProcessor' => $this->typeProcessorMock, 'storeManager' => $this->storeManagerMock, 'serviceMetadata' => $this->serviceMetadataMock, 'customAttributeTypeLocator' => $this->customAttributeTypeLocatorMock]);
 }