Skip to content

Commit 251d969

Browse files
committed
New generator
1 parent 27e9def commit 251d969

15 files changed

+1215
-279
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ For more information, please visit [https://ssl.reddit.com/dev/api](https://ssl.
88

99
### Requirements
1010

11-
PHP 7.3 and later.
12-
Should also work with PHP 8.0 but has not been tested.
11+
PHP 7.4 and later.
12+
Should also work with PHP 8.0.
1313

1414
### Composer
1515

@@ -91,6 +91,7 @@ Class | Method | HTTP request | Description
9191

9292
## Authorization
9393

94+
Authentication schemes defined for the API:
9495
### oauth2
9596

9697
- **Type**: `OAuth`

docs/Api/ThingApi.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Sigwin\RedditClient\ThingApi
22

3-
All URIs are relative to https://oauth.reddit.com.
3+
All URIs are relative to https://oauth.reddit.com, except if the operation defines another base path.
44

5-
Method | HTTP request | Description
6-
------------- | ------------- | -------------
7-
[**getInfo()**](ThingApi.md#getInfo) | **GET** /api/info | Get thing info
5+
| Method | HTTP request | Description |
6+
| ------------- | ------------- | ------------- |
7+
| [**getInfo()**](ThingApi.md#getInfo) | **GET** /api/info | Get thing info |
88

99

1010
## `getInfo()`
@@ -44,9 +44,9 @@ try {
4444

4545
### Parameters
4646

47-
Name | Type | Description | Notes
48-
------------- | ------------- | ------------- | -------------
49-
**id** | **string**| |
47+
| Name | Type | Description | Notes |
48+
| ------------- | ------------- | ------------- | ------------- |
49+
| **id** | **string**| | |
5050

5151
### Return type
5252

docs/Api/UserApi.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Sigwin\RedditClient\UserApi
22

3-
All URIs are relative to https://oauth.reddit.com.
3+
All URIs are relative to https://oauth.reddit.com, except if the operation defines another base path.
44

5-
Method | HTTP request | Description
6-
------------- | ------------- | -------------
7-
[**getSaved()**](UserApi.md#getSaved) | **GET** /user/{username}/saved | Get user saved things
8-
[**me()**](UserApi.md#me) | **GET** /api/me | Returns the identity of the user.
5+
| Method | HTTP request | Description |
6+
| ------------- | ------------- | ------------- |
7+
| [**getSaved()**](UserApi.md#getSaved) | **GET** /user/{username}/saved | Get user saved things |
8+
| [**me()**](UserApi.md#me) | **GET** /api/me | Returns the identity of the user. |
99

1010

1111
## `getSaved()`
@@ -48,12 +48,12 @@ try {
4848

4949
### Parameters
5050

51-
Name | Type | Description | Notes
52-
------------- | ------------- | ------------- | -------------
53-
**username** | **string**| |
54-
**after** | **string**| | [optional]
55-
**before** | **string**| | [optional]
56-
**limit** | **int**| | [optional] [default to 25]
51+
| Name | Type | Description | Notes |
52+
| ------------- | ------------- | ------------- | ------------- |
53+
| **username** | **string**| | |
54+
| **after** | **string**| | [optional] |
55+
| **before** | **string**| | [optional] |
56+
| **limit** | **int**| | [optional] [default to 25] |
5757

5858
### Return type
5959

src/Api/ThingApi.php

Lines changed: 60 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
use GuzzleHttp\Client;
2323
use GuzzleHttp\ClientInterface;
24+
use GuzzleHttp\Exception\ConnectException;
2425
use GuzzleHttp\Exception\RequestException;
2526
use GuzzleHttp\Psr7\MultipartStream;
2627
use GuzzleHttp\Psr7\Request;
@@ -61,6 +62,13 @@ final class ThingApi
6162
*/
6263
private $hostIndex;
6364

65+
/** @var string[] */
66+
public const contentTypes = [
67+
'getInfo' => [
68+
'application/json',
69+
],
70+
];
71+
6472
/**
6573
* @param ClientInterface $client
6674
* @param Configuration $config
@@ -109,14 +117,15 @@ public function getConfig(): Configuration
109117
*
110118
* Get thing info
111119
*
112-
* @param string $id id (required)
120+
* @param string $id id (required)
121+
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInfo'] to see the possible values for this operation
113122
*
114123
* @throws \InvalidArgumentException
115124
* @throws \Sigwin\RedditClient\ApiException on non-2xx response
116125
*/
117-
public function getInfo($id): \Sigwin\RedditClient\Model\ListingEnvelope
126+
public function getInfo($id, string $contentType = self::contentTypes['getInfo'][0]): \Sigwin\RedditClient\Model\ListingEnvelope
118127
{
119-
[$response] = $this->getInfoWithHttpInfo($id);
128+
[$response] = $this->getInfoWithHttpInfo($id, $contentType);
120129

121130
return $response;
122131
}
@@ -126,23 +135,26 @@ public function getInfo($id): \Sigwin\RedditClient\Model\ListingEnvelope
126135
*
127136
* Get thing info
128137
*
129-
* @param string $id (required)
138+
* @param string $id (required)
139+
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInfo'] to see the possible values for this operation
130140
*
131141
* @return array of \Sigwin\RedditClient\Model\ListingEnvelope, HTTP status code, HTTP response headers (array of strings)
132142
*
133143
* @throws \InvalidArgumentException
134144
* @throws \Sigwin\RedditClient\ApiException on non-2xx response
135145
*/
136-
public function getInfoWithHttpInfo($id): array
146+
public function getInfoWithHttpInfo($id, string $contentType = self::contentTypes['getInfo'][0]): array
137147
{
138-
$request = $this->getInfoRequest($id);
148+
$request = $this->getInfoRequest($id, $contentType);
139149

140150
try {
141151
$options = $this->createHttpClientOption();
142152
try {
143153
$response = $this->client->send($request, $options);
144154
} catch (RequestException $e) {
145155
throw new ApiException("[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null);
156+
} catch (ConnectException $e) {
157+
throw new ApiException("[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null);
146158
}
147159

148160
$statusCode = $response->getStatusCode();
@@ -157,6 +169,9 @@ public function getInfoWithHttpInfo($id): array
157169
$content = $response->getBody(); // stream goes to serializer
158170
} else {
159171
$content = (string) $response->getBody();
172+
if ('\Sigwin\RedditClient\Model\ListingEnvelope' !== 'string') {
173+
$content = json_decode($content);
174+
}
160175
}
161176

162177
return [
@@ -171,6 +186,9 @@ public function getInfoWithHttpInfo($id): array
171186
$content = $response->getBody(); // stream goes to serializer
172187
} else {
173188
$content = (string) $response->getBody();
189+
if ($returnType !== 'string') {
190+
$content = json_decode($content);
191+
}
174192
}
175193

176194
return [
@@ -198,13 +216,14 @@ public function getInfoWithHttpInfo($id): array
198216
*
199217
* Get thing info
200218
*
201-
* @param string $id (required)
219+
* @param string $id (required)
220+
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInfo'] to see the possible values for this operation
202221
*
203222
* @throws \InvalidArgumentException
204223
*/
205-
public function getInfoAsync($id): \GuzzleHttp\Promise\PromiseInterface
224+
public function getInfoAsync($id, string $contentType = self::contentTypes['getInfo'][0]): \GuzzleHttp\Promise\PromiseInterface
206225
{
207-
return $this->getInfoAsyncWithHttpInfo($id)
226+
return $this->getInfoAsyncWithHttpInfo($id, $contentType)
208227
->then(
209228
static function ($response) {
210229
return $response[0];
@@ -218,14 +237,15 @@ static function ($response) {
218237
*
219238
* Get thing info
220239
*
221-
* @param string $id (required)
240+
* @param string $id (required)
241+
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInfo'] to see the possible values for this operation
222242
*
223243
* @throws \InvalidArgumentException
224244
*/
225-
public function getInfoAsyncWithHttpInfo($id): \GuzzleHttp\Promise\PromiseInterface
245+
public function getInfoAsyncWithHttpInfo($id, string $contentType = self::contentTypes['getInfo'][0]): \GuzzleHttp\Promise\PromiseInterface
226246
{
227247
$returnType = '\Sigwin\RedditClient\Model\ListingEnvelope';
228-
$request = $this->getInfoRequest($id);
248+
$request = $this->getInfoRequest($id, $contentType);
229249

230250
return $this->client
231251
->sendAsync($request, $this->createHttpClientOption())
@@ -235,6 +255,9 @@ static function ($response) use ($returnType) {
235255
$content = $response->getBody(); // stream goes to serializer
236256
} else {
237257
$content = (string) $response->getBody();
258+
if ($returnType !== 'string') {
259+
$content = json_decode($content);
260+
}
238261
}
239262

240263
return [
@@ -255,11 +278,12 @@ static function ($exception): void {
255278
/**
256279
* Create request for operation 'getInfo'.
257280
*
258-
* @param string $id (required)
281+
* @param string $id (required)
282+
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInfo'] to see the possible values for this operation
259283
*
260284
* @throws \InvalidArgumentException
261285
*/
262-
public function getInfoRequest($id): Request
286+
public function getInfoRequest($id, string $contentType = self::contentTypes['getInfo'][0]): Request
263287
{
264288
// verify the required parameter 'id' is set
265289
if ($id === null || (\is_array($id) && \count($id) === 0)) {
@@ -274,23 +298,20 @@ public function getInfoRequest($id): Request
274298
$multipart = false;
275299

276300
// query params
277-
if (\is_array($id)) {
278-
$id = ObjectSerializer::serializeCollection($id, '', true);
279-
}
280-
if ($id !== null) {
281-
$queryParams['id'] = $id;
282-
}
283-
284-
if ($multipart) {
285-
$headers = $this->headerSelector->selectHeadersForMultipart(
286-
['application/json']
287-
);
288-
} else {
289-
$headers = $this->headerSelector->selectHeaders(
290-
['application/json'],
291-
[]
292-
);
293-
}
301+
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
302+
$id,
303+
'id', // param base name
304+
'string', // openApiType
305+
'', // style
306+
false, // explode
307+
true // required
308+
) ?? []);
309+
310+
$headers = $this->headerSelector->selectHeaders(
311+
['application/json'],
312+
$contentType,
313+
$multipart
314+
);
294315

295316
// for model (json/xml)
296317
if (\count($formParams) > 0) {
@@ -307,16 +328,17 @@ public function getInfoRequest($id): Request
307328
}
308329
// for HTTP post (form)
309330
$httpBody = new MultipartStream($multipartContents);
310-
} elseif ($headers['Content-Type'] === 'application/json') {
311-
$httpBody = \GuzzleHttp\json_encode($formParams);
331+
} elseif (mb_stripos($headers['Content-Type'], 'application/json') !== false) {
332+
// if Content-Type contains "application/json", json_encode the form parameters
333+
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
312334
} else {
313335
// for HTTP post (form)
314-
$httpBody = \GuzzleHttp\Psr7\build_query($formParams);
336+
$httpBody = ObjectSerializer::buildQuery($formParams);
315337
}
316338
}
317339

318340
// this endpoint requires OAuth (access token)
319-
if ($this->config->getAccessToken() !== null) {
341+
if (! empty($this->config->getAccessToken())) {
320342
$headers['Authorization'] = 'Bearer '.$this->config->getAccessToken();
321343
}
322344

@@ -331,11 +353,12 @@ public function getInfoRequest($id): Request
331353
$headers
332354
);
333355

334-
$query = \GuzzleHttp\Psr7\build_query($queryParams);
356+
$operationHost = $this->config->getHost();
357+
$query = ObjectSerializer::buildQuery($queryParams);
335358

336359
return new Request(
337360
'GET',
338-
$this->config->getHost().$resourcePath.($query ? "?{$query}" : ''),
361+
$operationHost.$resourcePath.($query ? "?{$query}" : ''),
339362
$headers,
340363
$httpBody
341364
);

0 commit comments

Comments
 (0)