swagger-api / swagger-api/swagger-codegen

Improve blank line break handling in generated code

Open
#7,173 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

Limiting number of empty line breaks in Mustache output is a known issue and it seems there will be no "fix" for that coming from Mustache team.

Example (generated with latest master):

  /**
   * Unique identifier for this bid. Read-only.
   * @return id
  **/
  @ApiModelProperty(value = "Unique identifier for this bid. Read-only.")



  public Long getId() {
    return id;
  }

This is clearly broken.

While Mustache is unable to fix this issue themselves (due to the way it generates output), Swagger Codegen can roll its own fix, following the example as outlined in that same issue.

Short summary: use some special non-whitespace character to represent line break in all templates. Post-process output from Mustache, removing all line breaks (\n) and replacing the special character with line breaks instead.

Swagger-codegen version

All versions so far.

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 locating the Mustache rendering path and the templates that produce the extra blank lines. Review the linked Mustache workaround, then verify that generated output removes unintended empty line breaks while preserving intended line breaks; the issue names no specific files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
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.