Skip to content

Commit 6bb3e15

Browse files
authored
Merge pull request #174 from ToshY/patch/automated-models-71e32c8-fixed
Patch/automated models 71e32c8 fixed
2 parents 71e32c8 + 2ac7392 commit 6bb3e15

File tree

14 files changed

+224
-7
lines changed

14 files changed

+224
-7
lines changed

.github/workflows/generator.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ jobs:
3434
- name: Run model generator
3535
run: php generator/Command/generate-models.php --log
3636

37+
- name: Run map generator for possible newly created models
38+
run: php generator/Command/generate-maps.php
39+
3740
- name: Create Pull Request
3841
uses: peter-evans/[email protected]
3942
id: cpr

Taskfile.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ tasks:
8080
cmds:
8181
- docker compose run --rm $TTY php php /app/generator/Command/generate-models.php {{.CLI_ARGS | default "--log"}}
8282

83+
specs:
84+
desc: Run maps and models generators
85+
cmds:
86+
- task: specs:maps
87+
- task: specs:models
88+
- task: specs:maps
89+
8390
# Git
8491
git:hooks:
8592
desc: Setup git hooks

docs/base-api.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,20 @@ $bunnyHttpClient->request(
597597
);
598598
```
599599

600+
#### [Get Video Library DRM Statistics](https://docs.bunny.net/reference/getdrmstatisticsendpoint_statistics)
601+
602+
```php
603+
$bunnyHttpClient->request(
604+
new \ToshY\BunnyNet\Model\Api\Base\StreamVideoLibrary\GetDrmStatistics(
605+
id: 1,
606+
query: [
607+
'dateFrom' => 'm-d-Y',
608+
'dateTo' => 'm-d-Y',
609+
],
610+
)
611+
);
612+
```
613+
600614
#### [Get Languages](https://docs.bunny.net/reference/videolibrarypublic_index3)
601615

602616
```php

docs/stream-api.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,21 @@ $bunnyHttpClient->request(
244244
```
245245
A support ticket has been created at bunny.net regarding this issue.
246246

247+
#### [Get Video Heatmap Data](https://docs.bunny.net/reference/video_getvideoheatmapdata)
248+
249+
```php
250+
$bunnyHttpClient->request(
251+
new \ToshY\BunnyNet\Model\Api\Stream\ManageVideos\GetVideoHeatmapData(
252+
libraryId: 1,
253+
videoId: 'e7e9b99a-ea2a-434a-b200-f6615e7b6abd',
254+
query: [
255+
'token' => 'ead85f9a-578b-42b7-985f-9a578b12b776',
256+
'expires' => 3600,
257+
],
258+
)
259+
);
260+
```
261+
247262
#### [Get Video Play Data](https://docs.bunny.net/reference/video_getvideoplaydata)
248263

249264
```php
@@ -443,7 +458,6 @@ $bunnyHttpClient->request(
443458
libraryId: 1,
444459
videoId: 'e7e9b99a-ea2a-434a-b200-f6615e7b6abd',
445460
query: [
446-
'language' => 'fi',
447461
'force' => true,
448462
],
449463
body: [
@@ -461,7 +475,7 @@ $bunnyHttpClient->request(
461475

462476
!!! note
463477

464-
- The `language` is a [two-letter (set 1) language abbreviation](https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes) for transcribing the video.
478+
- The `targetLanguages` / `sourceLanguage` require a [two-letter (set 1) language abbreviation](https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes) for transcribing the video.
465479
- Once a video has transcribed you need to set `force` to `true` in order to force a new transcription to be added.
466480
- The body parameter `sourceLanguage` takes precedence over the query parameter `language`.
467481

generator/Generator/ModelGenerator.php

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,14 +1117,21 @@ private function getNamespaceFromPath(string $path, string $httpMethod): array
11171117
/* @phpstan-ignore-next-line property.notFound */
11181118
$specData = $this->apiSpec->paths->getPath($path)->getRawSpecData()[$httpMethod];
11191119

1120-
[$operationNamespace, $operationClass] = explode('_', $specData['operationId'], 2);
1120+
$operationId = $this->retrieveOperationId($specData['operationId'], $specData['tags']);
1121+
1122+
[$operationNamespace, $operationClass] = explode('_', $operationId, 2);
1123+
1124+
$namespace = OpenApiModelUtils::extractNamespaceFromTags($specData['tags']);
1125+
$namespace = match ($namespace !== null) {
1126+
true => ClassUtils::toPascalCase($namespace),
1127+
false => OpenApiModelUtils::stripTagSuffix($operationNamespace),
1128+
};
11211129

1122-
$namespace = OpenApiModelUtils::stripTagSuffix($operationNamespace);
11231130
$class = OpenApiModelUtils::stripTagSuffix($operationClass);
11241131

11251132
if (empty($class) === true) {
11261133
if (empty($specData['summary']) === false) {
1127-
$class = implode('', array_map('ucfirst', explode(' ', $specData['summary'])));
1134+
$class = ClassUtils::toPascalCase($specData['summary']);
11281135
} else {
11291136
// This likely won't happen
11301137
$this->logger::print("* WARNING: Path '$path' does not have a summary to use for class name\n");
@@ -1137,6 +1144,28 @@ private function getNamespaceFromPath(string $path, string $httpMethod): array
11371144
];
11381145
}
11391146

1147+
/**
1148+
* @param string $operationId
1149+
* @param string[] $tags
1150+
* @return string
1151+
*/
1152+
private function retrieveOperationId(string $operationId, array $tags): string
1153+
{
1154+
[$operationNamespace, $operationClass] = explode('_', $operationId, 2);
1155+
1156+
foreach ($tags as $tag) {
1157+
if ($operationClass !== $tag) {
1158+
continue;
1159+
}
1160+
1161+
// Edge case where the current operationId does not conform to the expected format of <namespace>_<class>
1162+
$operationId = implode('_', [$operationClass, $operationNamespace]);
1163+
break;
1164+
}
1165+
1166+
return $operationId;
1167+
}
1168+
11401169
public static function getPhpTypeFromOpenApiType(string $openApiType): string
11411170
{
11421171
return match ($openApiType) {

generator/Map/Base.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
use ToshY\BunnyNet\Model\Api\Base\StreamVideoLibrary\AddWatermark;
9090
use ToshY\BunnyNet\Model\Api\Base\StreamVideoLibrary\DeleteVideoLibrary;
9191
use ToshY\BunnyNet\Model\Api\Base\StreamVideoLibrary\DeleteWatermark;
92+
use ToshY\BunnyNet\Model\Api\Base\StreamVideoLibrary\GetDrmStatistics;
9293
use ToshY\BunnyNet\Model\Api\Base\StreamVideoLibrary\GetLanguages;
9394
use ToshY\BunnyNet\Model\Api\Base\StreamVideoLibrary\GetVideoLibrary;
9495
use ToshY\BunnyNet\Model\Api\Base\StreamVideoLibrary\ListVideoLibraries;
@@ -249,6 +250,9 @@ final class Base
249250
'/videolibrary/{id}/removeBlockedReferrer' => [
250251
'post' => RemoveBlockedReferer::class,
251252
],
253+
'/videolibrary/{id}/drm/statistics' => [
254+
'get' => GetDrmStatistics::class,
255+
],
252256
'/dnszone' => [
253257
'get' => ListDnsZones::class,
254258
'post' => AddDnsZone::class,

generator/Map/Stream.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use ToshY\BunnyNet\Model\Api\Stream\ManageVideos\FetchVideo;
1919
use ToshY\BunnyNet\Model\Api\Stream\ManageVideos\GetVideo;
2020
use ToshY\BunnyNet\Model\Api\Stream\ManageVideos\GetVideoHeatmap;
21+
use ToshY\BunnyNet\Model\Api\Stream\ManageVideos\GetVideoHeatmapData;
2122
use ToshY\BunnyNet\Model\Api\Stream\ManageVideos\GetVideoPlayData;
2223
use ToshY\BunnyNet\Model\Api\Stream\ManageVideos\GetVideoStatistics;
2324
use ToshY\BunnyNet\Model\Api\Stream\ManageVideos\ListVideos;
@@ -58,6 +59,9 @@ final class Stream
5859
'/library/{libraryId}/videos/{videoId}/play' => [
5960
'get' => GetVideoPlayData::class,
6061
],
62+
'/library/{libraryId}/videos/{videoId}/play/heatmap' => [
63+
'get' => GetVideoHeatmapData::class,
64+
],
6165
'/library/{libraryId}/statistics' => [
6266
'get' => GetVideoStatistics::class,
6367
],

generator/Utils/ClassUtils.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,19 @@ public static function forwardSlashToBackwardSlash(string $path): string
102102
{
103103
return str_replace('/', '\\', $path);
104104
}
105+
106+
107+
public static function toPascalCase(string $text, string $textDelimiter = ' '): string
108+
{
109+
return implode(
110+
'',
111+
array_map(
112+
function ($v) {
113+
$v = strtolower($v);
114+
return ucfirst($v);
115+
},
116+
explode(separator: $textDelimiter, string: $text),
117+
),
118+
);
119+
}
105120
}

generator/Utils/OpenApiModelUtils.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static function normalizePath(string $urlPath, string $replacement = ':pa
2727
* @param array<string> $tags
2828
* @return string
2929
*/
30-
public static function stripTagSuffix(string $value, array $tags = ['Public', 'Index']): string
30+
public static function stripTagSuffix(string $value, array $tags = ['Public', 'Index', 'Endpoint']): string
3131
{
3232
return preg_replace(
3333
sprintf(
@@ -38,4 +38,17 @@ public static function stripTagSuffix(string $value, array $tags = ['Public', 'I
3838
$value,
3939
);
4040
}
41+
42+
/**
43+
* @param string[] $tags
44+
*/
45+
public static function extractNamespaceFromTags(array $tags): ?string
46+
{
47+
if (empty($tags) === true) {
48+
return null;
49+
}
50+
51+
// The first tag has priority over other tags in case there are multiple.
52+
return $tags[0];
53+
}
4154
}

src/Enum/Validation/Map/Base.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
use ToshY\BunnyNet\Model\Api\Base\StreamVideoLibrary\AddWatermark;
9292
use ToshY\BunnyNet\Model\Api\Base\StreamVideoLibrary\DeleteVideoLibrary;
9393
use ToshY\BunnyNet\Model\Api\Base\StreamVideoLibrary\DeleteWatermark;
94+
use ToshY\BunnyNet\Model\Api\Base\StreamVideoLibrary\GetDrmStatistics;
9495
use ToshY\BunnyNet\Model\Api\Base\StreamVideoLibrary\GetLanguages;
9596
use ToshY\BunnyNet\Model\Api\Base\StreamVideoLibrary\GetVideoLibrary;
9697
use ToshY\BunnyNet\Model\Api\Base\StreamVideoLibrary\ListVideoLibraries;
@@ -170,6 +171,7 @@ final class Base
170171
RemoveAllowedReferer::class => ModelValidationStrategy::STRICT_BODY,
171172
AddBlockedReferer::class => ModelValidationStrategy::STRICT_BODY,
172173
RemoveBlockedReferer::class => ModelValidationStrategy::STRICT_BODY,
174+
GetDrmStatistics::class => ModelValidationStrategy::STRICT_QUERY,
173175
ListDnsZones::class => ModelValidationStrategy::STRICT_QUERY,
174176
AddDnsZone::class => ModelValidationStrategy::STRICT_BODY,
175177
GetDnsZone::class => ModelValidationStrategy::NONE,

0 commit comments

Comments
 (0)