Doxygen can be used to create software documentation using many input (and ouput) formats. Here we use it to combine doxygen tags that describe function parameters, a PlantUML diagram, and Markdown in one input to create an ouput HTML file.
Bring architecture closer to the code so that it is in sync with the code:
Looking at the different software documentation types, and where the source for that documenation should live, and what tool should be used to maintain this documentation, we get a table as follows:
Documentation Types | Where it lives | Tool |
---|---|---|
Source code APIs and usage with e.g. examples | In source code files in GIT | Doxygen |
Diagrams e.g. UML sequence diagram for dynamic view, UML Component or Class diagram for static structure | Beside source code files in GIT | PlantUML |
General verbose desriptions e.g. User guide, HowTo guides | Beside source code files in GIT | Markdown |
"Beside" means as close to the source code as makes sense e.g. as part of the repo for a given module, or even as part of the same source code file.
Doxygen supports all of the above!
Note: Swagger is a framework for building RESTful APIs around the OpenAPI Specification. It isn't a code document generator.
From http://www.doxygen.nl/index.html:
Doxygen is the de facto standard tool for generating documentation from annotated C++ sources, but it also supports other popular programming languages such as C, Objective-C, C#, PHP, Java, Python, IDL (Corba, Microsoft, and UNO/OpenOffice flavors), Fortran, VHDL, Tcl, and to some extent D.
Doxygen can help you in three ways:
- It can generate an on-line documentation browser (in HTML) and/or an off-line reference manual (in $\mbox{\LaTeX}$) from a set of documented source files. There is also support for generating output in RTF (MS-Word), PostScript, hyperlinked PDF, compressed HTML, and Unix man pages. The documentation is extracted directly from the sources, which makes it much easier to keep the documentation consistent with the source code.
- You can configure doxygen to extract the code structure from undocumented source files. This is very useful to quickly find your way in large source distributions. Doxygen can also visualize the relations between the various elements by means of include dependency graphs, inheritance diagrams, and collaboration diagrams, which are all generated automatically.
- You can also use doxygen for creating normal documentation (as I did for the doxygen user manual and web-site).
Markdown is very light-weight i.e. minimal overhead to add the markup and formatting.
Github (and other source code repositories) render markdown pages automatically when viewing the page in the repo.
Doxygen version 1.8.0 ownwds supports Markdown per http://www.doxygen.nl/manual/markdown.html.
PlantUML makes if very easy to create standard software diagrams. See https://www.mytechiebits.com/Plantuml.
Doxygen supports PlantUML per http://www.doxygen.nl/manual/commands.html#cmdstartuml
The Doxygen configfilename includes a section to configure PlantUML settings:
# When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the
# path where java can find the plantuml.jar file. If left blank, it is assumed
# PlantUML is not used or called during a preprocessing step. Doxygen will
# generate a warning when it encounters a \startuml command in this case and
# will not generate output for the diagram.
PLANTUML_JAR_PATH = /usr/local/bin/plantuml.jar
# When using plantuml, the PLANTUML_CFG_FILE tag can be used to specify a
# configuration file for plantuml.
PLANTUML_CFG_FILE =
# When using plantuml, the specified paths are searched for files specified by
# the !include statement in a plantuml block.
PLANTUML_INCLUDE_PATH =
The above HTML document is generated from this simple source file that contains:
We run doxygen in the source code directory:
$ doxygen ./configfilename
Source Code directory contains our source file:
/**
*
* Add 2 numbers and return the answer.
*
* @param A
* the first number to add
*
* @param B
* the second number to add
*
* @return
* the sum of A + B
@startuml
activate Sum
Input -> Sum: A
Input -> Sum: B
Sum -> Output: A + B
deactivate Sum
@enduml
Value | Description
------------- | -------------
A | First input parameter
B | Second input parameter
A+B | The sum of the 2 input parameters
*/
unsigned short int add (unsigned short int A, unsigned short int B)
{
return A+B;
}
Each section of the above source file is shown separately below:
unsigned short int add (unsigned short int A, unsigned short int B)
{
return A+B;
}
/**
*
* Add 2 numbers and return the answer.
*
* @param A
* the first number to add
*
* @param B
* the second number to add
*
* @return
* the sum of A + B
*/
Value | Description
------------- | -------------
A | First input parameter
B | Second input parameter
A+B | The sum of the 2 input parameters
@startuml
activate Sum
Input -> Sum: A
Input -> Sum: B
Sum -> Output: A + B
deactivate Sum
@enduml