public function testOperationIsDataObject()
 {
     $description = new Description([]);
     $c = new Operation(array('name' => 'test', 'summary' => 'doc', 'notes' => 'notes', 'documentationUrl' => 'http://www.example.com', 'httpMethod' => 'POST', 'uri' => '/api/v1', 'responseModel' => 'abc', 'deprecated' => true, 'parameters' => array('key' => array('required' => true, 'type' => 'string', 'maxLength' => 10, 'name' => 'key'), 'key_2' => array('required' => true, 'type' => 'integer', 'default' => 10, 'name' => 'key_2'))), $description);
     $this->assertEquals('test', $c->getName());
     $this->assertEquals('doc', $c->getSummary());
     $this->assertEquals('http://www.example.com', $c->getDocumentationUrl());
     $this->assertEquals('POST', $c->getHttpMethod());
     $this->assertEquals('/api/v1', $c->getUri());
     $this->assertEquals('abc', $c->getResponseModel());
     $this->assertTrue($c->getDeprecated());
     $params = array_map(function ($c) {
         return $c->toArray();
     }, $c->getParams());
     $this->assertEquals(['key' => ['required' => true, 'type' => 'string', 'maxLength' => 10, 'name' => 'key'], 'key_2' => ['required' => true, 'type' => 'integer', 'default' => 10, 'name' => 'key_2']], $params);
     $this->assertEquals(['required' => true, 'type' => 'integer', 'default' => 10, 'name' => 'key_2'], $c->getParam('key_2')->toArray());
     $this->assertNull($c->getParam('afefwef'));
     $this->assertArrayNotHasKey('parent', $c->getParam('key_2')->toArray());
 }
 /**
  * @param Operation $operation
  * @param array     $params
  *
  * @return array
  */
 private function getParametersForSignature($operation, $params)
 {
     // gather all parameters needed to sign the request
     $signatureParams = array();
     // add all parameters defined in the service description which have location=query
     foreach ($operation->getParams() as $param) {
         /** @var Parameter $param */
         if ($param->getLocation() == 'query' && (isset($params[$param->getName()]) || $param->getDefault())) {
             $signatureParams[$param->getName()] = isset($params[$param->getName()]) ? $params[$param->getName()] : $param->getDefault();
         }
     }
     // check if the command allows additional parameters with location=query
     if ($operation->getAdditionalParameters()->getLocation() == 'query') {
         // if yes, add all additionally given parameters from $params skipping predefined parameters
         foreach ($params as $name => $value) {
             if (!$operation->hasParam($name)) {
                 $signatureParams[$name] = $value;
             }
         }
     }
     return $signatureParams;
 }
Example #3
0
 /**
  * Create a request for an operation with a uri merged onto a base URI
  */
 private function createCommandWithUri(Operation $operation, CommandInterface $command, ServiceClientInterface $client)
 {
     // Get the path values and use the client config settings
     $variables = [];
     foreach ($operation->getParams() as $name => $arg) {
         /* @var Parameter $arg */
         if ($arg->getLocation() == 'uri') {
             if (isset($command[$name])) {
                 $variables[$name] = $arg->filter($command[$name]);
                 if (!is_array($variables[$name])) {
                     $variables[$name] = (string) $variables[$name];
                 }
             }
         }
     }
     // Expand the URI template.
     $uri = Utils::uriTemplate($operation->getUri(), $variables);
     return $client->getHttpClient()->createRequest($operation->getHttpMethod(), $this->description->getBaseUrl()->combine($uri), $command['request_options'] ?: []);
 }