com.github.kongchen.swagger.docgen.mavenplugin.SpringMavenDocumentSource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swagger-maven-plugin Show documentation
Show all versions of swagger-maven-plugin Show documentation
A maven build plugin which helps you generate API document during build phase
The newest version!
package com.github.kongchen.swagger.docgen.mavenplugin;
import java.util.Set;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.RestController;
import com.github.kongchen.swagger.docgen.AbstractDocumentSource;
import com.github.kongchen.swagger.docgen.GenerateException;
import com.github.kongchen.swagger.docgen.reader.AbstractReader;
import com.github.kongchen.swagger.docgen.reader.ClassSwaggerReader;
import com.github.kongchen.swagger.docgen.reader.SpringMvcApiReader;
/**
* @author tedleman
* 01/21/15
* @author chekong
* 05/13/2013
*/
public class SpringMavenDocumentSource extends AbstractDocumentSource {
public SpringMavenDocumentSource(ApiSource apiSource, Log log, String encoding) throws MojoFailureException {
super(log, apiSource);
if(encoding !=null) {
this.encoding = encoding;
}
}
@Override
protected Set> getValidClasses() {
Set result = super.getValidClasses();
result.addAll(apiSource.getValidClasses(RestController.class));
result.addAll(apiSource.getValidClasses(ControllerAdvice.class));
return result;
}
@Override
protected ClassSwaggerReader resolveApiReader() throws GenerateException {
String customReaderClassName = apiSource.getSwaggerApiReader();
if (customReaderClassName == null) {
SpringMvcApiReader reader = new SpringMvcApiReader(swagger, LOG);
reader.setTypesToSkip(this.typesToSkip);
reader.setOperationIdFormat(this.apiSource.getOperationIdFormat());
return reader;
} else {
ClassSwaggerReader customApiReader = getCustomApiReader(customReaderClassName);
if (customApiReader instanceof AbstractReader) {
((AbstractReader)customApiReader).setOperationIdFormat(this.apiSource.getOperationIdFormat());
}
return customApiReader;
}
}
}