-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot generate swagger.json when JAX-RS annotated endpoints comes from superclass #140
Comments
This issue is caused by the ASM library (used to analyze a class) not scanning super classes by design - hence A general fix approach is to recursively visit any superclasses that exist (if a class has no private void analyzeClass(final String className, ClassResult classResult) {
try {
final ClassReader classReader = new ContextClassReader(className);
final ClassVisitor visitor = new JAXRSClassVisitor(classResult);
classReader.accept(visitor, ClassReader.EXPAND_FRAMES);
// recursively visit any super classes
if (!classReader.getSuperName().equals("java/lang/Object")) {
analyzeClass(classReader.getSuperName(), classResult);
}
} catch (IOException e) {
LogProvider.error("The class " + className + " could not be loaded!");
LogProvider.debug(e);
}
} With the above approach, I was then seeing issues with the JavaDocs missing but the following fixed it for me - i.e. replace private void combineResults(final Set<ClassResult> classResults) {
classResults.stream()
.flatMap(classResult -> classResult.getMethods().stream()) // flatten our set of sets (multiple methods within multiple class results) into one set
.forEach(methodResult -> {
// For our single methodResult, see if we have a matching entry in the methodComments map (if we do, set the 'methodDoc' property)
this.methodComments.entrySet().stream()
.filter(entry -> equalsSimpleTypeNames(entry.getKey(), methodResult))
.map(Entry::getValue)
.findAny()
.ifPresent(methodResult::setMethodDoc);
});
} I'll look to submit a PR for this shortly. |
Cannot generate swagger.json when JAX-RS annotated endpoints comes from superclass.
This issue related to maven plugin (0.16). In case I extend generic abstract class with JAX-RS endpoints and do add any endpoint to actual resource, then I'm receiving empty endpoint in swagger.json.
When I adding the endpoint to the actual resource implementation, its metadata exposed in swagger.json (like news/some at the above code snippet), but not the metadata of the endpoints from the parent abstract classes.
I will also try to debug the jaxrs-analyzer by myself.
Thanks!
The text was updated successfully, but these errors were encountered: