@bazo/openapi-client-generator 3.0.13 → 3.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -5
- package/bin.js +1043 -34
- package/package.json +1 -1
- package/skills/generate-client/SKILL.md +19 -8
- package/skills/integrate-php-client/SKILL.md +200 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @bazo/openapi-client-generator
|
|
2
2
|
|
|
3
|
-
Generate type-safe API clients from an OpenAPI / Swagger JSON spec. One CLI,
|
|
3
|
+
Generate type-safe API clients from an OpenAPI / Swagger JSON spec. One CLI, five output targets:
|
|
4
4
|
|
|
5
5
|
| Mode | Output | Stack |
|
|
6
6
|
|------|--------|-------|
|
|
@@ -8,6 +8,7 @@ Generate type-safe API clients from an OpenAPI / Swagger JSON spec. One CLI, fou
|
|
|
8
8
|
| `playwright` | `.ts` | Class wrapping Playwright's `APIRequestContext` for E2E tests + Zod validation |
|
|
9
9
|
| `swift` | `.swift` | `Codable` structs + `async/await` client (Foundation only) |
|
|
10
10
|
| `kotlin` | `.kt` | `@Serializable` data classes + Ktor-based suspend client |
|
|
11
|
+
| `php` | directory of `.php` | PSR-4 classes + backed enums + Symfony HttpClient/Serializer client |
|
|
11
12
|
|
|
12
13
|
Schemas are normalized, sorted by dependency, and emitted with full types; unused declarations are stripped from TypeScript output automatically.
|
|
13
14
|
|
|
@@ -35,11 +36,13 @@ openapi-client-generator <spec.json> <output-dir> -n <ClientName> [-m <mode>]
|
|
|
35
36
|
| `<spec.json>` | Path to the OpenAPI/Swagger JSON spec (positional, required) |
|
|
36
37
|
| `<output-dir>` | Directory to write the generated file into (positional, required) |
|
|
37
38
|
| `-n, --name` | Client/class name — must be a valid identifier (required) |
|
|
38
|
-
| `-m, --mode` | `full` \| `playwright` \| `swift` \| `kotlin` (default: `full`) |
|
|
39
|
+
| `-m, --mode` | `full` \| `playwright` \| `swift` \| `kotlin` \| `php` (default: `full`) |
|
|
40
|
+
| `--namespace` | Root PHP namespace, php mode only (default: `--name`) |
|
|
41
|
+
| `--php-version` | Target PHP version, php mode only: `8.0`–`8.5` (default: `8.1`) |
|
|
39
42
|
| `-v, --version` | Print version |
|
|
40
43
|
| `-h, --help` | Print help |
|
|
41
44
|
|
|
42
|
-
The output file is named after `--name` with the extension chosen by the mode (`MyClient.ts`, `ApiClient.swift`, `ApiClient.kt`).
|
|
45
|
+
The output file is named after `--name` with the extension chosen by the mode (`MyClient.ts`, `ApiClient.swift`, `ApiClient.kt`). The `php` mode instead writes a directory named after `--name` containing one PSR-4 file per class.
|
|
43
46
|
|
|
44
47
|
```bash
|
|
45
48
|
# React Query client
|
|
@@ -53,6 +56,9 @@ openapi-client-generator api.json Sources/Api -n ApiClient -m swift
|
|
|
53
56
|
|
|
54
57
|
# Kotlin client
|
|
55
58
|
openapi-client-generator api.json src/main/kotlin -n ApiClient -m kotlin
|
|
59
|
+
|
|
60
|
+
# PHP client
|
|
61
|
+
openapi-client-generator api.json src/Api -n ApiClient -m php --namespace "App\\Api" --php-version 8.2
|
|
56
62
|
```
|
|
57
63
|
|
|
58
64
|
A handy `package.json` script:
|
|
@@ -142,9 +148,25 @@ dependencies {
|
|
|
142
148
|
}
|
|
143
149
|
```
|
|
144
150
|
|
|
151
|
+
### `php` — Symfony HttpClient
|
|
152
|
+
|
|
153
|
+
Composer dependencies: `symfony/http-client`, `symfony/serializer`, `symfony/property-info`, `symfony/property-access`, `phpdocumentor/reflection-docblock`.
|
|
154
|
+
|
|
155
|
+
```php
|
|
156
|
+
use App\Api\ApiClient;
|
|
157
|
+
use Symfony\Component\HttpClient\HttpClient;
|
|
158
|
+
|
|
159
|
+
$api = new ApiClient(HttpClient::create(), 'https://api.example.com');
|
|
160
|
+
$response = $api->listTasks(page: 1, limit: 10);
|
|
161
|
+
$response->data; // typed model, hydrated via Symfony Serializer
|
|
162
|
+
$response->status; // 200
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Constructor: `new ApiClient(HttpClientInterface $client, string $baseUrl, ?SerializerInterface $serializer = null)` (a sensible serializer is built by the generated `SerializerFactory` when omitted). Output is a PSR-4 directory — models under `Model/`, plus `ApiResponse`, `ApiException` (thrown on every non-2xx), and the client class. `--php-version` gates emitted features: backed enums + `readonly` need 8.1+, `readonly class` 8.2+, typed constants 8.3+, `#[\Deprecated]` 8.4+, `#[\NoDiscard]` + `Uri\Rfc3986` URL building 8.5. Code generated for 8.0 uses serializer `^5.4|^6.x` (`AnnotationLoader`); 8.1+ requires serializer >= 6.4.
|
|
166
|
+
|
|
145
167
|
## Agent skills
|
|
146
168
|
|
|
147
|
-
The package ships [agent skills](skills/) — Markdown playbooks for AI coding agents covering CLI usage (`generate-client`) and per-mode integration (`integrate-{full,playwright,swift,kotlin}-client`). Compatible tools discover them automatically once the package is installed.
|
|
169
|
+
The package ships [agent skills](skills/) — Markdown playbooks for AI coding agents covering CLI usage (`generate-client`) and per-mode integration (`integrate-{full,playwright,swift,kotlin,php}-client`). Compatible tools discover them automatically once the package is installed.
|
|
148
170
|
|
|
149
171
|
## Development
|
|
150
172
|
|
|
@@ -160,7 +182,7 @@ task run # generate a sample client from fixtures/api.json into out/
|
|
|
160
182
|
|
|
161
183
|
Run a single test file: `bun vitest run src/__tests__/converter/primitives.test.ts`
|
|
162
184
|
|
|
163
|
-
See [CLAUDE.md](CLAUDE.md) for architecture details and the full task list. `task run-pw`, `task run-swift`, and `task run-
|
|
185
|
+
See [CLAUDE.md](CLAUDE.md) for architecture details and the full task list. `task run-pw`, `task run-swift`, `task run-kotlin`, and `task run-php` generate sample clients for the other modes. Runtime integration tests (`task test-runtime`) require a Java/Gradle toolchain (Kotlin), a Swift toolchain (Swift), or PHP >= 8.1 + Composer (PHP) and are skipped otherwise.
|
|
164
186
|
|
|
165
187
|
## License
|
|
166
188
|
|