From 9f27cb685f947005777a3cc7672d994b8cd5055b Mon Sep 17 00:00:00 2001 From: Christoph Kappestein Date: Sat, 28 Oct 2023 00:11:25 +0200 Subject: [PATCH] fix sdkgen repo --- src/Generator/Proxy/SDKgen.php | 2 +- src/Repository/SDKgenRepository.php | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Generator/Proxy/SDKgen.php b/src/Generator/Proxy/SDKgen.php index 1b65960..3de9885 100644 --- a/src/Generator/Proxy/SDKgen.php +++ b/src/Generator/Proxy/SDKgen.php @@ -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, diff --git a/src/Repository/SDKgenRepository.php b/src/Repository/SDKgenRepository.php index d986fef..f2f451a 100644 --- a/src/Repository/SDKgenRepository.php +++ b/src/Repository/SDKgenRepository.php @@ -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 @@ -56,6 +57,9 @@ public function getAll(): array } $accessToken = $this->obtainAccessToken($clientId, $clientSecret); + if (empty($accessToken)) { + return []; + } $return = []; $types = $this->getTypes($accessToken); @@ -63,7 +67,7 @@ public function getAll(): array [$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 ); @@ -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', ])); @@ -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) { @@ -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;