Skip to content

Commit

Permalink
add standalone option to ignore base url and security settings
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Jul 12, 2024
1 parent d78ec15 commit a42aa81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/Console/PushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use PSX\Api\Repository\LocalRepository;
use PSX\Api\Scanner\FilterFactoryInterface;
use PSX\Api\ScannerInterface;
use PSX\Api\Specification;
use PSX\Http\Client\Client;
use PSX\Http\Client\ClientInterface;
use PSX\Http\Client\GetRequest;
Expand Down Expand Up @@ -70,7 +71,8 @@ protected function configure(): void
->addArgument('name', InputArgument::REQUIRED, 'The target document name')
->addOption('client_id', 'u', InputOption::VALUE_REQUIRED, 'Optional the client id')
->addOption('client_secret', 's', InputOption::VALUE_REQUIRED, 'Optional the client secret')
->addOption('filter', 'i', InputOption::VALUE_REQUIRED, 'Optional a specific filter');
->addOption('filter', 'i', InputOption::VALUE_REQUIRED, 'Optional a specific filter')
->addOption('standalone', 'a', InputOption::VALUE_NONE, 'Ignore base url and security settings');
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand All @@ -88,7 +90,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$generator = $registry->getGenerator(LocalRepository::SPEC_TYPEAPI);

$filter = $this->filterFactory->getFilter($filterName);
$spec = (string) $generator->generate($this->scanner->generate($filter));
$spec = $this->scanner->generate($filter);

if ($input->hasOption('standalone') && $spec instanceof Specification) {
$spec->setBaseUrl(null);
$spec->setSecurity(null);
}

$result = (string) $generator->generate($this->scanner->generate($filter));
$helper = $this->getHelper('question');

if (empty($clientId)) {
Expand All @@ -106,7 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$accessToken = $this->obtainAccessToken($clientId, $clientSecret);
$userName = $this->obtainUserName($accessToken);

$this->importDocument($accessToken, $userName, $name, $spec);
$this->importDocument($accessToken, $userName, $name, $result);

$output->writeln('Document import Successful!');

Expand Down
2 changes: 1 addition & 1 deletion src/Specification.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function getSecurity(): ?SecurityInterface
return $this->security;
}

public function setSecurity(SecurityInterface $security): void
public function setSecurity(?SecurityInterface $security): void
{
$this->security = $security;
}
Expand Down

0 comments on commit a42aa81

Please sign in to comment.