Skip to content

How to make smart doc load source code

shalousun edited this page Nov 3, 2019 · 11 revisions

Smart-doc is a tool that relies entirely on Java Comments to analyze and generate Restful API documentation. If there is no source code, you will only see information such as field name and field type when generating the document. Here's how to get Smart-doc to load source code from outside to your current project for generating API documentation:

Load local source code via ApiConfig

An example is as follows:

ApiConfig config = new ApiConfig();
// Use SourceCodePath to set the source code path
config.setSourceCodePaths(
         SourceCodePath.path().setDesc("Load external project source").setPath("E:\\Test\\Mybatis-PageHelper-master\\src\\main\\java")
);

With the above configuration, smart-doc can load and analyze external source code.

Specify the source jar package by maven classifier

An example is as follows:

<!--Dependent library -->
<dependency>
     <groupId>com.github.shalousun</groupId>
     <artifactId>common-util</artifactId>
     <version>1.8.7</version>
</dependency>
<!--Dependent library source code-->
<dependency>
     <groupId>com.github.shalousun</groupId>
     <artifactId>common-util</artifactId>
     <version>1.8.7</version>
     <classifier>sources</classifier>
     <!--Set to test, source will not be placed in the final product package when the project is released -->
     <scope>test</scope>
</dependency>

This does not require setting the source code load path as above.