Repository navigation
fix: generation errors for PHP 8.1+ targets with enums - #162
Merged
Merged
Conversation
- Enum case names that start with a digit (e.g. '+7 days') are prefixed
with V_ like numeric values, instead of producing an invalid 'case 7_DAYS'
that aborted the generation.
- Optional or nullable array-of-enum request parameters are only mapped to
their values when set; an unset parameter threw a TypeError from
array_map() on null.
- Enum header parameters are sent as their values, like query, path and
cookie parameters; the enum object itself made PSR-7 throw.
- Inline array-of-enum items are named {Operation}{Field}ItemEnum, like
inline array-of-object items, instead of all collapsing into one
Schema\Enum class with the values of only one of them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
CLIENT_PHP_VERSION8.1 or later the generator emits native PHP enums. Regenerating 42 real-world clients at 8.3 surfaced four bugs in that path. Each one either aborts generation or makes generated code throw at runtime. Targets below 8.1 generate string constants and are not affected. Their output is byte-identical except for the new test fixture.+7 dayscase 7_DAYS: invalid PHP, generation abortsEnumGenerator::getCaseName()prefixesV_whenever the name starts with a digit, not only when it is entirely numeric →case V_7_DAYSarray_map()onnull→ TypeError when the request is sent$this->x === null ? null : array_map(...), the same null handling scalar enums get via?->valuegetHeaders()goes through the same field mapping as query/path/cookie parameters, so it sends->valueSchema\Enumclass with only one field's values; with differing value sets, requests type-hint the wrong enum{Operation}{Field}Item+Enum, exactly like inline array-of-object items in the same branch ofFieldFactoryNo working output changes: #1–#3 only change code that was already invalid or always threw. #4 renames a generated class, so it ships as 11.3.0 (CHANGELOG entry included). Any client that regenerates with an existing
Schema\Enumgets the new per-operation names.Tests
EnumGeneratorTest::testGetCaseName(8 cases: words, separators, integers, a leading digit, decimals, negatives, empty).Request/getResourcesByStatuses.yaml, with a mandatory and an optional inline array-of-enum query parameter (one value starts with a digit). It has expected request classes for 7.4, 8.1 and 8.3 plus the expected item enum.'Accept' => $this->accept→$this->accept->value).make test: OK, 461 tests. php-cs-fixer: 0 files. PHPStan: no errors.+7 daysperiods and twocriterion_status_infilters with different value sets, and a story API) now generate at 8.3, lint clean on PHP 8.5, and get correct per-operation item enums.🤖 Generated with Claude Code