Skip to content

Commit

Permalink
[FLINK-21193][docs] Update Rest API Generator to Hugo expand syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
sjwiesman committed Feb 10, 2021
1 parent 5b42f71 commit 7efc5f2
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 40 deletions.
3 changes: 1 addition & 2 deletions docs/assets/_custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ aside nav ul {
width: 0px;
}

/*
aside.book-menu nav {
a:hover {
font-weight: bold;
Expand All @@ -98,7 +97,7 @@ aside.book-menu nav {
font-weight: bold;
color: var(--body-font-color);
}
}*/
}

aside.book-menu > li {
padding: 10px 5px 5px 5px;
Expand Down
4 changes: 2 additions & 2 deletions flink-docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ To integrate a new endpoint into the generator
1. Add a new `DocumentingRestEndpoint` class to `RestAPIDocGenerator` that extends the new endpoint class
2. Add another call to `createHtmlFile` in `RestAPIDocGenerator#main`
3. Regenerate the documentation by running `mvn package -Dgenerate-rest-docs -pl flink-docs -am -nsu -DskipTests`
4. Integrate the generated file into the REST API documentation by adding `{% include generated/<file-name>.html %}` to the corresponding markdown file.
4. Integrate the generated file into the REST API documentation by adding `{{< generated/<file-name> }}` to the corresponding markdown file.

The documentation must be regenerated whenever
* a handler is added to/removed from a `RestServerEndpoint`
Expand All @@ -41,7 +41,7 @@ The `ConfigOptionsDocGenerator` can be use to generate a reference of `ConfigOpt

To integrate an `*Options` class from another package, add another module-package argument pair to `ConfigOptionsDocGenerator#LOCATIONS`.

The files can be generated by running `mvn package -Dgenerate-config-docs -pl flink-docs -am -nsu -DskipTests`, and can be integrated into the documentation using `{% include generated/<file-name>.html %}`.
The files can be generated by running `mvn package -Dgenerate-config-docs -pl flink-docs -am -nsu -DskipTests`, and can be integrated into the documentation using `{{ include generated/<file-name> >}}`.

The documentation must be regenerated whenever
* an `*Options` class was added or removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ private static boolean shouldBeDocumented(Field field) {
*/
private static String toHtmlTable(final List<OptionWithMetaInfo> options) {
StringBuilder htmlTable = new StringBuilder();
htmlTable.append("<table class=\"table table-bordered\">\n");
htmlTable.append("<table class=\"configuration table table-bordered\">\n");
htmlTable.append(" <thead>\n");
htmlTable.append(" <tr>\n");
htmlTable.append(" <th class=\"text-left\" style=\"width: 20%\">Key</th>\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private static String createHtmlEntry(MessageHeaders<?, ?, ?> spec) {

StringBuilder sb = new StringBuilder();
{
sb.append("<table class=\"table table-bordered\">\n");
sb.append("<table class=\"rest-api table table-bordered\">\n");
sb.append(" <tbody>\n");
sb.append(" <tr>\n");
sb.append(
Expand Down Expand Up @@ -220,32 +220,44 @@ private static String createHtmlEntry(MessageHeaders<?, ?, ?> spec) {
{
sb.append(" <tr>\n");
sb.append(" <td colspan=\"2\">\n");
sb.append(
" <button data-toggle=\"collapse\" data-target=\"#"
+ reqHash
+ "\">Request</button>\n");
sb.append(" <div id=\"" + reqHash + "\" class=\"collapse\">\n");
sb.append(" <div class=\"book-expand\">\n");
sb.append(" <label>\n");
sb.append(" <div class=\"book-expand-head flex justify-between\">\n");
sb.append(" <span>Request</span>\n");
sb.append(" &nbsp;");
sb.append(" <span>▾</span>\n");
sb.append(" </div>\n");
sb.append(" <input type=\"checkbox\" class=\"hidden\">\n");
sb.append(" <div class=\"book-expand-content markdown-inner\">\n");
sb.append(" <pre>\n");
sb.append(" <code>\n");
sb.append(requestEntry);
sb.append(" </code>\n");
sb.append(" </pre>\n");
sb.append(" </div>\n");
sb.append(" </div>\n");
sb.append(" </label>\n");
sb.append(" </div>\n");
sb.append(" </td>\n");
sb.append(" </tr>\n");
sb.append(" <tr>\n");
sb.append(" <td colspan=\"2\">\n");
sb.append(
" <button data-toggle=\"collapse\" data-target=\"#"
+ resHash
+ "\">Response</button>\n");
sb.append(" <div id=\"" + resHash + "\" class=\"collapse\">\n");
sb.append(" <div class=\"book-expand\">\n");
sb.append(" <label>\n");
sb.append(" <div class=\"book-expand-head flex justify-between\">\n");
sb.append(" <span>Response</span>\n");
sb.append(" &nbsp;");
sb.append(" <span>▾</span>\n");
sb.append(" </div>\n");
sb.append(" <input type=\"checkbox\" class=\"hidden\">\n");
sb.append(" <div class=\"book-expand-content markdown-inner\">\n");
sb.append(" <pre>\n");
sb.append(" <code>\n");
sb.append(responseEntry);
sb.append(" </code>\n");
sb.append(" </pre>\n");
sb.append(" </div>\n");
sb.append(" </div>\n");
sb.append(" </label>\n");
sb.append(" </div>\n");
sb.append(" </td>\n");
sb.append(" </tr>\n");
sb.append(" </tbody>\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static class TypeTestConfigGroup {
@Test
public void testCreatingTypes() {
final String expectedTable =
"<table class=\"table table-bordered\">\n"
"<table class=\"configuration table table-bordered\">\n"
+ " <thead>\n"
+ " <tr>\n"
+ " <th class=\"text-left\" style=\"width: 20%\">Key</th>\n"
Expand Down Expand Up @@ -179,7 +179,7 @@ public void testCreatingTypes() {
@Test
public void testCreatingDescription() {
final String expectedTable =
"<table class=\"table table-bordered\">\n"
"<table class=\"configuration table table-bordered\">\n"
+ " <thead>\n"
+ " <tr>\n"
+ " <th class=\"text-left\" style=\"width: 20%\">Key</th>\n"
Expand Down Expand Up @@ -307,7 +307,7 @@ public void testCreatingMultipleGroups() {
}

assertEquals(
"<table class=\"table table-bordered\">\n"
"<table class=\"configuration table table-bordered\">\n"
+ " <thead>\n"
+ " <tr>\n"
+ " <th class=\"text-left\" style=\"width: 20%\">Key</th>\n"
Expand All @@ -327,7 +327,7 @@ public void testCreatingMultipleGroups() {
+ "</table>\n",
tablesConverted.get("firstGroup"));
assertEquals(
"<table class=\"table table-bordered\">\n"
"<table class=\"configuration table table-bordered\">\n"
+ " <thead>\n"
+ " <tr>\n"
+ " <th class=\"text-left\" style=\"width: 20%\">Key</th>\n"
Expand All @@ -347,7 +347,7 @@ public void testCreatingMultipleGroups() {
+ "</table>\n",
tablesConverted.get("secondGroup"));
assertEquals(
"<table class=\"table table-bordered\">\n"
"<table class=\"configuration table table-bordered\">\n"
+ " <thead>\n"
+ " <tr>\n"
+ " <th class=\"text-left\" style=\"width: 20%\">Key</th>\n"
Expand Down Expand Up @@ -393,7 +393,7 @@ static class TestConfigGroupWithOverriddenDefault {
@Test
public void testOverrideDefault() {
final String expectedTable =
"<table class=\"table table-bordered\">\n"
"<table class=\"configuration table table-bordered\">\n"
+ " <thead>\n"
+ " <tr>\n"
+ " <th class=\"text-left\" style=\"width: 20%\">Key</th>\n"
Expand Down Expand Up @@ -442,7 +442,7 @@ public void testSections() throws IOException, ClassNotFoundException {
Formatter formatter = new HtmlFormatter();

String expected1 =
"<table class=\"table table-bordered\">\n"
"<table class=\"configuration table table-bordered\">\n"
+ " <thead>\n"
+ " <tr>\n"
+ " <th class=\"text-left\" style=\"width: 20%\">Key</th>\n"
Expand Down Expand Up @@ -480,7 +480,7 @@ public void testSections() throws IOException, ClassNotFoundException {
+ "</table>\n";

String expected2 =
"<table class=\"table table-bordered\">\n"
"<table class=\"configuration table table-bordered\">\n"
+ " <thead>\n"
+ " <tr>\n"
+ " <th class=\"text-left\" style=\"width: 20%\">Key</th>\n"
Expand Down Expand Up @@ -543,7 +543,7 @@ static class TestConfigGroupWithExclusion {
@Test
public void testConfigOptionExclusion() {
final String expectedTable =
"<table class=\"table table-bordered\">\n"
"<table class=\"configuration table table-bordered\">\n"
+ " <thead>\n"
+ " <tr>\n"
+ " <th class=\"text-left\" style=\"width: 20%\">Key</th>\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.apache.flink.docs.configuration.ConfigOptionsDocGenerator.COMMON_SECTION_FILE_NAME;
import static org.apache.flink.docs.configuration.ConfigOptionsDocGenerator.DEFAULT_PATH_PREFIX;
import static org.apache.flink.docs.configuration.ConfigOptionsDocGenerator.LOCATIONS;
import static org.apache.flink.docs.configuration.ConfigOptionsDocGenerator.extractConfigOptions;
Expand Down Expand Up @@ -222,20 +221,11 @@ private static void compareDocumentedAndExistingOptions(
}
}

private static Map<String, List<DocumentedOption>> parseDocumentedCommonOptions()
throws IOException {
final String rootDir = ConfigOptionsDocGeneratorTest.getProjectRootDir();

Path commonSection =
Paths.get(rootDir, "docs", "_includes", "generated", COMMON_SECTION_FILE_NAME);
return parseDocumentedOptionsFromFile(commonSection).stream()
.collect(Collectors.groupingBy(option -> option.key, Collectors.toList()));
}

private static Map<String, List<DocumentedOption>> parseDocumentedOptions() throws IOException {
final String rootDir = ConfigOptionsDocGeneratorTest.getProjectRootDir();

Path includeFolder = Paths.get(rootDir, "docs", "_includes", "generated").toAbsolutePath();
Path includeFolder =
Paths.get(rootDir, "docs", "layouts", "shortcodes", "generated").toAbsolutePath();
return Files.list(includeFolder)
.filter(
(path) -> {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ under the License.
to revisit the impact at that time.
-->
<minikdc.version>3.2.0</minikdc.version>
<generated.docs.dir>./docs/_includes/generated</generated.docs.dir>
<generated.docs.dir>./docs/layouts/shortcodes/generated</generated.docs.dir>
<hive.version>2.3.4</hive.version>
<hive-2.2.0-orc-version>1.4.3</hive-2.2.0-orc-version>
<orc.version>1.5.6</orc.version>
Expand Down

0 comments on commit 7efc5f2

Please sign in to comment.