-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Fix discriminator name not following variable naming convention #1742
Conversation
@@ -186,7 +186,7 @@ public function __construct(array $data = null) | |||
$this->container['color'] = isset($data['color']) ? $data['color'] : 'red'; | |||
|
|||
// Initialize discriminator property with the model name. | |||
$discriminator = array_search('className', self::$attributeMap, true); | |||
$discriminator = array_search('class_name', self::$attributeMap, true); | |||
$this->container[$discriminator] = static::$openAPIModelName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1) OpenAPI\Client\ModelInheritanceTest::testDiscriminatorInitialization
Failed asserting that null is identical to 'Dog'.
/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/tests/ModelInheritanceTest.php:70
+ $discriminator = array_search('class_name', self::$attributeMap, true);
$this->container[$discriminator] = static::$openAPIModelName;
Due to this PR, array_search
may become unnecessary. We can pass {{discriminatorName}}
to $this->container
directly as following.
- Mustache template
$this->container[{{discriminatorName}}] = static::$openAPIModelName;
- PHP code
- $discriminator = array_search('class_name', self::$attributeMap, true);
+ $this->container['class_name'] = static::$openAPIModelName;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌 I'll make the change later tonight.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update. LGTM ✨
…APITools#1742) * fix discrimintator name not following variable naming convention * fix test * update samples * use discriminator name directly in php * single quote array index
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.master
,. Default:3.4.x
,4.0.x
master
.Description of the PR
Fix discriminator name not following variable naming convention by using
toVarName
cc @OpenAPITools/generator-core-team