OpenAPITools / OpenAPITools/openapi-generator
[BUG][php-nextgen] Invalid class name used for nullable parameters (regression)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the php-nextgen generator and compare output from versions 2.17 and 2.18 using the provided openapi.json and Docker generation command. Done means nullable enum parameters retain the fully qualified class name with namespace separators in method signatures, documentation, and instantiation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, php
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 65/100