You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by pa...@apache.org on 2026/04/04 00:56:37 UTC

(flink) branch master updated: [FLINK-39359][docs] Introduce integration test cases to ensure that the generated REST-API related documentation stays consistent with the code. (#27884)

This is an automated email from the ASF dual-hosted git repository.

panyuepeng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/master by this push:
     new 9b3037ba399 [FLINK-39359][docs] Introduce integration test cases to ensure that the generated REST-API related documentation stays consistent with the code. (#27884)
9b3037ba399 is described below

commit 9b3037ba3993080c23e56c86f72194adff0b6037
Author: Yuepeng Pan <hi...@gmail.com>
AuthorDate: Sat Apr 4 08:56:29 2026 +0800

    [FLINK-39359][docs] Introduce integration test cases to ensure that the generated REST-API related documentation stays consistent with the code. (#27884)
    
    Co-authored-by: 1996fanrui <19...@gmail.com>
    Co-authored-by: Sergey Nuyanzin <sn...@gmail.com>
---
 .../docs/rest/RuntimeOpenApiSpecGenerator.java     |  4 +-
 .../docs/rest/SqlGatewayOpenApiSpecGenerator.java  |  4 +-
 .../java/org/apache/flink/docs/util/Utils.java     | 13 ++++
 .../ConfigOptionsDocGeneratorTest.java             | 12 +--
 .../ConfigOptionsDocsCompletenessITCase.java       |  5 +-
 .../configuration/ConfigOptionsYamlSpecTest.java   |  3 +-
 .../RuntimeOpenRestAPIDocsCompletenessITCase.java  | 87 ++++++++++++++++++++++
 ...qlGatewayOpenRestAPIDocsCompletenessITCase.java | 76 +++++++++++++++++++
 8 files changed, 188 insertions(+), 16 deletions(-)

diff --git a/flink-docs/src/main/java/org/apache/flink/docs/rest/RuntimeOpenApiSpecGenerator.java b/flink-docs/src/main/java/org/apache/flink/docs/rest/RuntimeOpenApiSpecGenerator.java
index 00e30689ba5..a12b38000f5 100644
--- a/flink-docs/src/main/java/org/apache/flink/docs/rest/RuntimeOpenApiSpecGenerator.java
+++ b/flink-docs/src/main/java/org/apache/flink/docs/rest/RuntimeOpenApiSpecGenerator.java
@@ -36,6 +36,8 @@ import static org.apache.flink.docs.rest.OpenApiSpecGenerator.createDocumentatio
  */
 public class RuntimeOpenApiSpecGenerator {
 
+    public static final String RUNTIME_OPEN_API_TITLE = "Flink JobManager REST API";
+
     /**
      * Generates the Runtime REST API OpenAPI spec.
      *
@@ -51,7 +53,7 @@ public class RuntimeOpenApiSpecGenerator {
                 continue;
             }
             createDocumentationFile(
-                    "Flink JobManager REST API",
+                    RUNTIME_OPEN_API_TITLE,
                     new DocumentingDispatcherRestEndpoint(),
                     apiVersion,
                     Paths.get(
diff --git a/flink-docs/src/main/java/org/apache/flink/docs/rest/SqlGatewayOpenApiSpecGenerator.java b/flink-docs/src/main/java/org/apache/flink/docs/rest/SqlGatewayOpenApiSpecGenerator.java
index 4596c6ba5b8..b3fb6cb6fcf 100644
--- a/flink-docs/src/main/java/org/apache/flink/docs/rest/SqlGatewayOpenApiSpecGenerator.java
+++ b/flink-docs/src/main/java/org/apache/flink/docs/rest/SqlGatewayOpenApiSpecGenerator.java
@@ -36,6 +36,8 @@ import static org.apache.flink.docs.rest.OpenApiSpecGenerator.createDocumentatio
  */
 public class SqlGatewayOpenApiSpecGenerator {
 
+    public static final String SQL_GATEWAY_OPEN_API_TITLE = "Flink SQL Gateway REST API";
+
     /**
      * Generates the Sql Gateway REST API OpenAPI spec.
      *
@@ -51,7 +53,7 @@ public class SqlGatewayOpenApiSpecGenerator {
                 continue;
             }
             createDocumentationFile(
-                    "Flink SQL Gateway REST API",
+                    SQL_GATEWAY_OPEN_API_TITLE,
                     new DocumentingSqlGatewayRestEndpoint(),
                     apiVersion,
                     Paths.get(
diff --git a/flink-docs/src/main/java/org/apache/flink/docs/util/Utils.java b/flink-docs/src/main/java/org/apache/flink/docs/util/Utils.java
index 43e2a44b8dd..2b75f6b6ad3 100644
--- a/flink-docs/src/main/java/org/apache/flink/docs/util/Utils.java
+++ b/flink-docs/src/main/java/org/apache/flink/docs/util/Utils.java
@@ -18,6 +18,8 @@
 
 package org.apache.flink.docs.util;
 
+import java.io.File;
+
 /** Contains various shared utility functions. */
 public enum Utils {
     ;
@@ -34,4 +36,15 @@ public enum Utils {
                 .replaceAll(">", "&gt;")
                 .replaceAll(TEMPORARY_PLACEHOLDER, "<wbr>");
     }
+
+    public static String getProjectRootDir() {
+        final String dirFromProperty = System.getProperty("rootDir");
+        if (dirFromProperty != null) {
+            return dirFromProperty;
+        }
+
+        // to make this work in the IDE use a default fallback
+        final String currentDir = System.getProperty("user.dir");
+        return new File(currentDir).getParent();
+    }
 }
diff --git a/flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsDocGeneratorTest.java b/flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsDocGeneratorTest.java
index b7ce9f6f51d..487dd9ab52f 100644
--- a/flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsDocGeneratorTest.java
+++ b/flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsDocGeneratorTest.java
@@ -49,6 +49,7 @@ import java.util.List;
 import java.util.Map;
 
 import static org.apache.flink.configuration.description.TextElement.text;
+import static org.apache.flink.docs.util.Utils.getProjectRootDir;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatException;
 import static org.assertj.core.api.Assertions.assertThatNoException;
@@ -768,15 +769,4 @@ class ConfigOptionsDocGeneratorTest {
                                 ConfigOptionsDocGenerator.verifyClassAnnotation(
                                         InternalOptions.class));
     }
-
-    static String getProjectRootDir() {
-        final String dirFromProperty = System.getProperty("rootDir");
-        if (dirFromProperty != null) {
-            return dirFromProperty;
-        }
-
-        // to make this work in the IDE use a default fallback
-        final String currentDir = System.getProperty("user.dir");
-        return new File(currentDir).getParent();
-    }
 }
diff --git a/flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsDocsCompletenessITCase.java b/flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsDocsCompletenessITCase.java
index 79831e1e0a8..1555a5534db 100644
--- a/flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsDocsCompletenessITCase.java
+++ b/flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsDocsCompletenessITCase.java
@@ -22,6 +22,7 @@ import org.apache.flink.api.java.tuple.Tuple2;
 import org.apache.flink.configuration.ConfigOption;
 import org.apache.flink.docs.util.ConfigurationOptionLocator;
 import org.apache.flink.docs.util.OptionWithMetaInfo;
+import org.apache.flink.docs.util.Utils;
 
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
@@ -232,7 +233,7 @@ class ConfigOptionsDocsCompletenessITCase {
     }
 
     private static Map<String, List<DocumentedOption>> parseDocumentedOptions() throws IOException {
-        final String rootDir = ConfigOptionsDocGeneratorTest.getProjectRootDir();
+        final String rootDir = Utils.getProjectRootDir();
 
         Path includeFolder =
                 Paths.get(rootDir, "docs", "layouts", "shortcodes", "generated").toAbsolutePath();
@@ -284,7 +285,7 @@ class ConfigOptionsDocsCompletenessITCase {
 
     private static Map<String, List<ExistingOption>> findExistingOptions(
             Predicate<OptionWithMetaInfo> predicate) throws Exception {
-        final String rootDir = ConfigOptionsDocGeneratorTest.getProjectRootDir();
+        final String rootDir = Utils.getProjectRootDir();
 
         final Collection<ExistingOption> existingOptions = new ArrayList<>();
         new ConfigurationOptionLocator()
diff --git a/flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsYamlSpecTest.java b/flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsYamlSpecTest.java
index 8eca1094302..1e00a3b1b9a 100644
--- a/flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsYamlSpecTest.java
+++ b/flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsYamlSpecTest.java
@@ -29,6 +29,7 @@ import java.util.List;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
+import static org.apache.flink.docs.util.Utils.getProjectRootDir;
 import static org.assertj.core.api.Assertions.assertThat;
 
 /**
@@ -44,7 +45,7 @@ class ConfigOptionsYamlSpecTest {
         final Collection<String> allOptions = new ArrayList<>();
         new ConfigurationOptionLocator()
                 .discoverOptionsAndApply(
-                        Paths.get(ConfigOptionsDocGeneratorTest.getProjectRootDir()),
+                        Paths.get(getProjectRootDir()),
                         (aClass, optionWithMetaInfos) -> {
                             optionWithMetaInfos.stream()
                                     .filter(o -> o.field.getAnnotation(Deprecated.class) == null)
diff --git a/flink-docs/src/test/java/org/apache/flink/docs/rest/RuntimeOpenRestAPIDocsCompletenessITCase.java b/flink-docs/src/test/java/org/apache/flink/docs/rest/RuntimeOpenRestAPIDocsCompletenessITCase.java
new file mode 100644
index 00000000000..a3088674e73
--- /dev/null
+++ b/flink-docs/src/test/java/org/apache/flink/docs/rest/RuntimeOpenRestAPIDocsCompletenessITCase.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.docs.rest;
+
+import org.apache.flink.docs.util.Utils;
+import org.apache.flink.runtime.rest.util.DocumentingDispatcherRestEndpoint;
+import org.apache.flink.runtime.rest.versioning.RuntimeRestAPIVersion;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import static org.apache.flink.docs.rest.RuntimeOpenApiSpecGenerator.RUNTIME_OPEN_API_TITLE;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Verifies that generated Runtime REST and Open API docs (HTML + OpenAPI yml) match committed
+ * files.
+ *
+ * <p>This acts as a freshness check to ensure the documentation stays in sync with the code.
+ */
+class RuntimeOpenRestAPIDocsCompletenessITCase {
+
+    @Test
+    void testRuntimeRestApiDocsUpToDate(@TempDir Path tempDir) throws Exception {
+        final DocumentingDispatcherRestEndpoint endpoint = new DocumentingDispatcherRestEndpoint();
+        for (final RuntimeRestAPIVersion apiVersion : RuntimeRestAPIVersion.values()) {
+            if (apiVersion == RuntimeRestAPIVersion.V0) {
+                continue;
+            }
+            final String version = apiVersion.getURLVersionPrefix();
+            String targetHtmlName = String.format("rest_%s_dispatcher.html", version);
+            final Path pathOfGeneratedHtml = tempDir.resolve(targetHtmlName);
+            final Path pathOfCommittedHtml = getPathOfCommittedHtml(targetHtmlName);
+            RestAPIDocGenerator.createHtmlFile(endpoint, apiVersion, pathOfGeneratedHtml);
+            assertThat(pathOfCommittedHtml)
+                    .as("Missing committed %s file: %s", targetHtmlName, pathOfCommittedHtml)
+                    .exists()
+                    .as(
+                            "Committed `%s` file is out of date. Please regenerate docs under `flink-docs` module based on `README.md`.",
+                            targetHtmlName)
+                    .hasSameTextualContentAs(pathOfGeneratedHtml);
+
+            String targetYmlName = String.format("rest_%s_dispatcher.yml", version);
+            final Path pathOfGeneratedYml = tempDir.resolve(targetYmlName);
+            final Path pathOfCommittedYml = getPathOfCommittedYaml(targetYmlName);
+            OpenApiSpecGenerator.createDocumentationFile(
+                    RUNTIME_OPEN_API_TITLE, endpoint, apiVersion, pathOfGeneratedYml);
+            assertThat(pathOfCommittedYml)
+                    .as("Missing committed %s file: %s", targetYmlName, pathOfCommittedYml)
+                    .exists()
+                    .as(
+                            "Committed `%s` file is out of date. Please regenerate docs under `flink-docs` module based on `README.md`.",
+                            targetYmlName)
+                    .hasSameTextualContentAs(pathOfGeneratedYml);
+        }
+    }
+
+    static Path getPathOfCommittedHtml(String fileName) {
+        final String rootDir = Utils.getProjectRootDir();
+        return Paths.get(rootDir, "docs", "layouts", "shortcodes", "generated", fileName)
+                .toAbsolutePath();
+    }
+
+    static Path getPathOfCommittedYaml(String fileName) {
+        final String rootDir = Utils.getProjectRootDir();
+        return Paths.get(rootDir, "docs", "static", "generated", fileName).toAbsolutePath();
+    }
+}
diff --git a/flink-docs/src/test/java/org/apache/flink/docs/rest/SqlGatewayOpenRestAPIDocsCompletenessITCase.java b/flink-docs/src/test/java/org/apache/flink/docs/rest/SqlGatewayOpenRestAPIDocsCompletenessITCase.java
new file mode 100644
index 00000000000..31f44963b62
--- /dev/null
+++ b/flink-docs/src/test/java/org/apache/flink/docs/rest/SqlGatewayOpenRestAPIDocsCompletenessITCase.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.docs.rest;
+
+import org.apache.flink.table.gateway.rest.util.DocumentingSqlGatewayRestEndpoint;
+import org.apache.flink.table.gateway.rest.util.SqlGatewayRestAPIVersion;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.nio.file.Path;
+
+import static org.apache.flink.docs.rest.RuntimeOpenRestAPIDocsCompletenessITCase.getPathOfCommittedHtml;
+import static org.apache.flink.docs.rest.RuntimeOpenRestAPIDocsCompletenessITCase.getPathOfCommittedYaml;
+import static org.apache.flink.docs.rest.SqlGatewayOpenApiSpecGenerator.SQL_GATEWAY_OPEN_API_TITLE;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Verifies that generated SQL Gateway REST and Open API docs (HTML + OpenAPI yml) match committed
+ * files.
+ *
+ * <p>This acts as a freshness check to ensure the documentation stays in sync with the code.
+ */
+class SqlGatewayOpenRestAPIDocsCompletenessITCase {
+
+    @Test
+    void testSqlGatewayRestApiDocsUpToDate(@TempDir Path tempDir) throws Exception {
+        final DocumentingSqlGatewayRestEndpoint endpoint = new DocumentingSqlGatewayRestEndpoint();
+        for (final SqlGatewayRestAPIVersion apiVersion : SqlGatewayRestAPIVersion.values()) {
+            if (apiVersion == SqlGatewayRestAPIVersion.V0) {
+                continue;
+            }
+            final String version = apiVersion.getURLVersionPrefix();
+            String targetHtmlName = String.format("rest_%s_sql_gateway.html", version);
+            final Path pathOfGeneratedHtml = tempDir.resolve(targetHtmlName);
+            final Path pathOfCommittedHtml = getPathOfCommittedHtml(targetHtmlName);
+            RestAPIDocGenerator.createHtmlFile(endpoint, apiVersion, pathOfGeneratedHtml);
+            assertThat(pathOfCommittedHtml)
+                    .as("Missing committed %s file: %s", targetHtmlName, pathOfCommittedHtml)
+                    .exists()
+                    .as(
+                            "Committed `%s` file is out of date. Please regenerate docs under `flink-docs` module based on `README.md`.",
+                            targetHtmlName)
+                    .hasSameTextualContentAs(pathOfGeneratedHtml);
+
+            String targetYmlName = String.format("rest_%s_sql_gateway.yml", version);
+            final Path pathOfGeneratedYml = tempDir.resolve(targetYmlName);
+            final Path pathOfCommittedYml = getPathOfCommittedYaml(targetYmlName);
+            OpenApiSpecGenerator.createDocumentationFile(
+                    SQL_GATEWAY_OPEN_API_TITLE, endpoint, apiVersion, pathOfGeneratedYml);
+            assertThat(pathOfCommittedYml)
+                    .as("Missing committed %s file: %s", targetYmlName, pathOfCommittedYml)
+                    .exists()
+                    .as(
+                            "Committed `%s` file is out of date. Please regenerate docs under `flink-docs` module based on `README.md`.",
+                            targetYmlName)
+                    .hasSameTextualContentAs(pathOfGeneratedYml);
+        }
+    }
+}