swagger-api / swagger-api/swagger-codegen
Provide an option to suppress "Unknown library option" message in JavaClientCodegen
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When developing custom libraries by extending the JavaClientCodegen, it prints an error message for any libraries the parent class doesn't recognise when doing procesOpts.
Unknown library option (-l/--library): myjavaclient
This is misleading and we should be able to control whether want to display this or not from subclasses.
Swagger-codegen version
Both 2.x and 3.x
It comes from https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java#L285 and https://github.com/swagger-api/swagger-codegen-generators/blob/master/src/main/java/io/swagger/codegen/v3/generators/java/JavaClientCodegen.java#L268
Steps to reproduce
- Extend
JavaClientCodegenand set custom library
public class MyJavaClientCodegen extends JavaClientCodegen {
public MyJavaClientCodegen() {
supportedLibraries.put("myjavaclient", "My Java client");
setLibrary("myjavaclient");
}
@Override
public String getName() {
return "myjavaclient";
}
}
- Run the codegen (v2 pseudo example shown)
new DefaultGenerator()
.opts(new CodegenConfigurator()
.setInputSpec("/path/to/spec")
.setOutputDir("/path/to/outputs")
.setLang("myjavaclient")
.toClientOptInput())
.generate();
- Observe that it prints
Unknown library option (-l/--library): myjavaclienteven though it generates the code successfully.
Suggest a fix/enhancement
I think one solution might be to expose a property (system/additional - please advise) that can be used to control whether this is logged. The default behaviour should be to continue logging unknown libraries. Let me know if you like this proposal and I will be more than happy to raise PRs for both v2 and v3 generators.
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 by reading JavaClientCodegen.java in the v2 and v3 generator paths identified in the issue, around the processOpts logic that reports unknown libraries. Check how subclasses register supportedLibraries and set a custom library. Done means custom libraries no longer produce the message when suppression is enabled, while unknown libraries still log it by default in both generator versions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100