Skip to content

Commit

Permalink
No dto if no request data (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
DimanKuskov authored and sspat committed Jan 24, 2020
1 parent 30f5b5d commit ef2eb32
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/CodeGenerator/Dto/PhpParserRootDtoFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function generateRootDto(
}

if (count($queryParameters)) {
$queryParametersDtoClassName = rtrim($className, 'Dto') . self::QUERY_PARAMETERS_PREFIX;
$queryParametersDtoClassName = preg_replace('/Dto$/', '', $className) . self::QUERY_PARAMETERS_PREFIX;
$queryParametersDtoFileName = $queryParametersDtoClassName . '.php';

$generatedClasses[] = $this->dtoFactory->generateParamDto(
Expand Down
60 changes: 32 additions & 28 deletions src/Command/GenerateApiCodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,37 +222,41 @@ protected function execute(InputInterface $input, OutputInterface $output) : ?in

// Root dto generation

$dtoNamespace = $this->namingStrategy->buildNamespace(
$operationNamespace,
self::DTO_NAMESPACE,
self::REQUEST_SUFFIX
);
$dtoClassName = $this->namingStrategy->stringToNamespace(
$operationName . self::REQUEST_SUFFIX . self::DTO_SUFFIX
);
$dtoPath = $this->namingStrategy->buildPath(
$operationPath, self::DTO_NAMESPACE, self::REQUEST_SUFFIX
);
$dtoFileName = $dtoClassName . '.php';
$parameters = array_merge($pathItem->parameters, $operation->parameters);

$rootDtoNamespace = $dtoNamespace;
$rootDtoClassName = $dtoClassName;
if(count($parameters) or !is_null($inputDtoClassName)) {

$parameters = array_merge($pathItem->parameters, $operation->parameters);
$dtoNamespace = $this->namingStrategy->buildNamespace(
$operationNamespace,
self::DTO_NAMESPACE,
self::REQUEST_SUFFIX
);
$dtoClassName = $this->namingStrategy->stringToNamespace(
$operationName . self::REQUEST_SUFFIX . self::DTO_SUFFIX
);
$dtoPath = $this->namingStrategy->buildPath(
$operationPath, self::DTO_NAMESPACE, self::REQUEST_SUFFIX
);
$dtoFileName = $dtoClassName . '.php';

$rootDtoNamespace = $dtoNamespace;
$rootDtoClassName = $dtoClassName;

$filesToGenerate = array_merge(
$filesToGenerate,
$this->rootDtoFactory->generateRootDto(
$dtoPath,
$dtoFileName,
$dtoNamespace,
$dtoClassName,
$inputDtoNamespace,
$inputDtoClassName,
$this->filterAllowedParameters($parameters, 'path'),
$this->filterAllowedParameters($parameters, 'query')
)
);

$filesToGenerate = array_merge(
$filesToGenerate,
$this->rootDtoFactory->generateRootDto(
$dtoPath,
$dtoFileName,
$dtoNamespace,
$dtoClassName,
$inputDtoNamespace,
$inputDtoClassName,
$this->filterAllowedParameters($parameters, 'path'),
$this->filterAllowedParameters($parameters, 'query')
)
);
}

// Service interface generation

Expand Down

0 comments on commit ef2eb32

Please sign in to comment.