swagger-api / swagger-api/swagger-codegen

[JAVA] Not possible to disable builder pattern in models

Open
#8,076 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the Java model generation path used by the swagger-codegen Maven plugin and reviewing how generator configuration options reach the model templates. Confirm how builder methods are currently emitted and identify the existing generation tests. Done means a configuration option can disable builders while preserving the default behavior and is covered by generation tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.