swagger-api / swagger-api/swagger-codegen-generators

Filenames incorrect on windows due to inconsistent use of "/" and File.separator [Windows only, Jersey JAX-RS]

Open
#626 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
299
Forks
439
PR merge metrics
No merged PRs in 30d

Description

As of 1.0.17, becuase the DefaultCodegenConfig#apiFilename method uses File.separator to concatenate the filename, an issue occurs on windows that causes the generator to create files with incorrect package structures. This is a problem because some classes are expected to be in the same package, and this could also break ignore rules, leading to duplicate classes and other compilation issues. In the java JAX-RS generator, we check for a '/', causing the index to be inaccurate on Windows (or any other OS that doesn't use / as the file path separator), resulting in a the substring and replace calls not doing what is intended. The same happens in the Factory.mustache branch of the if statement.

We should use File.separator everywhere we are forming/checking file paths. Otherwise, we run the risk of assuming the OS the project is running on, and breaking compilation due to malformed paths.

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 with DefaultCodegenConfig.java at apiFilename and AbstractJavaJAXRSServerCodegen.java around line 227. Inspect the Factory.mustache branch as well, tracing where '/' is used while constructing or parsing paths. Done means path handling consistently uses File.separator and generated Windows package structures, ignore rules, and filenames no longer cause duplicate classes or compilation issues.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.