Skip to content

Commit b9419cc

Browse files
committed
fix multiline description and enum with invalid value
1 parent 4ddc657 commit b9419cc

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [11.1.2] - 2025.10.28
8+
### Fixed
9+
- Enum with invalid PHP constant value
10+
- README.md with multiline description in operations
11+
712
## [11.1.1] - 2025.09.23
813
### Fixed
914
- Acessing nullable enum with `?->value` instead of `->value?->value`

src/Generator/EnumGenerator.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class EnumGenerator extends MutatorAccessorClassGeneratorAbstract
1616

1717
public static function getCaseName(string $value): string
1818
{
19-
$sanitized = preg_replace('[^A-Z0-9_]', '', strtoupper(str_replace([' ', '-', '/', '.'], '_', $value)));
19+
$sanitized = preg_replace('/[^A-Z0-9_]/', '', strtoupper(str_replace([' ', '-', '/', '.'], '_', $value)));
2020

2121
if (is_numeric($sanitized)) {
2222
return 'V_' . $sanitized;
@@ -76,9 +76,14 @@ private function generateEnumConsts(Field $root): array
7676

7777
$statements = [];
7878
foreach ($root->getEnumValues() as $value) {
79+
$caseName = self::getCaseName((string)$value);
80+
if (empty($caseName)) {
81+
continue;
82+
}
83+
7984
$statements[] = $this
8085
->builder
81-
->enumCase(self::getCaseName((string)$value))
86+
->enumCase($caseName)
8287
->setValue($value);
8388
}
8489

src/Generator/MutatorAccessorClassGeneratorAbstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ protected function generateEnumStatements(Field $field): array
116116
$enumValues = $field->isArrayOfEnums() ? $field->getArrayItem()->getEnumValues() : $field->getEnumValues();
117117
if (!empty($enumValues)) {
118118
foreach ($enumValues as $enumValue) {
119-
if (is_string($enumValue)) {
119+
if (preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $enumValue)) {
120120
$constName = SchemaNaming::getEnumConstName($field, $enumValue);
121121
$statements[] = $this->builder->constant(
122122
$constName,

template/README.md.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ $result = $client->{{ exampleOperation.name }}($request);
4444
### {{ tag }}
4545
Endpoints:
4646
{% for operation in operations %}
47-
- **{{ operation.name }}**{% if operation.description is not empty %} - {{ operation.description }}{% endif %}
47+
- **{{ operation.name }}**{% if operation.description is not empty %} - {{ operation.description | trim | split('\n') | first }}{% endif %}
4848
4949
{% endfor %}
5050

0 commit comments

Comments
 (0)