Repository navigation
Expand file tree
/
Copy pathgenerate.php
More file actions
97 lines (86 loc) · 3.04 KB
/
Copy pathgenerate.php
File metadata and controls
97 lines (86 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* generate.php — Orchestrates generation of the Camunda Orchestration Cluster PHP SDK.
*
* Pipeline:
* 1. Run openapi-generator (php-nextgen) against the bundled spec -> generated/
* 2. Run post-generation hooks in hooks/post_gen/ (sorted) that:
* - emit validated semantic value-object types (generated/semantic/)
* - integrate the ObjectSerializer with those value objects
* - retype generated models/apis to use them
* - relicense / clean up generator boilerplate
*
* The generated/ tree is NEVER hand-edited. Regenerate via `make generate`.
*
* Usage:
* php generate.php [--spec external-spec/bundled/rest-api.bundle.json]
* [--metadata external-spec/bundled/spec-metadata.json]
* [--out generated] [--skip-openapi-generator]
*/
declare(strict_types=1);
$root = __DIR__;
$opts = getopt('', [
'spec:',
'metadata:',
'out:',
'config:',
'skip-openapi-generator',
]);
$spec = $opts['spec'] ?? 'external-spec/bundled/rest-api.bundle.json';
$metadata = $opts['metadata'] ?? 'external-spec/bundled/spec-metadata.json';
$out = $opts['out'] ?? 'generated';
$config = $opts['config'] ?? 'openapi-generator-config.yaml';
$specPath = realpathOrFail($root . '/' . $spec, 'bundled spec');
$metadataPath = file_exists($root . '/' . $metadata) ? realpath($root . '/' . $metadata) : null;
$outDir = $root . '/' . $out;
function realpathOrFail(string $path, string $what): string
{
$rp = realpath($path);
if ($rp === false) {
fwrite(STDERR, "error: $what not found at $path — run `make bundle-spec` first\n");
exit(1);
}
return $rp;
}
function log_step(string $msg): void
{
fwrite(STDOUT, "[generate] $msg\n");
}
// 1. openapi-generator ---------------------------------------------------------
if (!isset($opts['skip-openapi-generator'])) {
log_step('running openapi-generator (php-nextgen)...');
// Regenerate cleanly so removed operations/models do not linger.
exec('rm -rf ' . escapeshellarg($outDir));
$cmd = 'npx --yes @openapitools/openapi-generator-cli generate -c '
. escapeshellarg($config)
. ' -i ' . escapeshellarg($specPath)
. ' -o ' . escapeshellarg($outDir)
. ' 2>&1';
passthru($cmd, $code);
if ($code !== 0) {
fwrite(STDERR, "error: openapi-generator failed\n");
exit($code);
}
} else {
log_step('skipping openapi-generator (--skip-openapi-generator)');
}
// 2. post-gen hooks ------------------------------------------------------------
$context = [
'root' => $root,
'out_dir' => $outDir,
'spec_path' => $specPath,
'metadata_path' => $metadataPath,
];
$hooksDir = $root . '/hooks/post_gen';
$hooks = glob($hooksDir . '/*.php') ?: [];
sort($hooks);
foreach ($hooks as $hook) {
$run = require $hook;
if (!is_callable($run)) {
fwrite(STDERR, "warning: hook " . basename($hook) . " did not return a callable; skipping\n");
continue;
}
log_step('hook: ' . basename($hook));
$run($context);
}
log_step('done.');