Skip to content

Commit a687e40

Browse files
authored
Merge pull request #160 from php-api-clients/pass-certain-information-on-to-file-templating
Pass certain information on to file templating
2 parents a60503a + 3abc86c commit a687e40

File tree

4 files changed

+61
-10
lines changed

4 files changed

+61
-10
lines changed

example/templates/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,37 @@
88
[![License](https://poser.pugx.org/api-clients/{{ packageName }}/license.png)](https://packagist.org/packages/api-clients/{{ packageName }})
99

1010
Non-Blocking first {{ fullName }} client, this is a read only sub split, see [`github-root`](https://github.com/php-api-clients/github-root).
11+
12+
{% if client.configuration.entryPoints.call == true or client.configuration.entryPoints.operations == true %}
13+
## Supported operations
14+
15+
{% for operation in client.operations %}
16+
17+
### {{ operation.operationId }}
18+
19+
{{ operation.summary }}
20+
21+
{% if client.configuration.entryPoints.call == true %}
22+
Using the `call` method:
23+
```php
24+
$client->call('{{ operation.matchMethod }} {{ operation.path }}'{% if operation.parameters|length > 0 %}, [
25+
{% for parameter in operation.parameters %} '{{ parameter.targetName }}' => {% if parameter.type == 'string' %}'{% endif %}{{ parameter.example.raw }}{% if parameter.type == 'string' %}'{% endif %},
26+
{% endfor %}]{% endif %});
27+
```
28+
{% endif %}
29+
30+
{% if client.configuration.entryPoints.operations == true %}
31+
Operations method:
32+
```php
33+
$client->operations()->{{ operation.groupCamel }}()->{{ operation.nameCamel }}({% if operation.parameters|length > 0 %}
34+
{% for parameter in operation.parameters %} {{ parameter.targetName }}: {% if parameter.type == 'string' %}'{% endif %}{{ parameter.example.raw }}{% if parameter.type == 'string' %}'{% endif %},
35+
{% endfor %}{% endif %});
36+
```
37+
{% endif %}
38+
39+
{% if operation.externalDocs != null %}
40+
You can find more about this operation over at the [{{ operation.externalDocs.description }}]({{ operation.externalDocs.url }}).
41+
{% endif %}
42+
43+
{% endfor %}
44+
{% endif %}

src/Gatherer/Operation.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,22 @@ public static function gather(
150150
$returnType[] = '\\' . ResponseInterface::class;
151151
}
152152

153+
$name = lcfirst(trim(Utils::basename($className), '\\'));
154+
$group = strlen(trim(trim(Utils::dirname($className), '\\'), '.')) > 0 ? trim(Utils::dirname($className), '\\') : 'Fallback';
155+
153156
return new \ApiClients\Tools\OpenApiClientGenerator\Representation\Operation(
154157
ClassString::factory($baseNamespace, 'Operation\\' . Utils::fixKeyword($className)),
155158
ClassString::factory($baseNamespace, $classNameSanitized),
156159
ClassString::factory($baseNamespace, 'Operator\\' . Utils::fixKeyword($className)),
157-
lcfirst(trim(Utils::basename($className), '\\')),
158-
strlen(trim(trim(Utils::dirname($className), '\\'), '.')) > 0 ? trim(Utils::dirname($className), '\\') : 'Fallback',
160+
$name,
161+
(new Convert($name))->toCamel(),
162+
$group,
163+
(new Convert($group))->toCamel(),
159164
$operation->operationId,
160165
strtoupper($matchMethod),
161166
strtoupper($method),
167+
$operation->summary,
168+
$operation->externalDocs,
162169
$path,
163170
$metaData,
164171
array_unique($returnType),

src/Generator.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -570,12 +570,23 @@ private function oneClient(
570570
\WyriHaximus\SubSplitTools\Files::setUp(
571571
$configurationLocation . $this->configuration->templates->dir,
572572
$configurationLocation . $this->configuration->destination->root . DIRECTORY_SEPARATOR,
573-
(static function (string $namespace, ?array $variables): array {
573+
(static function (string $namespace, ?array $variables, array $operations, array $webHooks, Configuration $configuration): array {
574574
$vars = $variables ?? [];
575575
$vars['namespace'] = $namespace;
576+
$vars['client'] = [
577+
'configuration' => $configuration,
578+
'operations' => $operations,
579+
'webHooks' => $webHooks,
580+
];
576581

577582
return $vars;
578-
})($this->configuration->namespace->source . '\\', $this->configuration->templates->variables),
583+
})(
584+
$this->configuration->namespace->source . '\\',
585+
$this->configuration->templates->variables,
586+
$operations,
587+
$webHooks,
588+
$this->configuration,
589+
),
579590
);
580591
$this->statusOutput->markStepDone('generating_templated_files');
581592
}
@@ -727,12 +738,6 @@ private function subSplitClient(
727738
$this->statusOutput->itemForStep('generating_schemas', count($schemas));
728739
foreach ($schemas as $schema) {
729740
if ($throwableSchemaRegistry->has($schema->className->relative)) {
730-
yield from Schema::generate(
731-
$this->configuration->subSplit->subSplitsDestination . DIRECTORY_SEPARATOR . $this->splitPathPrefix($this->configuration->subSplit->sectionPackage, 'common') . $this->configuration->destination->source,
732-
$schema,
733-
[...$schemaRegistry->aliasesForClassName($schema->className->relative)],
734-
);
735-
736741
yield from Error::generate(
737742
$this->configuration->subSplit->subSplitsDestination . DIRECTORY_SEPARATOR . $this->splitPathPrefix($this->configuration->subSplit->sectionPackage, 'common') . $this->configuration->destination->source,
738743
$schema,

src/Representation/Operation.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace ApiClients\Tools\OpenApiClientGenerator\Representation;
66

77
use ApiClients\Tools\OpenApiClientGenerator\ClassString;
8+
use cebe\openapi\spec\ExternalDocumentation;
89

910
final readonly class Operation
1011
{
@@ -21,10 +22,14 @@ public function __construct(
2122
public ClassString $classNameSanitized,
2223
public ClassString $operatorClassName,
2324
public string $name,
25+
public string $nameCamel,
2426
public string $group,
27+
public string $groupCamel,
2528
public string $operationId,
2629
public string $matchMethod,
2730
public string $method,
31+
public string $summary,
32+
public ?ExternalDocumentation $externalDocs,
2833
public string $path,
2934
/** @var array<mixed> $metaData */
3035
public array $metaData,

0 commit comments

Comments
 (0)