Skip to content

[JAVA] CodegenParameter instance copy is not safe #3908

@RaphC

Description

@RaphC

Hi,

Description

I'm using swagger codegen maven plugin to generate from swagger file our Java class with my own generator. I extended JavaJAXRSSpecServerCodegen to add some feature like ignoring some of parameters in the methods which are described in the swagger file. To do that, I set a vendor extensions and then when the plugin invokes fromOperation It ignores the parameters with these extension. In my code I have to make a copy of the CodegenParameter.

List printableParams = Lists.newLinkedList();
for (CodegenParameter p : op.allParams) {
....
printableParams.add(p.copy());
}

Unfortunately when copying CodegenParameter instance, the attribute vendorExtensions is copied by reference.

output.vendorExtensions = this.vendorExtensions;

So If the current instance p modify its vendorExtensions Map (add a new element for instance), my new cloned instance is affected by whereas it shouldn't be.

Swagger-codegen version

2.2.1

Swagger declaration file content or url
Command line used for generation
Steps to reproduce
Related issues
Suggest a Fix

Just make a copy of attribute vendorExtensions in the method copy() of CodegenParameter instead of copying reference

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions