OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAXRS-CXF] JaxRS cxf-ext samples expose developer home directories via testDataFile

Open
#4,534 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is there a good use case for the JaxRS cxf-ext templates to allow the testDataFile to be specified at generation time?

Currently the mustache template drops this absolute path into the generated code:

File cacheFile = new File(System.getProperty("jaxrs.test.server.json",
        "{{testDataFile}}"));
cache = JsonCache.Factory.instance.get("test-data").load(cacheFile).child("/{{invokerPackage}}/{{classname}}");

Because of this, when we regenerate the petstore samples we typically leak personal home directory locations into the codebase and cause unnecessary churn in the history. But also, it instantly makes that generated project non-portable and it just seems unlikely to me that it's intentional - I'm struggling to see a good reason to do it this way.

Instead I wanted to propose the following change so that the default is to pull the resource from the class path instead of file system, but then realised it doesn't use the testDataFile property at all and suggests that we could drop it entirely:

final String property = System.getProperty("jaxrs.test.server.json");
if (property == null) {
    cache = JsonCache.Factory.instance.get("test-data")
            .load(FakeApiServiceImpl.class.getResourceAsStream("test-data.json"))
            .child("/{{invokerPackage}}/{{classname}}");
} else {
    cache = JsonCache.Factory.instance.get("test-data")
            .load(new File(property))
            .child("/{{invokerPackage}}/{{classname}}");
}

Is this a reasonable way forward or does it cause too much backwards compatibility pain?

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 modules/openapi-generator/src/main/resources/JavaJaxRS/cxf-ext/apiServiceImpl.mustache and inspect how testDataFile is supplied when the JaxRS cxf-ext samples are generated. Compare the generated petstore samples with the proposed classpath resource and system-property fallback. Done means regenerated samples no longer contain developer home directories while the existing override behavior is preserved or its compatibility impact is documented.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.