Make a copy of vendorExtensions map instead of copying the reference#4093
Make a copy of vendorExtensions map instead of copying the reference#4093wing328 merged 3 commits intoswagger-api:masterfrom
Conversation
…ng the reference
| } | ||
| output.vendorExtensions = this.vendorExtensions; | ||
| if(this.vendorExtensions != null){ | ||
| output.vendorExtensions = new HashMap<String, Object>(this.vendorExtensions); |
There was a problem hiding this comment.
Please use 4-space instead of tab.
Also what about vendorExtensions in other objects (e.g. CodegenProperty) ?
There was a problem hiding this comment.
4-space instead of tab done.
CodegenProperty implements Cloneable interface and use default cloning behavior. So members which are not primitive are copied by reference. We should rewrite the clone method to be prevent the copy by reference.
neither CodegenOperation nor CodegenModel doesn't support cloning feature and has no copy method.... but there's an InlineModelResolver which provides a copyVendorExtensions method.
There was a problem hiding this comment.
@RaphC have you committed/pushed the change? I only see 1 commit in this PR.
There was a problem hiding this comment.
@wing328 Not yet. I'm waiting for your feedback about CodegenProperty
There was a problem hiding this comment.
We should rewrite the clone method to be prevent the copy by reference.
Yes, please help contribute the enhancement.
There was a problem hiding this comment.
Right. I'll make a PR ASAP.
…ng the reference (swagger-api#4093) * swagger-api#3908 make a copy of vendorExtensions map instead of copying the reference * using 4-space instead of tab. * make a copy of vendorExtensions map instead of copying the reference
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates)2.3.0branch for breaking (non-backward compatible) changes.Description of the PR
In the method copy of the class CodegenParameter, we make a copy of vendorExtensions map instead of copying the reference to prevent unwanted instance modification of a copied instance.