We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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 generator produce a invalid php file when shema have an enum with default value.
PHP Warning: Use of undefined constant TYPE_MOVE - assumed 'TYPE_MOVE' (this will throw an Error in a future version of PHP)
Tested with php 7.4
5.1.1, 5.2.1, master
openapi: 3.0.0 info: title: 'Enum Bug' version: latest paths: '/': get: operationId: demoBug responses: '200': description: Success content: application/json: schema: $ref: '#/components/schemas/MoveMovement' components: schemas: MoveMovement: required: - type properties: type: type: string default: MOVE enum: - MOVE
docker run --rm -v ${PWD}:/local --user "${USER_ID}:${GROUP_ID}" openapitools/openapi-generator-cli:latest generate -i /local/model.yaml -g php -o /local/php
Generate php model with an enum property with default value
The model constructor will have invalid php code
const TYPE_MOVE = 'MOVE'; ... public function __construct(array $data = null) { $this->container['type'] = $data['type'] ?? TYPE_MOVE; }
should be
$this->container['type'] = $data['type'] ?? self::TYPE_MOVE;
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java
@Override public String toEnumDefaultValue(String value, String datatype) { return "self::" + datatype + "_" + value; }
The text was updated successfully, but these errors were encountered:
Can you please file a PR with the suggested fix?
Sorry, something went wrong.
Issue OpenAPITools#10244 fix php enum default value initialization
282496a
@wing328 Now I did #10273
Issue #10244 fix php enum default value initialization (#10273)
f9fa62a
Co-authored-by: Eric Durand-Tremblay <[email protected]>
Successfully merging a pull request may close this issue.
Description
PHP generator produce a invalid php file when shema have an enum with default value.
Tested with php 7.4
openapi-generator version
5.1.1, 5.2.1, master
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Generate php model with an enum property with default value
The model constructor will have invalid php code
should be
Suggest a fix
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java
The text was updated successfully, but these errors were encountered: