You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: codegen/README.md
+55Lines changed: 55 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,3 +13,58 @@ Generate the SDK using:
13
13
```sh
14
14
go run ./... generate ./openapi.yaml ./build
15
15
```
16
+
17
+
## Features
18
+
19
+
### Enum Support
20
+
21
+
The codegen automatically generates PHP 8.1+ backed enums for properties with enum constraints in the OpenAPI specification. Enums are consolidated within their respective tag files alongside model classes.
22
+
23
+
For example, given an OpenAPI schema property:
24
+
25
+
```yaml
26
+
status:
27
+
type: string
28
+
enum:
29
+
- PENDING
30
+
- FAILED
31
+
- PAID
32
+
```
33
+
34
+
The generator creates:
35
+
1. A PHP enum (e.g., `CheckoutStatus` in `Checkouts.php`):
36
+
```php
37
+
enum CheckoutStatus: string
38
+
{
39
+
case PENDING = 'PENDING';
40
+
case FAILED = 'FAILED';
41
+
case PAID = 'PAID';
42
+
}
43
+
```
44
+
45
+
2. Model properties with enum types:
46
+
```php
47
+
public ?CheckoutStatus $status = null;
48
+
```
49
+
50
+
#### File Organization
51
+
52
+
All enums for a tag are generated at the top of the tag's PHP file, followed by the model classes. This keeps related enums and models together while minimizing the number of files.
53
+
54
+
**Example structure of `Checkouts.php`:**
55
+
```php
56
+
<?php
57
+
namespace SumUp\Checkouts;
58
+
59
+
enum CheckoutStatus: string { /* ... */ }
60
+
enum CardType: string { /* ... */ }
61
+
// ... other enums ...
62
+
63
+
class Checkout { /* ... */ }
64
+
class CheckoutRequest { /* ... */ }
65
+
// ... other classes ...
66
+
```
67
+
68
+
#### Autoloading
69
+
70
+
Generated files with multiple classes and enums are added to the `classmap` in `composer.json` to ensure proper autoloading.
0 commit comments