Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHP][php-nextgen] Fix usage of enums in parameters (Fix #20086) #20294

Merged
merged 1 commit into from
Dec 16, 2024

Conversation

JulianVennen
Copy link
Contributor

Using enums in path, header or query parameters with the php-nextgen generator currently causes type errors like the following:

PHP Fatal error:  Uncaught TypeError: OpenAPI\Client\ObjectSerializer::toPathValue(): Argument #1 ($value) must be of type string, OpenAPI\Client\Model\IntEnum given, called in /tmp/openapi-tests/src/Api/DefaultApi.php on line 1183 and defined in /tmp/openapi-tests/src/ObjectSerializer.php:165
Stack trace:
#0 /tmp/openapi-tests/src/Api/DefaultApi.php(1183): OpenAPI\Client\ObjectSerializer::toPathValue()
#1 /tmp/openapi-tests/src/Api/DefaultApi.php(1051): OpenAPI\Client\Api\DefaultApi->pathIntPGetRequest()
#2 /tmp/openapi-tests/src/Api/DefaultApi.php(1033): OpenAPI\Client\Api\DefaultApi->pathIntPGetWithHttpInfo()
#3 /tmp/openapi-tests/dev.php(11): OpenAPI\Client\Api\DefaultApi->pathIntPGet()
#4 {main}
  thrown in /tmp/openapi-tests/src/ObjectSerializer.php on line 165

Example spec: https://gist.github.com/JulianVennen/237b96487d45bbe24b3b174e0e7a758c

This PR fixes those errors by passing the value to these functions instead.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in Git BASH)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
    @jebentier @dkarlovi @mandrean @jfastnacht @ybelenko @renepardon

@@ -711,7 +711,7 @@ use {{invokerPackage}}\ObjectSerializer;
{{#queryParams}}
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
${{paramName}},
${{paramName}}{{#isEnumRef}}->value{{/isEnumRef}},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about inline enum? shall we use isEnumOrRef instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An inline enum for that would look like this, right?

paths:
  /path-int/{p}:
    get:
      parameters:
        - name: p
          in: path
          required: true
          description: Integer option in path
          schema:
            type: integer
            enum:
              - 0
              - 1
              - 2
            x-enum-varnames:
              - ZERO
              - ONE
              - TWO
      responses:
        '200':
          description: OK

That does not generate any model classes or constants in the php-nextgen generator.
The type of the function parameter is just int or string so adding ->value would be incorrect.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

let's give it a try

@JulianVennen JulianVennen requested a review from wing328 December 15, 2024 13:06
@JulianVennen JulianVennen changed the title [PHP][php-nextgen] Fix usage of enums in parameters [PHP][php-nextgen] Fix usage of enums in parameters (Fix #20086) Dec 15, 2024
@wing328 wing328 merged commit e87c4ea into OpenAPITools:master Dec 16, 2024
16 checks passed
@wing328 wing328 added this to the 7.11.0 milestone Dec 16, 2024
@JulianVennen JulianVennen deleted the backed-enum-params branch December 20, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants