swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.01k stars 6.03k forks source link

[JAVA] Not possible to disable builder pattern in models #8076

Open rubena opened 6 years ago

rubena commented 6 years ago
Description

When we generate the Java client of the defined API, the model comes with a builder pattern that makes no possible to access attributes on Freemarker without using the full getter method name. It forces us to use ${item.getId()} instead of ${item.id} or change the generated code, which is not an option in a project where the model must be generated many times.

Swagger-codegen version

2.3.1

Command line used for generation

Maven plugin configuration:

<plugin>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>2.3.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/docs/api.yaml</inputSpec>
                            <language>java</language>
                            <configOptions>
                                <sourceFolder>src/gen/java/main</sourceFolder>
                                <dateLibrary>legacy</dateLibrary>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Suggest a fix/enhancement

A configuration option to disable builder generation

filip-majernik commented 6 years ago

Also it causes compile problems for Java if there are two fields named like this: 'identifier' and 'setIdentifier'. The java model class would contain two methods like this:

public void setIdentifier(String identifier) {
        this.identifier = identifier;
    }

public DocumentIdentificationDto withSetIdentifier(String setIdentifier) {
    this.setIdentifier = setIdentifier;
    return this;
}

It would be nice to be able to set a prefix for the Builder methods, e.g. 'with'. In the meantime if there any workaround?