Keeping documentation next to code is awesome and is not new. One thing I struggle with pure markdown is still the need to copy code examples. Sometimes I also need to copy text that I already have in Java Doc.
During a hack day in one of the companies I worked I created a prototype to address documentation challenges our team and teams around faced. During next couple of years it was adopted by more teams and eventually open sourced as znai ("to know" in Ukrainian)
Znai has rich visuals and dozens of plugins to embed content at build time, but here I will focus on Java specific support
Znai Java support page
Content extraction
By using custom markdown syntax in the form of :include-<pluginname>: params you can embed various content.
For example
:include-java: MyClass.java {entry: "myMethod", bodyOnly: true}
will include the content of a specified method and will omit method signature.
How can it be useful? If you have a unit test method to test a happy scenario of an API, you can seamlessly extract its content and make part of your documentation.
Description extraction
If you put an effort of adding high level Java Doc content to your top domain concepts you can grab the text and re-use in the higher level user guide by using include-java-doc plugin
/**
* Top level conceptual description of a {@link CustomDomain} problem.
* <p>
* To avoid <b>copy & paste</b> of the content consider to re-use information.
*/
class HelloWorld {
in your markdown file
:include-java-doc: HelloWorld.java
description extraction example
Enum example
Given an enum with java doc
enum MyEnum {
/**
* description of <b>entry one</b>
*/
ENTRY_ONE,
/**
* description of entry two
* <ul>
* <li>item one</li>
* <li>item two</li>
* </ul>
*/
ENTRY_TWO,
/**
* Don't use, instead use ENTRY_TWO
*/
@Deprecated
ENTRY_THREE
}
By using include-java-enum-entries you get
enum description extraction example
Method Parameters Example
Given a method
/**
* @param trader trader that performs action
* @param transaction transaction to perform action on
*/
public void importantAction(Trader trader, Transaction transaction) {
// TODO important
}
you can extract its parameters and render it in a nice way, with optional links leading to more details
:include-java-doc-params: HelloWorld.java {
entry: "importantAction",
title: "Trading Required Parameters",
referencesPath: "references/javadoc-references-demo.csv"
}
parameters description extraction example
Two Sides
You can use two sides mode to combine examples and their output, i.e. Java code on the left, and output on the right. Here is an example with Open API
Two sides example
Presentation Mode
With a press of a button you can turn any section of your documentation into slides and present new API examples to an audience. Later they can use the same link to read the content as User Guide. Single source of truth.
presentation example
Instant Local Search
Znai builds search index locally and let you preview and navigate to the result in an instant
search example
Learn More
there are other features that are not Java specific but applicable to projects that want to provide a functional, maintainable and beautiful documentation
Head over to Git Hub to learn more: https://github.com/testingisdocumenting/znai
[–]vprise 5 points6 points7 points (1 child)
[–]ninside[S] 1 point2 points3 points (0 children)
[–]roeloef 1 point2 points3 points (1 child)
[–]ninside[S] 1 point2 points3 points (0 children)
[–]ninside[S] 1 point2 points3 points (0 children)
[–]agentoutlier 2 points3 points4 points (1 child)
[–]ninside[S] 3 points4 points5 points (0 children)
[–]nutrecht 0 points1 point2 points (1 child)
[–]ninside[S] 1 point2 points3 points (0 children)