Skip to content

Commit

Permalink
Fixed: conflection when imported class is same named with current class
Browse files Browse the repository at this point in the history
Fixed: method parameter type incorrectly shown due to zend-code bug zendframework/zend-code#76
  • Loading branch information
allansun committed Aug 2, 2018
1 parent 2f5f042 commit b9a914f
Show file tree
Hide file tree
Showing 53 changed files with 2,086 additions and 2,053 deletions.
14 changes: 9 additions & 5 deletions dev_src/Code/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ function parseMethod(OperationObject $OperationObject, string $path, string $ope

foreach ($methodParameters as $Parameter) {
/** @var ParameterGenerator $Parameter $ParamTag */
$tags[] = new ParamTag($Parameter->getName(), $Parameter->getType());

$tags[] = new ParamTag($Parameter->getName(),
(!$Parameter->getType() || in_array($Parameter->getType(), self::$internalPhpTypes))
? $Parameter->getType()
: $this->getUseAlias($Parameter->getType())
);
}

$responseTypes = [];
Expand Down Expand Up @@ -168,7 +173,6 @@ protected function generateParameters(OperationObject $OperationObject, string $
foreach ((array)$pathParameters[1] as $parameter) {
$ParameterGenerator = new ParameterGenerator($parameter);
if ('namespace' == $parameter) {
$ParameterGenerator->setType('string');
$ParameterGenerator->setDefaultValue('default');
}

Expand All @@ -181,9 +185,9 @@ protected function generateParameters(OperationObject $OperationObject, string $
if ('body' == $Parameter->in) {
if ($Parameter->schema) {
$parameters[] =
new ParameterGenerator('Model',
$this->getUseAlias('\\Kubernetes\\Model\\' . Utility::convertRefToClass
($Parameter->schema->_ref)));
new ParameterGenerator('Model'
,'\\Kubernetes\\Model\\' . Utility::convertRefToClass($Parameter->schema->_ref)
);
}
} else {
$queryParameters[] = $Parameter;
Expand Down
33 changes: 31 additions & 2 deletions dev_src/Code/AbstractClassFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ abstract class AbstractClassFile extends FileGenerator
*/
protected $sourceFileDirectory;

protected static $internalPhpTypes = [
'void',
'int',
'float',
'string',
'bool',
'array',
'callable',
'iterable',
'object'
];


protected function parseDescription(string $description): string
{
Expand All @@ -39,17 +51,34 @@ protected function checkAndAddDeprecatedTag($description, DocBlockGenerator &$Do

protected function getUseAlias(string $fullClassName): string
{
if (0 !== strpos($fullClassName, '\\')) {
$fullClassName = '\\' . $fullClassName;
}

$classInfo = explode('\\', $fullClassName);
$className = array_pop($classInfo);

while (in_array($className, $uses)) {
$className .= array_pop($classInfo);
if ($className == $this->ClassGenerator->getName()) {
$className = 'The' . $className;
}

$classGeneratorUses = $this->ClassGenerator->getUses();
$uses = [];

foreach ($classGeneratorUses as $use) {
$useInfo = explode(' as ', $use);

$uses[$useInfo[0]] = $useInfo[1];
}

if ($this->ClassGenerator->hasUse($fullClassName)) {
return $uses[$fullClassName];
}

while (in_array($className, $uses)) {
$className .= array_pop($classInfo);
}

$this->ClassGenerator->addUse($fullClassName, $className);

return $className;
Expand Down
62 changes: 31 additions & 31 deletions src/API/APIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
namespace Kubernetes\API;

use \Kubernetes\Model\Io\K8s\Kube_aggregator\Pkg\Apis\Apiregistration\V1\APIServiceList as APIServiceList;
use \Kubernetes\Model\Io\K8s\Kube_aggregator\Pkg\Apis\Apiregistration\V1\APIService as APIService;
use \Kubernetes\Model\Io\K8s\Kube_aggregator\Pkg\Apis\Apiregistration\V1beta1\APIServiceList as APIServiceList;
use \Kubernetes\Model\Io\K8s\Apimachinery\Pkg\Apis\Meta\V1\DeleteOptions as DeleteOptions;
use \Kubernetes\Model\Io\K8s\Kube_aggregator\Pkg\Apis\Apiregistration\V1\APIService as TheAPIService;
use \Kubernetes\Model\Io\K8s\Apimachinery\Pkg\Apis\Meta\V1\Status as Status;
use \Kubernetes\Model\Io\K8s\Apimachinery\Pkg\Apis\Meta\V1\DeleteOptions as DeleteOptions;
use \Kubernetes\Model\Io\K8s\Apimachinery\Pkg\Apis\Meta\V1\Patch as Patch;
use \Kubernetes\Model\Io\K8s\Kube_aggregator\Pkg\Apis\Apiregistration\V1beta1\APIService as APIService;
use \Kubernetes\Model\Io\K8s\Apimachinery\Pkg\Apis\Meta\V1\WatchEvent as WatchEvent;
use \Kubernetes\Model\Io\K8s\Kube_aggregator\Pkg\Apis\Apiregistration\V1beta1\APIServiceList as APIServiceListV1beta1;
use \Kubernetes\Model\Io\K8s\Kube_aggregator\Pkg\Apis\Apiregistration\V1beta1\APIService as TheAPIServiceV1beta1;

class APIService extends \Kubernetes\AbstractAPI
{
Expand Down Expand Up @@ -52,10 +52,10 @@ public function list(array $queries)
/**
* create an APIService
*
* @param APIService $Model
* @return APIService|mixed
* @param TheAPIService $Model
* @return TheAPIService|mixed
*/
public function create(\APIService $Model)
public function create(\Kubernetes\Model\Io\K8s\Kube_aggregator\Pkg\Apis\Apiregistration\V1\APIService $Model)
{
return $this->parseResponse(
$this->client->request('post',
Expand Down Expand Up @@ -112,7 +112,7 @@ public function deleteCollection(array $queries)
* @configkey export boolean
* @param $name
* @param array $queries
* @return APIService|mixed
* @return TheAPIService|mixed
*/
public function read($name, array $queries)
{
Expand All @@ -131,10 +131,10 @@ public function read($name, array $queries)
* replace the specified APIService
*
* @param $name
* @param APIService $Model
* @return APIService|mixed
* @param TheAPIService $Model
* @return TheAPIService|mixed
*/
public function replace($name, \APIService $Model)
public function replace($name, \Kubernetes\Model\Io\K8s\Kube_aggregator\Pkg\Apis\Apiregistration\V1\APIService $Model)
{
return $this->parseResponse(
$this->client->request('put',
Expand All @@ -161,7 +161,7 @@ public function replace($name, \APIService $Model)
* @param array $queries
* @return Status|mixed
*/
public function delete($name, \DeleteOptions $Model, array $queries)
public function delete($name, \Kubernetes\Model\Io\K8s\Apimachinery\Pkg\Apis\Meta\V1\DeleteOptions $Model, array $queries)
{
return $this->parseResponse(
$this->client->request('delete',
Expand All @@ -180,9 +180,9 @@ public function delete($name, \DeleteOptions $Model, array $queries)
*
* @param $name
* @param Patch $Model
* @return APIService|mixed
* @return TheAPIService|mixed
*/
public function patch($name, \Patch $Model)
public function patch($name, \Kubernetes\Model\Io\K8s\Apimachinery\Pkg\Apis\Meta\V1\Patch $Model)
{
return $this->parseResponse(
$this->client->request('patch',
Expand All @@ -199,10 +199,10 @@ public function patch($name, \Patch $Model)
* replace status of the specified APIService
*
* @param $name
* @param APIService $Model
* @return APIService|mixed
* @param TheAPIService $Model
* @return TheAPIService|mixed
*/
public function replaceStatus($name, \APIService $Model)
public function replaceStatus($name, \Kubernetes\Model\Io\K8s\Kube_aggregator\Pkg\Apis\Apiregistration\V1\APIService $Model)
{
return $this->parseResponse(
$this->client->request('put',
Expand Down Expand Up @@ -270,7 +270,7 @@ public function watch($name)
* @configkey timeoutSeconds integer
* @configkey watch boolean
* @param array $queries
* @return APIServiceList|mixed
* @return APIServiceListV1beta1|mixed
*/
public function listApiregistrationV1beta1(array $queries)
{
Expand All @@ -288,10 +288,10 @@ public function listApiregistrationV1beta1(array $queries)
/**
* create an APIService
*
* @param APIService $Model
* @return APIService|mixed
* @param TheAPIServiceV1beta1 $Model
* @return TheAPIServiceV1beta1|mixed
*/
public function createApiregistrationV1beta1(\APIService $Model)
public function createApiregistrationV1beta1(\Kubernetes\Model\Io\K8s\Kube_aggregator\Pkg\Apis\Apiregistration\V1beta1\APIService $Model)
{
return $this->parseResponse(
$this->client->request('post',
Expand Down Expand Up @@ -348,7 +348,7 @@ public function deleteCollectionApiregistrationV1beta1(array $queries)
* @configkey export boolean
* @param $name
* @param array $queries
* @return APIService|mixed
* @return TheAPIServiceV1beta1|mixed
*/
public function readApiregistrationV1beta1($name, array $queries)
{
Expand All @@ -367,10 +367,10 @@ public function readApiregistrationV1beta1($name, array $queries)
* replace the specified APIService
*
* @param $name
* @param APIService $Model
* @return APIService|mixed
* @param TheAPIServiceV1beta1 $Model
* @return TheAPIServiceV1beta1|mixed
*/
public function replaceApiregistrationV1beta1($name, \APIService $Model)
public function replaceApiregistrationV1beta1($name, \Kubernetes\Model\Io\K8s\Kube_aggregator\Pkg\Apis\Apiregistration\V1beta1\APIService $Model)
{
return $this->parseResponse(
$this->client->request('put',
Expand All @@ -397,7 +397,7 @@ public function replaceApiregistrationV1beta1($name, \APIService $Model)
* @param array $queries
* @return Status|mixed
*/
public function deleteApiregistrationV1beta1($name, \DeleteOptions $Model, array $queries)
public function deleteApiregistrationV1beta1($name, \Kubernetes\Model\Io\K8s\Apimachinery\Pkg\Apis\Meta\V1\DeleteOptions $Model, array $queries)
{
return $this->parseResponse(
$this->client->request('delete',
Expand All @@ -416,9 +416,9 @@ public function deleteApiregistrationV1beta1($name, \DeleteOptions $Model, array
*
* @param $name
* @param Patch $Model
* @return APIService|mixed
* @return TheAPIServiceV1beta1|mixed
*/
public function patchApiregistrationV1beta1($name, \Patch $Model)
public function patchApiregistrationV1beta1($name, \Kubernetes\Model\Io\K8s\Apimachinery\Pkg\Apis\Meta\V1\Patch $Model)
{
return $this->parseResponse(
$this->client->request('patch',
Expand All @@ -435,10 +435,10 @@ public function patchApiregistrationV1beta1($name, \Patch $Model)
* replace status of the specified APIService
*
* @param $name
* @param APIService $Model
* @return APIService|mixed
* @param TheAPIServiceV1beta1 $Model
* @return TheAPIServiceV1beta1|mixed
*/
public function replaceStatusApiregistrationV1beta1($name, \APIService $Model)
public function replaceStatusApiregistrationV1beta1($name, \Kubernetes\Model\Io\K8s\Kube_aggregator\Pkg\Apis\Apiregistration\V1beta1\APIService $Model)
{
return $this->parseResponse(
$this->client->request('put',
Expand Down
18 changes: 9 additions & 9 deletions src/API/Binding.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

namespace Kubernetes\API;

use \Kubernetes\Model\Io\K8s\Api\Core\V1\Binding as Binding;
use \Kubernetes\Model\Io\K8s\Api\Core\V1\Binding as TheBinding;

class Binding extends \Kubernetes\AbstractAPI
{

/**
* create a Binding
*
* @param string $namespace
* @param Binding $Model
* @return Binding|mixed
* @param $namespace
* @param TheBinding $Model
* @return TheBinding|mixed
*/
public function create(string $namespace = 'default', \Binding $Model)
public function create($namespace = 'default', \Kubernetes\Model\Io\K8s\Api\Core\V1\Binding $Model)
{
return $this->parseResponse(
$this->client->request('post',
Expand All @@ -30,12 +30,12 @@ public function create(string $namespace = 'default', \Binding $Model)
/**
* create binding of a Pod
*
* @param string $namespace
* @param $namespace
* @param $name
* @param Binding $Model
* @return Binding|mixed
* @param TheBinding $Model
* @return TheBinding|mixed
*/
public function createPod(string $namespace = 'default', $name, \Binding $Model)
public function createPod($namespace = 'default', $name, \Kubernetes\Model\Io\K8s\Api\Core\V1\Binding $Model)
{
return $this->parseResponse(
$this->client->request('post',
Expand Down
Loading

0 comments on commit b9a914f

Please sign in to comment.