Skip to content

[BUG][php-nextgen] Invalid class name used for nullable parameters (regression) #23141

@frozenbrain

Description

@frozenbrain

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

We're generating OpenAPI docs from a Symfony project using the NelmioApiDocBundle.

Example endpoint for reference:

public function test(#[MapQueryParameter] ?TestEnum $testParam = null): JsonResponse { /* ... */ }

This generates an endpoint with a parameter that looks like this (full sample linked below):

{
  "name": "testParam",
  "in": "query",
  "schema": {
    "oneOf": [
      { "$ref": "#/components/schemas/TestEnum" },
      { "type": "null" }
    ],
    "default": null
  }
}

Up until 2.17 the generated method looked like this and was working fine (shortened):

/**
 * @param  \OpenAPI\Client\Model\TestEnum|null $test_param test_param (optional)
 */
public function test(
    ?\OpenAPI\Client\Model\TestEnum $test_param = null
): void { /* ... */ }

Since 2.18 the output is broken, as the FQCN is missing the backslashes:

/**
 * @param  \OpenAPIClientModelTestEnum|null $test_param test_param (optional)
 */
public function test(
    ?\OpenAPIClientModelTestEnum $test_param = null
): void { /* ... */ }

The docs are also affected by this, although the example code was already broken (in a different way) with 2.17. Aside from that, at least the client itself worked. For comparison:

// 2.17
$test_param = new \OpenAPI\Client\Model\\OpenAPI\Client\Model\TestEnum(); // \OpenAPI\Client\Model\TestEnum
// ...
/*
| Name | Type | Description  | Notes |
| ------------- | ------------- | ------------- | ------------- |
| **test_param** | [**\OpenAPI\Client\Model\TestEnum**](../Model/.md)|  | [optional] |
*/

// latest
$test_param = new \OpenAPI\Client\Model\\OpenAPIClientModelTestEnum(); // \OpenAPIClientModelTestEnum
// ...
/*
| Name | Type | Description  | Notes |
| ------------- | ------------- | ------------- | ------------- |
| **test_param** | [**\OpenAPIClientModelTestEnum**](../Model/.md)|  | [optional] |
*/
openapi-generator version

Worked from 2.14 to 2.17.
Broken since 2.18.

OpenAPI declaration file content or url

https://gist.github.com/frozenbrain/8f36f90d00ca61a3b7056726ce80514e

Generation Details

docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:latest generate --generator-name php-nextgen --input-spec /local/openapi.json --output /local/client-latest

Steps to reproduce

Generate a client using the command above from the provided openapi.json file.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions