Skip to content

Commit

Permalink
fix sdkgen repo
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Oct 27, 2023
1 parent b62b45d commit 9f27cb6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Generator/Proxy/SDKgen.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function generate(SpecificationInterface $specification): Generator\Code\
// transform to TypeAPI spec
$body = (new TypeAPI($this->baseUrl))->generate($specification);

$uri = Uri::parse('https://api.sdkgen.app/generator/generate/' . $this->type);
$uri = Uri::parse('https://api.sdkgen.app/generate/' . $this->type);
$uri = $uri->withParameters([
'base_url' => $this->baseUrl,
'config' => $this->config,
Expand Down
14 changes: 10 additions & 4 deletions src/Repository/SDKgenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use PSX\Http\Client\Client;
use PSX\Http\Client\ClientInterface;
use PSX\Http\Client\GetRequest;
use PSX\Http\Client\PostRequest;

/**
* SDKgenRepository
Expand Down Expand Up @@ -56,14 +57,17 @@ public function getAll(): array
}

$accessToken = $this->obtainAccessToken($clientId, $clientSecret);
if (empty($accessToken)) {
return [];
}

$return = [];
$types = $this->getTypes($accessToken);
foreach ($types as $type) {
[$name, $fileExtension, $mime] = $type;

$return[$name] = new GeneratorConfig(
fn(string $baseUrl, string $config) => new Generator\Proxy\SDKgen($this->httpClient, $accessToken, $name, $baseUrl, $config),
fn(?string $baseUrl, ?string $config) => new Generator\Proxy\SDKgen($this->httpClient, $accessToken, $name, $baseUrl, $config),
$fileExtension,
$mime
);
Expand All @@ -79,7 +83,7 @@ private function getTypes(string $accessToken): array
return $item->get();
}

$response = $this->httpClient->request(new GetRequest('https://api.sdkgen.app/generator/types', [
$response = $this->httpClient->request(new GetRequest('https://api.sdkgen.app/types', [
'Authorization' => 'Bearer ' . $accessToken,
'Accept' => 'application/json',
]));
Expand Down Expand Up @@ -139,9 +143,11 @@ private function obtainAccessToken(string $clientId, string $clientSecret): ?str
return $item->get();
}

$response = $this->httpClient->request(new GetRequest('https://api.sdkgen.app/authorization/token', [
$response = $this->httpClient->request(new PostRequest('https://api.sdkgen.app/authorization/token', [
'Authorization' => 'Basic ' . base64_encode($clientId . ':' . $clientSecret),
'Accept' => 'application/json',
], [
'grant_type' => 'client_credentials'
]));

if ($response->getStatusCode() !== 200) {
Expand All @@ -159,7 +165,7 @@ private function obtainAccessToken(string $clientId, string $clientSecret): ?str
}

$item->set($accessToken);
$item->expiresAfter(new \DateInterval('P1D'));
$item->expiresAfter(60 * 60 * 24);
$this->cache->save($item);

return $accessToken;
Expand Down

0 comments on commit 9f27cb6

Please sign in to comment.