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

Fix discriminator name not following variable naming convention #1742

Merged
merged 5 commits into from Dec 24, 2018

Conversation

wing328
Copy link
Member

@wing328 wing328 commented Dec 22, 2018

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./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\.
  • Filed the PR against the correct branch: master, 3.4.x, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

Fix discriminator name not following variable naming convention by using toVarName

cc @OpenAPITools/generator-core-team

@@ -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;
Copy link
Contributor

@ackintosh ackintosh Dec 23, 2018

Choose a reason for hiding this comment

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

https://travis-ci.org/OpenAPITools/openapi-generator/builds/471525982?utm_source=github_status&utm_medium=notification

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;	

Copy link
Member Author

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.

Copy link
Contributor

@ackintosh ackintosh left a 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 ✨

@wing328 wing328 merged commit 0dee995 into master Dec 24, 2018
@wing328 wing328 deleted the fix_java_inheritance branch December 24, 2018 09:12
A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
…APITools#1742)

* fix discrimintator name not following variable naming convention

* fix test

* update samples

* use discriminator name directly in php

* single quote array index
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.

None yet

2 participants