OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAXRS-CXF] JaxRS cxf-ext samples expose developer home directories via testDataFile
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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