swagger-gradle-plugin icon indicating copy to clipboard operation
swagger-gradle-plugin copied to clipboard

Generate swagger file from annotated interfaces

Open PiotrDros opened this issue 6 years ago • 2 comments

Hi, is that possible to plugin work with annotated interfaces instead of concrete spring RestController class? In Spring Boot 2.1.0 project I want to separate interface from implementation, in my case, BookController. So I created an interface IBookController and put on it all swagger/spring-web annotations. However, when I try to generate the swagger file (run gradle generateSwaggerDocumentation) it seems to ignore spring annotations (for example @RequestParam String filter in getBooks method).

https://github.com/PiotrDros/SpringSwagger/tree/feature/separate_interfaces/spring-swagger

PiotrDros avatar Nov 15 '18 12:11 PiotrDros

Hi, Same question for me, thanks!!

lferna avatar Nov 21 '18 15:11 lferna

Looks like in SpringMvcApiReader this is the culprit:

Set<Class<?>> getValidClasses() {
    Set<Class<?>> classes = Sets.union(classFinder.getValidClasses(Api, apiSource.locations), classFinder.getValidClasses(RestController, apiSource.locations))
    Set<Class<?>> copied = new HashSet<>(classes)
    for (Class<?> clazz : classes) {
        for (Class<?> aClazz : classes) {
            if (clazz != aClazz && clazz.isAssignableFrom(aClazz)) {
                copied.remove(clazz)
            }
        }
    }
    copied
}

My initial guess (without having debugged it) would be that it's picking up the lower classes and only using those. Of course I could be way off the mark on that though.

gigaSproule avatar Nov 30 '18 00:11 gigaSproule